Well, I created my own general class to add a special discount, and everything seems to work fine, except for some reason I canβt find, my amount is calculated twice! This leads to double the amount of discounts and the wrong total amount. Now this happens on the cart page and on the checkout pages ... BUT ... when I complete the order, the amount is in order, calculated only once, and the total amount is in order.
It is strange that the collect method is called twice for pages with a cart, but only once when the order ends, but I can "track where all this happens and why."
To skip the junk code, I insert only important
<sales> <quote> <totals> <mydiscount> <class>ucon_mydiscount/total_mydiscount</class> <before>subtotal</before> </mydiscount> </totals> </quote> </sales>
and collector methods
public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $quote = $address->getQuote(); $quoteId = $quote->getEntityId(); $items = $quote->getAllItems(); if (!count($items)) { return $this; } $discount = 0; $productId = 2556; foreach($items as $item) { if($item->getProduct()->getId() == $productId) { $qty = $item->getQty(); $totalPrice = round(($item->getRowTotal()+$item->getTaxAmount()),2);
and fetcher
public function fetch(Mage_Sales_Model_Quote_Address $address) { $amount = $address->getMydiscountAmount(); if ($amount != 0) { $title = Mage::helper('ucon_mydiscount')->__('My discount'); $address->addTotal(array( 'code' => $this->getCode(), 'title' => $title, 'value' => $amount )); } return $this; }
edit: Another thing that I find very strange is that I am doing setValue in the collect method, not addValue, so even if the method is called twice, it should not be a double value, it should just set it twice to the correct value.
Relja source share