user2025950
user2025950

Reputation:

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?

Upvotes: 2

Views: 8125

Answers (3)

Gerard de Visser
Gerard de Visser

Reputation: 8050

You can use following calculation:

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

$grandTotalWithoutShipping = $grandTotal - $shipping;

Upvotes: 1

ahe_borriglione
ahe_borriglione

Reputation: 496

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');
}

Upvotes: 2

Jeffrey de Graaf
Jeffrey de Graaf

Reputation: 479

Well, making a calculation.

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

Upvotes: 2

Related Questions