如何动态获取订单明细? [英] How to get order details dynamically?

查看:66
本文介绍了如何动态获取订单明细?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过其ID从Magento检索订单. 如何通过ID加载特定的订单?

I need to retrieve an order from Magento by its id. How do I load a specific order by id?

到目前为止,我已经尝试过:

so far i have tried this:

<?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/>";

}
?>

对于静态订单来说效果很好...但是我想动态获取.

it works fine for static order...but i want to get dynamically.

推荐答案

为此,您需要执行以下步骤:

For this you need to follow the following steps:

  1. 创建一个表单以搜索订单详细信息
  2. 您可以在所需位置添加自定义代码.

然后,您需要在要显示订单详细信息的URL上提交搜索表单.必须有一个与表单提交的URL相关联的模板文件.

Then you need to submit your search form on the URL where you want to show the order details. there must be one template file associated with the form submitted URL.

在模板文件中,您可以使用上面指定的代码.但是要使其动态化,需要使用以下方式获取提交的订单号:

In the Template file you can use your above specified code. but as you want to make it dynamic need to fetch submitted order number using the following way:

$orderId = $this->getRequest()->getParam('search_orderid'); //search_orderid is name of search box

搜索表单:

<form id="orderSerchForm" method="post" action="<?php echo $this->getUrl('sales/order/history') ?>">
  <input type="text" name="search_order" id="search_order" placeholder="Enter Order ID" />
  <input type="submit" />
</form> 

这篇关于如何动态获取订单明细?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆