[英]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. 但是当客人处理订单时,
$total
为空。
What can be done? 该怎么办?
PS: I am using Magento 1.6.1 CE PS:我正在使用Magento 1.6.1 CE
Taken from Magento's app/code/core/Mage/Checkout/Block/Onepage.php
: 取自Magento的
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
=) 我有99%的把握可以使用
getOrder()
和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
. 注意:
isCustomerLoggedIn()
方法在定义Mage_Checkout_Block_Onepage_Abstract
其不受继承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... 很抱歉在您之前说废话...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.