Php Magento在success.phtml上从来宾获取数据

Php Magento在success.phtml上从来宾获取数据,php,magento,subtotal,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 C

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

$_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

摘自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\u Checkout\u Block\u Success执行完全相同的操作

注意:
Mage\u Checkout\u Block\u Onepage\u Abstract
中定义了
isCustomerLoggedIn()
方法,该方法不是由
Mage\u Checkout\u Block\u Success继承的。因此,您可以简单地使用它的实现:

public function isCustomerLoggedIn()
{
    return Mage::getSingleton('customer/session')->isLoggedIn();
}
例如,您现在的代码应如下所示:

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

很抱歉在…之前说了一些没有意义的话。

您确定$amount不是空的吗?;);-)数量和总数都是空的!我试过你的代码。非常感谢你。但它输出相同的东西。注册用户查看价格,非注册用户不查看!:/该死,我把代码贴错位置了。在检查登录状态的if语句中。然后——当然——它不会向来宾用户显示。因此,我现在将代码粘贴到正确的位置。使用您的代码,页面解析将中断。我不知道为什么?!首先,确保粘贴我答案中的最后一个代码。然后,如果没有更改其他代码,请准备将
$order
重命名为
$\u order
。最后,请友好一点,让我看看Magento写入异常的
var/log/exception.log
var/log/system.log
和Apache日志(尾行)中的日志。哦,对了。你把代码粘贴到哪里了?在块或模板中就好了。但不在模型或控制器内。。。