Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

How To Update Price Dynamically in Add to cart

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

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