Back to Top

How To Update Price Dynamically in Add to cart

Updated 9 October 2012

1. Goto Following Directory

app/code/core/Mage/Checkout/Model/

2. Open “cart.php”

3. Look for “public function save() {}” Action.

4. The Code Looks like this

Searching for an experienced
Magento Company ?
Find out More
public function save() {
      Mage::dispatchEvent(‘checkout_cart_save_before’, array(‘cart’=>$this));
      $this->getQuote()->getBillingAddress();
      $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
      $this->getQuote()->collectTotals();
      $this->getQuote()->save();
      $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
      Mage::dispatchEvent(‘checkout_cart_save_after’, array(‘cart’=>$this));
      return $this;
}

5. Replace the function with the following code

public function save() {
      Mage::dispatchEvent(‘checkout_cart_save_before’, array(‘cart’=>$this));
      $this->getQuote()->getBillingAddress();
      $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
      $this->getQuote()->collectTotals();
      foreach($this->getQuote()->getAllItems() as $item) {
          $productId = $item->getProductId();
          $product = Mage::getModel(‘catalog/product’)->load($productId);
          $item->setCustomPrice($new_calculated price);
          $item->setOriginalCustomPrice($_POST['coming_price']);
       }
      $this->getQuote()->save();
      $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
      Mage::dispatchEvent(‘checkout_cart_save_after’, array(‘cart’=>$this));
      return $this;
}

6.Update and Enjoy

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home