Magento – Calculate grand total on order

grand-totalorders

I know grand total is calculated on quote, I would like to find out is there a way to create an order object, add items to it and then get it's grand total without just manually adding item prices to get sum. Also this needs to be done without saving the order.

Best Answer

To calculate and process the grand total you need to follow these

$quote = Mage::getSingleton('checkout/session')->getQuote();
    $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
    $address = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress();
    $quote = $address->getQuote();
    $session= Mage::getSingleton('checkout/session');    
                $items = $session->getQuote()->getAllItems();
        //$items = $quote->getAddressItems($items);
    //echo '<pre>'; print_r($items);

    if(Excellence_Fee_Model_Fee::canApply($address)){
                 //$exist_amount = $quote->getFeeAmount();
                    // $fee = 1000;
                        //$fees = $fee * $result;
                    $balance = 1000;
                        //          $balance = $fee;

                        //$this->_setAmount($balance);
                        //$this->_setBaseAmount($balance);
                        $address->setGrandTotal($balance);

                        $address->setFeeAmount($balance);

                        $address->setBaseFeeAmount($balance);
                        $quote->setGrandTotal($balance);
                        $quote->setBaseGrandTotal($balance);
                        //echo '<pre>'; print_r($quote);
                        $quote->setFeeAmount($balance);
                        //echo '<pre>'; print_r($quote);

                        $address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
                        //echo '<pre>'; print_r($address);
                        $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());
                        //$address->getGrandTotal();
                    //echo '<pre>'; print_r($address);
                    echo  Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();

This is working on checkout and cart page to update the grandtotal. Hope this will help you and you find a correct solution.

Related Topic