Magento 1.9 – How to Get Shipping Price From Quote

cartmagento-1.9shipping

I am trying to get the shipping price from the quote on the cart page for the entire order.

I have tried multiple things including:

Mage::getModel("checkout/session")->getQuote()->getShippingMethod()->getPrice();


$rates = Mage::getModel("checkout/session")->getQuote()->getShippingAddress()->getAllShippingRates();
foreach($rates as $rate){
    $rate->getPrice();
}

What can I do to get the shipping price in the Magento cart?

Best Answer

This will do the trick. From your question, I assume that the customer has already selected their desired shipping method.

<?php

$quote = Mage::getModel("checkout/session")->getQuote();
$amount = $quote->getShippingAddress()->getShippingAmount();

In fact, there are a number of methods available to you. Such as:

<?php 

$address = $quote->getShippingAddress();
$address->getBaseShippingAmount();
$address->getBaseShippingDiscountAmount();
$address->getBaseShippingHiddenTaxAmount();
$address->getBaseShippingInclTax();
$address->getBaseShippingTaxAmount();

$address->getShippingAmount();
$address->getShippingDiscountAmount();
$address->getShippingHiddenTaxAmount();
$address->getShippingInclTax();
$address->getShippingTaxAmount();

If you simply want to get all available shipping rates into an array:

<?php

$address = $quote->getShippingAddress();

$shippingPrices = array();
foreach($address->getAllShippingRates() as $rate){
    $shippingPrices[$rate->getCode()] = $rate->getPrice();
}
var_dump($shippingPrices);
Related Topic