4

I am currenly working on one custom module for magento 1.9.1

I am stuck on getting the session value of the checkouts subtotal.

I know how to get it in a template file but i have to get in in a simple php file.

This is the code that i am tring to get the value:

<?PHP
require('app/Mage.php'); //Path to Magento

Mage::app();
echo Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); 
?>

It's not returning the value. The module is located in /app/code/local if it is important.

Did i have to make any function or something ?

Thanks!

Venelin
  • 121
  • 2
  • 3
  • 5

3 Answers3

3

This may help you:

$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = round($totals["subtotal"]->getValue()); //Subtotal value
$grandtotal = round($totals["grand_total"]->getValue()); //Grandtotal value
TBI Infotech
  • 4,788
  • 1
  • 13
  • 30
0

You can also try following code it will work

<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
Delphin Sam
  • 148
  • 1
  • 1
  • 9
0

To access the cart subTotal in the script outside Magento you need frontend session.

Try this code it works.( Tested )

<?php
require('app/Mage.php'); 
Mage::app();

Mage::getSingleton('core/session', array('name' => 'frontend'));
echo Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); 
?>
Mukesh
  • 1,428
  • 4
  • 28
  • 58