我正在尝试从订单中获取小计和总计,但结果始终为 NULL。
我尝试了很多我在网上找到的解决方案,但没有任何效果。我等待的事件是:sales_order_place_after
这是代码:
class MyCompany_MyObserver_Model_Observer {
public function send_email($observer) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
//Get name and email of customer
$email = $customer->getEmail();
$fullname = $customer->getName();
//Get the customer group and check that if Trade customer group a email gets sent
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
到目前为止,所有代码都可以正常工作。我可以获取姓名、电子邮件和 groupID
无论如何,下面的代码都会中断!我已经尝试了所有我能找到的解决方案。我正在尝试使用 var_dump 来查看值..
$session= Mage::getSingleton('checkout/session');
//Get totals
$number = Mage::getModel('checkout/cart')->getQuote()->getTotals();
$subtotal = number_format($number,2);
$discount = $totals['discount']->getValue();
$shippingtotal = $totals['shipping']->getValue();
var_dump($grandtotal);
//die();
$grand_total = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
$shippingMethod = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();
$paymentMethod = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getTitle();
//Get billing and shipping address
$billingaddress = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress();
$billingStreet = $billingaddress->getData('street');
$billingPostcode = $billingaddress->getData("postcode");
$billingCity = $billingaddress->getData("city");
$billingRegion = $billingaddress->getRegionCode();
$billingCountry = $billingaddress->getCountryModel()->getName();
$shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
$shippingName = $shippingAddress->getName();
$shippingCompany = $shippingAddress->getData("company");
$shippingStreet = $shippingAddress->getData("street");
$shippingPostcode = $shippingAddress->getData("postcode");
$shippingCity = $shippingAddress->getData("city");
$shippingRegion = $shippingAddress->getRegion();
$shippingCountry = $shippingAddress->getCountryModel()->getName();
}
}
我的配置文件看起来像这样:我捕捉到了正确的事件吗?我唯一能得到的是:订单 ID 客户姓名和电子邮件。
<events>
<checkout_onepage_controller_success_action>
<observers>
<sales_order_place_after>
<type>singleton</type>
<class>MyCompany_MyObserver_Model_Observer</class>
<method>send_email</method>
</sales_order_place_after>
</observers>
</checkout_onepage_controller_success_action>
</events>