我有一個奇怪的問題。我已經開發了一個模塊,它根據數據庫中的某個值添加一行到總計。但在我的模塊模型(這是從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