1

I am trying to get the subtotal amount on checkout success page. It works good for registred users:

$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$amount = $_order->getData('subtotal');
$total  = number_format($amount, 2);

But when the order is processed by a guest, $total is empty.

What can be done?

P.S.: I am using Magento 1.6.1 CE

durron597
  • 31,968
  • 17
  • 99
  • 158
nicmare
  • 170
  • 3
  • 11

1 Answers1

0

Taken from Magento's app/code/core/Mage/Checkout/Block/Onepage.php:

if (!$this->isCustomerLoggedIn()) {
    return $this->getQuote()->getShippingAddress();
} else {
    return Mage::getModel('sales/quote_address');
}

I am 99% sure you can do exactly the same with getOrder() and with Mage_Checkout_Block_Success =)

Note: the isCustomerLoggedIn() method is defined at Mage_Checkout_Block_Onepage_Abstract which is not inherited by Mage_Checkout_Block_Success. So, you could simply use its implementation:

public function isCustomerLoggedIn()
{
    return Mage::getSingleton('customer/session')->isLoggedIn();
}

E.g. your code now shall look like this:

if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
    $order = Mage::getSingleton('checkout/session')->getOrder();
} else {
    $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
}

Sorry for saying non-sense things before...

shybovycha
  • 11,556
  • 6
  • 52
  • 82
  • hi shybobycha! tried your code. thank you very much. but it outputs the same things. registered users see price, non registered not! :/ – nicmare Jan 06 '12 at 18:33
  • damn it, i pasted the code to the wrong position. within an if statement which checks for logged in status. and then - of course - it wont display for guest users. so i pasted my code now to the right place. with your code, the page parsing breaks. i dunno why?! – nicmare Jan 06 '12 at 18:43
  • First of all, be sure to paste the last code in my answer. Then, be ready to rename `$order` to `$_order` if you did not change other of your code. At last, please, be so nice and show me the log within `var/log/exception.log`, `var/log/system.log` and Apache log (tail lines) where the Magento writes its exceptions. – shybovycha Jan 06 '12 at 18:48
  • oh, right. where did you pasted that code - within the Block or template it would be nice. but not within Model or Controller... – shybovycha Jan 06 '12 at 18:49