php - Magento、getSubtotal 和 getGrandTotal 始终返回零

标签 php magento model cart

我有一个奇怪的问题。我开发了一个模块,它根据数据库中的某些值在总计中添加一行。但是在我调用的模块模型(继承自 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/

相关文章:

php - magento 类别未显示在添加产品页面上?

r - 为什么 AICc 会小于 AIC?

python - 将 JSON 对象列表转换为 Django 模型实例

php - Symfony2 session 未按预期工作/ session 不断超时

php - 使用 curl 从数据库传输数据的最佳方法是什么

php - 使用 PHP 生成 OAuth 1.0 签名

php - Cakephp 缓存关联结果

php - 我可以将 mysql 结果存储在 apc 缓存中吗?

php - 从目录中选择随机文件

php - Magento 事件观察器或自定义模块在生产中不起作用