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.
-
Perhaps a stupid question, but it sounds to me like you want to temporarily use a order object? Something a quote object actually already is. What is the quote functionality missing that you need to use temporarily order object for?– Tim HofmanMar 4, 2014 at 19:17
-
Good point. What I am trying to do is to make multiple order objects out of one order objects with different data. The reason I am not using quote object is that I need to add some existing order items to order objects, so I would need to convert these to quote items if using quote. Another reason is that I need increment id, and some other stuff that are order specific.– LDusanMar 5, 2014 at 9:38
2 Answers
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.
without just manually adding item prices to get sum.
Magento does not provide a built-in function to calculate the totals as it does for quotes (collectTotals). The above would be approach that comes to mind. Of course it misses things like taxes, discounts, shipping, etc so if possible I would look into what Tim suggests using the quote object instead.