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!

  • 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. – Kristof at Fooman Jul 16 '14 at 6:33
  • I haven't set it. How i can make it? Thank you so much! – Venelin Jul 16 '14 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. – Kristof at Fooman Jul 17 '14 at 2:52
6
$quote = Mage::getSingleton('checkout/session')->getQuote();
$subtotal = $quote->getSubtotal();
| improve this answer | |
  • Thanks but it still not getting the value and it's displayed. – Venelin Jul 16 '14 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 '19 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 '19 at 15:09
3

Try this:

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

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())
| improve this answer | |
1

This should work:

Mage::helper('checkout')->getQuote()->getData('subtotal');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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