9

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?

1 Answer 1

19

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);
2
  • 1
    My pleasure and good luck to you in your endeavors! Commented Aug 18, 2016 at 17:48
  • Thanks it worked Commented Jul 3 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.