简体   繁体   中英

Magento getData from guest on success.phtml

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?

PS: I am using Magento 1.6.1 CE

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();
}

Eg 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM