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!

1
  • Hi, try to init session before using Mage::getSingleton('core/session', array('name'=>'frontend'));. Or look there link Commented Nov 30, 2014 at 14:18

3 Answers 3

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
0

You can also try following code it will work

<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
1
  • NO it's not working... :(
    – Venelin
    Commented Jul 16, 2014 at 12:42
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(); 
?>

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.