How Can I Change product prices on checkout step 4 (After customer choose payment method)?
-
05-10-2020 - |
Pregunta
public function paymentEvent(Varien_Event_Observer $observer) {
$this->log("Entramos al observer");
$quote = $observer->getQuote();
$store = Mage::app()->getStore($quote->getStoreId());
$cartItems = $quote->getAllVisibleItems();
foreach($cartItems as $item) {
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$newPrice = $this->getNewPrice($product->getPrice()); // Function that calculate the newPrice (%)
$product->setPrice($newPrice);
$this->log($product->getPrice()); // this shows the new price
$product->save(); // this doesn't save nothing, on step 5 the price is the same.
}
$this->log("Observer END");
return $this;
}
Solución
public function paymentEvent(Varien_Event_Observer $observer) {
$this->log("Entramos al observer");
$quote = $observer->getQuote();
$store = Mage::app()->getStore($quote->getStoreId());
$cartItems = $quote->getAllVisibleItems();
foreach($cartItems as $item) {
$newPrice = $this->getNewPrice($item->getPrice()); // Function that calculate the newPrice (%)
$item->setCustomPrice($newPrice);
$item->setOriginalCustomPrice($newPrice);
$item->getProduct()->setIsSuperMode(true);
$item->save();
}
$quote->collectTotals()->save();
$this->log("Observer END");
return $this;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange