简体   繁体   中英

Cart grand total without shipping costs in Magento

This is the code I have:

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"’); 
}

How do I make it show totals without the shipping costs included?

好吧,进行计算。

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

It seems in Magento 1.8 is no shipping amount available in sales_flat_quote - table anymore.

I had to retrieve the totals by:

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

And check:

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

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

You can use following calculation:

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

$grandTotalWithoutShipping = $grandTotal - $shipping;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM