订单下达后,如何在Magento中自动获取订单详细信息?

时间:2017-02-03 09:22:26

标签: php magento magento-1.9

我是Magento的新手。

我想从Magento获取订单详情( order_id,产品ID,SKU,数量,价格,送货地址,送货方式)。

我主要担心的是我想将所有信息存储在一个新的单表中,我正在为自己开发一个自定义PHP应用程序。

我收到了这段代码,但我真的不知道在哪里创建页面并加载数据:

<?PHP
$orderNumber = 145000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order item collection
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0]; 
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
echo "orderNumber=".$orderNumber."<br/>";
echo "orderValue=".$orderValue."<br/>";
echo "product_name=".$product_name."<br/>";
echo "product_id=".$product_id."<br/>";
echo "product_sku=".$product_sku."<br/>";
echo "category_id=".$category_id."<br/>";
echo "category_name=".$category_name."<br/><br/>";
}
?>

我收到了这段代码,但我真的不知道在哪里创建页面并加载数据

<?PHP
$orderNumber = 145000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order item collection
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0]; 
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
echo "orderNumber=".$orderNumber."<br/>";
echo "orderValue=".$orderValue."<br/>";
echo "product_name=".$product_name."<br/>";
echo "product_id=".$product_id."<br/>";
echo "product_sku=".$product_sku."<br/>";
echo "category_id=".$category_id."<br/>";
echo "category_name=".$category_name."<br/><br/>";
}
?>

2 个答案:

答案 0 :(得分:0)

要按增量ID加载订单,可以执行以下操作:

Mage::getModel('sales/order')->loadByIncrementId('10000001'); //use a real increment order id here

要按实体ID加载,您只需调用load:

Mage::getModel('sales/order')->load(24999); //use an entity id here

答案 1 :(得分:0)

在root中创建文件(即test.php)并尝试以下编码。

require_once 'app/Mage.php';
ini_set('display_errors', 1);
umask(0);
Mage::app();

$orderNumber = 145000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order item collection
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0]; 
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
echo "orderNumber=".$orderNumber."<br/>";
echo "orderValue=".$orderValue."<br/>";
echo "product_name=".$product_name."<br/>";
echo "product_id=".$product_id."<br/>";
echo "product_sku=".$product_sku."<br/>";
echo "category_id=".$category_id."<br/>";
echo "category_name=".$category_name."<br/><br/>";
} 

当你可以从外部获取细节时它的工作。