1

Here is the modules config file: app\etc\modules\Cart_Updates.xml

<?xml version="1.0" encoding="UTF-8"?>
  <config>
     <modules>
       <Cart_Updates>
         <codePool>local</codePool>
         <active>true</active>
       </Cart_Updates>
    </modules>
  </config>

Here is my config file : in app\code\local\Cart\Updates\etc\config.xml

<?xml version="1.0"?>
  <config>
   <modules>
     <Cart_Updates>
       <version>1.0.1</version>
     </Cart_Updates>
   </modules>
   <global>
       <models>
         <Cart_Updates>
           <class>Cart_Updates_Model</class>
         </Cart_Updates>
       </models>
       <events>
          <sales_quote_add_item>
              <observers>
                 <cart_updates_model_observer>
                    <type>singleton</type>
                    <class>Cart_Updates_Model_Observer</class>
                    <method>updatePrice</method>
                 </cart_updates_model_observer>
             </observers>
          </sales_quote_add_item>
      </events>
  </global>
 </config>

And here is the Observer: in app\code\local\Cart\Updates\Model\Observer.php

<?php

    class Cart_Updates_Model_Observer {

      public function modifyPrice(Varien_Event_Observer $observer) {
        //exit;
      $order = Mage::registry('current_order'); //For getting current order 
      echo $orderid = $order->getRealOrderId(); // For getting orderid
      $quote_item = $observer->getQuoteItem();
      $payment = 30; //add your custom product price here and do your logic here
      $quote_item->setOriginalCustomPrice($payment);
      $quote_item->save();
      return $this;
      }
      }
    ?>
2
  • Do you want to update your cart item price on cart update? Mar 9, 2017 at 12:10
  • i want to set the custom price when product will be added to the cart, it will show custom price that we will set in the observer and over ride the original one
    – Zoo
    Mar 9, 2017 at 12:12

1 Answer 1

2

here is code for updting the custom price

use this event checkout_cart_product_add_after

for current event

  $item->setCustomPrice($customprice);
  $item->setOriginalCustomPrice($customprice);
  $item->getProduct()->setIsSuperMode(true);

other method

   $product_id = $item->getProductId();
   $product=Mage::getModel('catalog/product')->load($product_id); 
   $item= Mage::getModel('sales/quote_item')->load($item->getId());
   $payment = 30;
   $item->setStoreId(Mage::app()->getStore()->getStoreId());
   $item->setCustomPrice($payment);
   $item->setOriginalCustomPrice($payment);
   $item->setProduct($product);  
   $item->save(); 
6
  • Not working bro.
    – Zoo
    Mar 9, 2017 at 12:14
  • i think it is not triggering the Observer. i have added die; top of the function its not doing any thing.
    – Zoo
    Mar 9, 2017 at 12:16
  • use checkout_cart_product_add_after event Mar 9, 2017 at 12:18
  • It is not working for me Bro..
    – Xabby
    Mar 9, 2017 at 15:41
  • @Xabby change method name to updatePrice as you declare in config.xml Mar 9, 2017 at 17:20

Your Answer

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

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