Tutorialsplane

Magento get quote details


Magento get quote details : Magento quote is basically an offer for user if it is accepted by user it converts to order. If you are working with magento quote you need various thing to work on such as quote items, quote total, shipping method etc. We are going to explain the quote details with example.


Magento get quote details

Here are details about the magento get quote details.

First of all let us get quote session. Here you have to option whether you want to get quote session on front or on magento admin. We will go through both in this tutorial.

Get magento Quote Session

If you are working with magento front end use the following method to get Quote Session.

Get magento Quote Session

$quote = Mage::getSingleton('checkout/session')->getQuote();

If you are working with magento admin Quote. Use the below method to get the quote session-

Get magento admin Quote Session

Get magento admin Quote Session

$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();

Once the quote is retrieved either from front end or admin we will access other attributes in the same way.

Magento get quote id

You can get Quote Id as below –

magento get quote id from session

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
// use Mage::getSingleton('adminhtml/session_quote') for admin quote
$quoteId = $quote->getId();

Magento Get Quote Items

You can get quote items on both frontend and backend as below-

Get magento Quote Session

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); //use for admin quote
$quoteItems = $quote->getAllVisibleItems();
foreach ($quoteItems as $item) {
    $productId = $item->getProductId(); 
    $productName = $item->getProductName();   
}

Get Payment Method From Magento Quote Session

You can get Payment Detail as below –

Get Payment Method From Magento Quote Session

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$quote = Mage::getModel('sales/quote')->load($quote->getQuoteId());
$paymentCode = $quote->getPayment()->getMethodInstance()->getCode();
$paymentTitle = $quote->getPayment()->getMethodInstance()->getTitle();

Get Shipping Method From Magento Quote Session

You can get Shipping Method as below –

Get Shipping Method From Magento Quote Session

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();

Magento Get Shipping And Billing Address Quote Session

You can get Shipping And Billing Address as below –

Magento Get Shipping And Billing Address Quote Session

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$shippingAddress = $quote->getShippingAddress();
$billingAddress = $quote->getBillingAddress();

Magento get quote shipping amount

You can get Shipping Amount as below –

Magento get quote shipping amount

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$shippingAmount = $quote->getShippingAddress()->getShippingAmount();

Magento get Quote Grand Total

You can get Grand Total as below –

Magento get Quote Grand Total

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$grandTotal = $quote->getGrandTotal();

Magento get Quote Tax

You can get Tax as below –

Magento get Quote Tax

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$tax = $quote->getShippingAddress()->getData('tax_amount');

Magento get Quote Discount Amount

Magento get Quote Discount Amount

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$totals =  $quote->getTotals();
$totalDiscount = $totals["discount"]->getValue();
Note : From $totals = $quote->getTotals(); you can also get ‘subtotal’, ‘shipping’, ‘tax’, ‘discount’ and ‘grand_total’ .

For ‘subtotal’, ‘shipping’, ‘tax’, ‘discount’ and ‘grand_total’ You can use following syntax to get the values –

$quote = Mage::getSingleton('checkout/session')->getQuote();
//$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote(); // use this for admin quote
$totals =  $quote->getTotals();
$totalDiscount = $totals["discount"]->getValue();
$tax = $totals["tax"]->getValue();
$subtotal = $totals["subtotal"]->getValue();
$shipping = $totals["shipping"]->getValue();
$grandTotal = $totals["grand_total"]->getValue();