1

I want to show custom price on product detail page. Based on category id

suppose when I view product A with price 100 and categeory id 1

I want to show its price as 100 + 20

and for category id 2

price as 100

What observer should I use to show different price without changing code?

0

1 Answer 1

0

you can use catalog_product_load_after event to change price in product detail page

<catalog_product_load_after>
    <observers>
        <custom_checkout_observer>
            <type>singleton</type>
            <class>Custom_Custom_Model_Observer</class>
            <method>loadaftercatalog</method>
        </custom_checkout_observer>
    </observers>
</catalog_product_load_after>

In observer.php,

 public function loadaftercatalog($observer)
    {
        $oldprice = 0;
        $product = $observer->getEvent()->getProduct();
        $oldprice = $product->getPrice();
        $newprice = 20 + $oldprice;
        $categoryIds = $product->getCategoryIds();
        foreach($categoryIds as $categoryId){
                if($categoryId == 5){
                    $product->setPrice($newprice);
                }
            }
        return $this;
    }
1
  • Nothing change using this . Aug 4, 2016 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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