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

Posted

tags:

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

<?php

// 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.
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);

// To get some basic order details, subtotal, shipping cost, discount, tax and grand total.
echo "order subtotal: ".$order->getSubtotal()."<br>";
echo "shipping: ".$order->getShippingAmount()."<br>";
echo "discount: ".$order->getDiscountAmount()."<br>";
echo "tax: ".$order->getTaxAmount()."<br>";
echo "grand total".$order->getGrandTotal()."<br><br><br>";

// 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
echo "Complete Order detail:<br>".print_r($order->debug(),true)."<br>";

// To get the order details for each item in the order, the order item detail is stored in the table sales_flat_order_item
$orderItems = array();
foreach($order->getItemsCollection() as $item)
{
    //$product = Mage::getModel('catalog/product')->load($item->getProductId());
    $row=array();
    $row['sku'] = $item->getSku();
    $row['original_price'] = $item->getOriginalPrice();
    $row['price'] = $item->getPrice();
    $row['qty_ordered']= (int)$item->getQtyOrdered();
    $row['subtotal']= $item->getSubtotal();
    $row['tax_amount']= $item->getTaxAmount();
    $row['tax_percent']= $item->getTaxPercent();
    $row['discount_amount']= $item->getDiscountAmount();
    $row['row_total']= $item->getRowTotal();
    $orderItems[]=$row;
}
echo "All items in the order:<br>".print_r($orderItems,true)."<br><br><br>";

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

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

在 magento 2.4 企业中结账时使用在线交易进行订单拆分

php 从magento sql获取订单

贝宝快递结账 |错误的订单 ID:“x”

如何在 Magento 中获取订单时间?

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