更新后,Magento值变为双倍

时间:2013-03-09 17:18:48

标签: php magento-1.7

我正在进行扩展。在此扩展中,我需要更新总计。

例如,如果subtotal=$4discount_amount=$1,则授予总额为$3。我的问题是,当我执行计算时,折扣价格变为双倍。

class PunchTab_Points_Model_Total_Calcdiscount extends Mage_Sales_Model_Quote_Address_Total_Abstract {
    public function collect(Mage_Sales_Model_Quote_Address $address) {
        $session = 2;
        //$session=   Mage::getSingleton('core/session')->getMyValue();
        if (isset($session)) {
            $total_discount = $session;
            //Mage::helper('core')->currency($total_discount, true, false);
            $address - > setCalcdiscountAmount((float) $total_discount);
            $address - > setGrandTotal(($address - > getGrandTotal() - $address - > getCalcdiscountAmount()));
            $address - > setBaseGrandTotal(($address - > getBaseGrandTotal() - $address - > getCalcdiscountAmount()));
            return $this;
        }
    }
    public function fetch(Mage_Sales_Model_Quote_Address $address) {
        $amt = $address - > getCalcdiscountAmount();
        if ($address - > getCalcdiscountAmount() > 0) {
            $address - > addTotal(array('code' => $this - > getCode(), 'title' => Mage :: helper('sales') - > __('Reward Discount'), 'value' => -$amt,));
        }
        return $this;
    }
}

此时,折扣/会话值变为双倍。请帮忙。

1 个答案:

答案 0 :(得分:1)

你能不能快速修复,例如

$subtotal = 4
$discount_amount= 1

$temp_discount_amount = $discount_amount % 2

$discount_amount = $temp_discount_amount

输出将是您的双倍金额的一半,这将是您的预期折扣。我知道它是一个简单的解决方案,但应该可以工作。