2

I am currently trying to get the Subtotal value with Magento 1.9.1.

Here is my code:

    <?php

    class AG_Fee_Model_Fee extends Varien_Object{



        public static function getFee(){

        $subtotal = Mage::helper('checkout')->formatPrice($this->getSubtotal());

            $feeAmt = $subtotal;

            return $feeAmt;

        }

        public static function canApply($address){

            $setFee = Mage::getStoreConfig('checkout/fee/active');

            if($setFee==1)

            {

                return true;

            }

        }

    }

I am calling the subtotal like this: $subtotal = Mage::helper('checkout')->formatPrice($this->getSubtotal()); But it's giving me no result...

Where is the problem?

I'll be so gratefull to you if you can help me!

Thanks in advance!

3
  • unless you have set the subtotal for $this the getSubtotal() call would not return anything. The reason it doesn't error out is you have extended from Varien_Object which has magic getters. Jul 16, 2014 at 6:33
  • I haven't set it. How i can make it? Thank you so much!
    – Venelin
    Jul 16, 2014 at 12:41
  • The approach Marius posted should work. You might have to post more of what, when and how you are executing your code. Jul 17, 2014 at 2:52

4 Answers 4

6
$quote = Mage::getSingleton('checkout/session')->getQuote();
$subtotal = $quote->getSubtotal();
3
  • Thanks but it still not getting the value and it's displayed.
    – Venelin
    Jul 16, 2014 at 12:41
  • i used this but it always give wrong subtotal don't know why but when i used @TBI Infotech solution it works perfectly. any idea why this happen
    – MageLerner
    Jan 10, 2019 at 15:08
  • 1
    @MageLerner. I wrote this 4.5 years ago. I have no idea. Maybe something changed in the newer version. Maybe I was just simply wrong. Use what works for you.
    – Marius
    Jan 10, 2019 at 15:09
3

Try this:

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = round($totals["subtotal"]->getValue()); //Subtotal value
1
  • Why @Marius answer is not getting right total do you have any idea about this
    – MageLerner
    Jan 10, 2019 at 15:09
2

Your information is very limited, and it's a very late reply, but others running into this, could try this:

Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getSubtotal())
1

This should work:

Mage::helper('checkout')->getQuote()->getData('subtotal');

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.