1

I'm trying to include a JavaScript countdown and price of product on the product page and also in the category page but I have the following bug: for RWD theme because of tier price, the observer inserts the price and countdown twice. My observer looks like this and here is my phtml file.
RWD theme has this div for price info:

<div class="price-info">
    <?php echo $this->getPriceHtml($_product); ?><br>
    <?php echo $this->getChildHtml('bundle_prices') ?><br>
    <?php echo $this->getTierPriceHtml() ?><br>
</div>

If I remove the last line with TierPrice, my observer does not duplicate my price, but if I don't then the price is duplicated.
Can someone tell me what's wrong?

Thanks guys !

1

Your observer is currently setup to be called every time a Block is inserted into a page. (This is a bit inefficient as it will be called hundreds of times per page load, but we'll ignore that for now)

On line 11 of your observer you are filtering all the blocks by its type: if ($_type == 'catalog/product_price') This if condition will return true for both the blocks which are included in the calls getPriceHtml($_product); and getTierPriceHtml(); as they are of the same type.

What you need to do is set your Observer to type singleton in your XML declaration. Company_Module_Model_Observer insertBlock singleton

This would ensure that on the second call at getTierPriceHtml, a second Observer is not created. Now all that is left to do is just put a flag into your insertBlock method to ensure that it doesn't insert your countdown template multiple times.

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.