来自guest的Magento getData在success.phtml上

时间:2012-01-06 10:51:39

标签: php magento subtotal

我正在尝试获取结帐成功页面上的小计金额。它适用于注册用户:

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

但是当客人处理订单时,$total为空。

可以做些什么?

P.S。:我正在使用 Magento 1.6.1 CE

1 个答案:

答案 0 :(得分:0)

取自Magento的app/code/core/Mage/Checkout/Block/Onepage.php

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

我99%确定您可以使用getOrder()Mage_Checkout_Block_Success =)

完全相同

注意: isCustomerLoggedIn()方法定义在Mage_Checkout_Block_Onepage_AbstractMage_Checkout_Block_Success不会继承该方法。所以,你可以简单地使用它的实现:

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

E.g。你的代码现在应该是这样的:

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

对不起之前说过无意义的事情......