Magento,getSubtotal和getGrandTotal总是返回零

Unf*_*foX 5 php model totals magento cart

我有一个奇怪的问题.我开发了一个模块,根据数据库中的某些值为总计添加一行.但是当我打电话时,我的模块模型(继承自Mage_Sales_Model_Quote_Address_Total_Abstract)

$address->getSubtotal()
Run Code Online (Sandbox Code Playgroud)

要么

$address->getGrandTotal()
Run Code Online (Sandbox Code Playgroud)

或任何其他总计方法,我得到零(0)返回.但是在phpmyadmin中,我看到那些值不是零.除这些总计列之外的任何其他列都返回其正确的值(即,getAddressId()返回ID,getAddressType返回"运送"等)

可能是什么问题,任何想法?谢谢----------编辑-----------好的,在@Alan Storm的评论之后,我看到我应该更清楚了.我正在尝试开发分期付款模块.我将在管理员中设置分期付款(根据月数更改),并且我会在结账时将此费用添加到购物车总额中.

这是我的收集方法,

public function collect(Mage_Sales_Model_Quote_Address $address)
{

$address->setInstalmentCount(2); //instalment count is hardcoded as 2 for debugging

$paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
$paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
if ($paymentMethod != 'oos' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())){            
    return $this;
}

$paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();

if ($paymentMethod->getCode() != 'oos') {            
    return $this;
}

$items = $address->getAllItems();
if (!count($items)) {
    return $this;
}

$baseTotal = $address->getBaseGrandTotal();   // THIS ALWAYS RETURNS ZERO

// adress is the reference for grand total
$quote = $address->getQuote();
$store = $quote->getStore();

$fee_perc = $oosconfig['inst' . round($address->getInstalmentCount())]; // get the setting from admin
$ins_fee = $store->convertPrice($baseTotal*$fee_perc/100.0, false); // calculate the fee    

$baseTotal += $ins_fee; // add to totals

$address->setInstalmentFee($ins_fee);

// update totals
$address->setBaseGrandTotal($baseTotal);
$address->setGrandTotal($store->convertPrice($baseTotal, false));    

return $this;   

}
Run Code Online (Sandbox Code Playgroud)

------ EDIT2 ------

好的伙计们,我已经弄明白了!问题出在我应该添加的config.xml中

<after>grand_total</after>
Run Code Online (Sandbox Code Playgroud)

由于它不存在,它首先收集我的模块的总数,而小计和grand_total尚未计算.因此,它们以零为零.

谢谢你!

Ala*_*orm 7

添加OP"自助服务台"答案.如果你喜欢它,请务必投票给原始问题.

好的伙计们,我已经弄明白了!问题出在我应该添加的config.xml中

<after>grand_total</after>
Run Code Online (Sandbox Code Playgroud)

由于它不存在,它首先收集我的模块的总数,而小计和grand_total尚未计算.因此,它们以零为零.