i know there is a lot of posts that i have seen and i didn't find the error in the code bellow : config.xml :
<events>
<core_block_abstract_to_html_after>
<observers>
<type>singleton</type>
<class>WebDirect_CustomPrice_Model_Observer</class>
<method>convertPricespanToInput</method>
</observers>
</core_block_abstract_to_html_after>
</events>
Observer class :
class WebDirect_CustomPrice_Model_Observer
{
const MODULE_NAME = 'WebDirect_CustomPrice';
public function convertPricespanToInput($observer = NULL)
{
if (!$observer) {
return;
}
if ('product.info.simple' == $observer->getEvent()->getBlock()->getNameInLayout()) {
if (!Mage::getStoreConfig('advanced/modules_disable_output/'.self::MODULE_NAME)) {
$transport = $observer->getEvent()->getTransport();
$block = new WebDirect_CustomPrice_Block_priceSpanToInput();
$block->setPassingTransport($transport['html']);
$block->toHtml();
}
}
return $this;
}
}
and a class that add a custom javascript in product view page :
class WebDirect_CustomPrice_Block_priceSpanToInput extends Mage_Core_Block_Text {
//protected $_nameInLayout = 'selectify.qty_input_to_select';
//protected $_alias = 'qty_input_to_select';
public function setPassingTransport($transport)
{
$this->setData('text', $transport.$this->_generateQtyInputToSelectHtml());
}
private function _generatepriceSpanToInputHtml()
{
$price = Mage::registry('current_product')->getPrice();
$product_Id = Mage::registry('current_product')->getId();
return '
<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function() {
$("product-price-'.$product_Id.'").replace(\'<span class="price" id="product-price-'.$product_Id.'"> <input type="text" id="CP_ID" class="input-text price" name="custom_price" style="width:auto;" value="'.$price.'" onchange="onChangeCP(this);"/></span><input type="hidden" id="custom_price_total" name="custom_price_total" value="'.$price.'">\');
});
//]]>
</script>
';
}
}
is there any error in that code ? I can't see anything!
The issue is in defining observer function in your config.xml.
<events>
<core_block_abstract_to_html_after>
<observers>
<type>singleton</type>
<class>WebDirect_CustomPrice_Model_Observer</class>
<method>convertPricespanToInput</method>
</observers>
</core_block_abstract_to_html_after>
</events>
should be replaced by:
<events>
<core_block_abstract_to_html_after>
<observers>
<some_unique_identifier>
<type>singleton</type>
<class>WebDirect_CustomPrice_Model_Observer</class>
<method>convertPricespanToInput</method>
</some_unique_identifier>
</observers>
</core_block_abstract_to_html_after>
</events>
where "some_unique_identifier" can be any unique string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With