0

I have try to update price area html any page Ex.(Homepage, Product Listing, Product view page, etc..) via observer i have create event observer but i have no idea hoe to update layout. i have use catalog_product_get_final_price event and i have not use another event.

Her is my code

<frontend>
    <events>
        <catalog_product_get_final_price>
          <observers>
            <Test_Priceevent>
              <type>singleton</type>
              <class>Test_Priceevent_Model_Observer</class>
              <method>callforprice</method>
            </Test_Priceevent>
          </observers>
        </catalog_product_get_final_price>
</frontend>

And Observer Code is

class Test_Priceevent_Model_Observer
{
    public function callforprice(Varien_Event_Observer $observer)
    {
       echo "Test";
    }
}

currently display "Test" near product price but i have remove price section and display my custom test in specific product not all product

So Please Help me :)

1

You cannot modify the layout using the event catalog_product_get_final_price.
This event is dispatched on the product view page, but after the layout is loaded and the blocks are instantiated.
So any modifications you do to the layout object will be ignored.
But even if you could do that, this is not the way to do it.
The event is dispatched in the method getFinalPrice and the application expects this method to return a valid number.
It is not used just to display the price. It is also used for different calculations. So if you modify the price into a string by using this method there will be awful side-effects.
Instead you should modify /app/design/frontend/{package}/{theme}/template/catalog/product/price.phtml.
I know it's a big and scary file, but you need to put your condition at the top.
something like this:

<?php if (your condition for displaying a text) : ?>
   <?php echo $this->__('Your text here')?>
<?php else ?>
   <!-- original content of the file -->
<?php endif;?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.