我有一个奇怪的问题。我已经开发了一个模块,它根据数据库中的某个值添加一行到总计。但在我的模块模型(这是从Mage_Sales_Model_Quote_Address_Total_Abstract继承)当我打电话Magento,getSubtotal和getGrandTotal总是返回零
$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;
}
------ EDIT2 ------
好球员,我已经想通了!问题是我的config.xml 我应该补充
<after>grand_total</after>
既然是不存在的,这是第一次我收集模块的总而小计和grand_total尚未计算。正因为如此,他们以零来形容。
虽然谢谢!
目前尚不清楚你想与地址引用的对象,这使得提供一个答案很难在这里做什么。这个类不用于从数据库中获取值。 – 2011-12-26 19:40:03
我已经编辑了您的评论的问题的答案。 – UnfoX 2011-12-26 19:50:18
好吧,我已经想通了!问题是我的config.xml 我应该补充 grand_total 既然是不存在的,这是第一次我收集模块的总而小计和grand_total尚未计算。正因为如此,他们以零来形容。 谢谢,虽然! –
UnfoX
2011-12-26 21:18:39