Question

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;
}
Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top