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
Categories:
magento
View Comments
Comment or Ask a Question
Quick Links