我正在尝试在结帐成功页面上获取小计金额。它适用于注册用户:
$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$amount = $_order->getData('subtotal');
$total = number_format($amount, 2);
但是当订单由客人处理时,$total是空的。
可以做什么?
PS:我正在使用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_Checkout_Block_Success=做同样的事情
注意:该isCustomerLoggedIn()方法定义在Mage_Checkout_Block_Onepage_Abstract其不被继承Mage_Checkout_Block_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());
}
抱歉之前说了些无意义的话……