从Magento中的签出会话获取最后一个订单详细信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从Magento中的签出会话获取最后一个订单详细信息相关的知识,希望对你有一定的参考价值。

The code snippet below can be placed in any template file or anywhere after the Mage is initialized, and there has to be an order placed before.
  1. <?php
  2.  
  3. // First we need to the last real order id from the checkout/session and then passing this order id as a parameter to retrieve the order object from sales/order model.
  4. $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
  5. $order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);
  6.  
  7. // To get some basic order details, subtotal, shipping cost, discount, tax and grand total.
  8. echo "order subtotal: ".$order->getSubtotal()."<br>";
  9. echo "shipping: ".$order->getShippingAmount()."<br>";
  10. echo "discount: ".$order->getDiscountAmount()."<br>";
  11. echo "tax: ".$order->getTaxAmount()."<br>";
  12. echo "grand total".$order->getGrandTotal()."<br><br><br>";
  13.  
  14. // To show all the order details, the code below will pull all the order details for this order id from the table sales_flat_order
  15. echo "Complete Order detail:<br>".print_r($order->debug(),true)."<br>";
  16.  
  17. // To get the order details for each item in the order, the order item detail is stored in the table sales_flat_order_item
  18. $orderItems = array();
  19. foreach($order->getItemsCollection() as $item)
  20. {
  21. //$product = Mage::getModel('catalog/product')->load($item->getProductId());
  22. $row=array();
  23. $row['sku'] = $item->getSku();
  24. $row['original_price'] = $item->getOriginalPrice();
  25. $row['price'] = $item->getPrice();
  26. $row['qty_ordered']= (int)$item->getQtyOrdered();
  27. $row['subtotal']= $item->getSubtotal();
  28. $row['tax_amount']= $item->getTaxAmount();
  29. $row['tax_percent']= $item->getTaxPercent();
  30. $row['discount_amount']= $item->getDiscountAmount();
  31. $row['row_total']= $item->getRowTotal();
  32. $orderItems[]=$row;
  33. }
  34. echo "All items in the order:<br>".print_r($orderItems,true)."<br><br><br>";

以上是关于从Magento中的签出会话获取最后一个订单详细信息的主要内容,如果未能解决你的问题,请参考以下文章

PHP 从Magento的结账会议中获取最后的订单详细信息

TFS:如何撤消批处理文件中未修改文件的签出

如何将订单详细信息传递到 magento 中的 paypal-express-checkout?

来自 SVN 存储库的签出代码在 xcode 5 中出现错误

如何检索分支上元素的结帐评论?

Magento 2在结帐页面phtml中发送到支付网关之前获取订单ID?