好的,我創建了自定義的Total類,用於添加特殊折扣,並且一切看起來都正常,除了由於某種原因我無法找到,我的總計算了兩次!這會導致雙倍的折扣,並導致總計不正確。現在,這發生在購物車頁面和結帳頁面上......但是......當我完成訂單時總數很好,只計算一次,總計很好。Magento:自定義總數計數兩次?
奇怪的是,這就像收集方法被稱爲購物車頁面的兩次,但只有一次完成訂單,但我可以'追蹤所有這些發生的地方,爲什麼。
要跳過垃圾代碼,我就只粘貼重要
<sales>
<quote>
<totals>
<mydiscount>
<class>ucon_mydiscount/total_mydiscount</class>
<before>subtotal</before>
</mydiscount>
</totals>
</quote>
</sales>
和收藏家的方法
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);
//discount 10%
$discount = round($totalPrice * 0.1,2);
$discount = 0 - $discount;
}
}
if($discount == 0)
return $this;
$this->_setAmount($discount);
$this->_setBaseAmount($discount);
return $this;
}
和提取程序
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;
}
編輯:還有一兩件事,我覺得很奇怪 - 我在我的collect方法中執行setValue,而不是addValue,所以即使方法被調用了t它不應該是雙重值,它應該簡單地將它設置爲正確的值兩次。
我用Andrey的評論作爲出發點,從[這裏](http://stackoverflow.com/questions/4363876/how-to-set-custom-grand-total-before-checkout-process-in-magento ) – Relja
我經歷過這一次,但現在不能找到我所做的修復它。我相信我複製了一個Mage類,明確地檢查了總數是否已經被使用了。嘗試在每個收集和提取函數中添加斷點或「Mage :: log(__ METHOD __)」,以查看兩次調用的內容 - 這是我上次調試的方式。 – clockworkgeek