购物车总计不含Magento的运费

时间:2013-01-30 16:01:32

标签: php function magento

这是我的代码:

public function TOTALCODE () 
{ 
if ($parentBlock = $this->getParentBlock()) 
{ 
$amount = __(number_format(Mage::getSingleton(’checkout/session’)->getQuote()->getGrandTotal(), 2, ‘,’, ‘.’)); 
$text = __(’€ %s (incl. 21% btw)’, $amount); 
$parentBlock->addLink($text, ‘checkout/cart’, $text, true, array(), 50,null,’class="top-link-cart"’); 
}

如何在不包含运费的情况下显示总数?

3 个答案:

答案 0 :(得分:2)

好吧,做一个计算。

$subtotal = Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal() - Mage::getSingleton('checkout/session')->getQuote()->getShippingAmount()

答案 1 :(得分:2)

似乎在Magento 1.8中,sales_flat_quote - table中没有可用的运费。

我必须通过以下方式检索总数:

$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals()

并检查:

$totalKeys = array('subtotal', 'shipping', 'tax', 'discount', 'grand_total');

foreach ($totalKeys as $totalKey) {
    if (isset($totals[$totalKey])) echo $totals[$totalKey]->getData('value');
}

答案 2 :(得分:1)

您可以使用以下计算:

$grandTotal = Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();
$shipping = Mage::getSingleton('checkout/cart')->getQuote()->getTotals()['shipping']->getValue();

$grandTotalWithoutShipping = $grandTotal - $shipping;
相关问题