我有一个奇怪的问题。我开发了一个模块,它根据数据库中的某些值在总计中添加一行。但是在我调用的模块模型(继承自 Mage_Sales_Model_Quote_Address_Total_Abstract)中
$address->getSubtotal()
或
$address->getGrandTotal()
或任何其他总计方法,我得到零 (0) 返回。但是在 phpmyadmin 中,我看到这些值不为零。除了这些总计列之外的任何其他列都会返回它们的正确值(即 getAddressId() 返回 ID,getAddressType 返回“shipping”等)
可能是什么问题,有什么想法吗? 谢谢 - - - - - 编辑 - - - - - - 好的,在@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;
}
------ 编辑2 ------
好的,我已经弄明白了!问题出在我的 config.xml 我应该添加
<after>grand_total</after>
由于它不存在,它首先收集我模块的总计,而小计和总计尚未计算。因此,它们以零出现。
谢谢你!
最佳答案
添加 OP“自助服务台”答案。如果您喜欢,请务必对原始问题投赞成票。
OK guys, I have figured it out! The problem was with my config.xml I should have added
<after>grand_total</after>
Since it is absent, it was first collecting my module's total while subtotal and grand_total were not calculated yet. Because of this, they were coming as zeros.
关于php - Magento、getSubtotal 和 getGrandTotal 始终返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8638514/