0

I'm using checkout_cart_product_add_after event.

I have requirement like this Tier Prices for Specific Increments

I have written following code in my observer.

But row total is not updated in cart page.But in system.log its giving updated value.Thanks in advance.please let me know if you need any clarification.

Here Specific increment=3;

    class Exinent_Customprice_Model_Observer {
                public function customprice(Varien_Event_Observer $observer){

                     $item = $observer->getQuoteItem();
                        if ($item->getParentItem()) {
        $item = $item->getParentItem();
    }             
                 if (($item->getQty() % 3) == 0)
                  {
                  $custom_price=5;
                  $item->setCustomPrice($custom_price); 
                  $item->setOriginalCustomPrice($custom_price);
                  $item->getProduct()->setIsSuperMode(true);                           
                  }
                 else
                 {
                  $custom_price=5;
                  $rem=(int)(($item->getQty())/3);
                  $rowsubtotal=($rem)*(3)*($custom_price)+($item->getQty() % 3)*($item->getProduct()->getPrice()); 

                Mage::log($rowsubtotal);
                $item->setRowTotal($rowsubtotal);
                Mage::log($item->getRowTotal());
                 }
    }
    }

2 Answers 2

2

checkout_cart_product_add_after is triggered after the quote has already been saved. Try sales_quote_product_add_after instead, which is triggered in Mage_Sales_Model_Quote::addProduct().

The event has one parameter, items with an array of quote items that have been generated from this product. For simple products it is always one item. For complex products (bundle, configurable), the first array item is always the parent (i.e. the main product). So you get your item like this:

item = $observer->getItems()[0];
-1

You need to write $item->save(); after setting custom price to save the quote item custom price.

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.