【问题标题】:How to get order details dynamically?如何动态获取订单详情?
【发布时间】:2015-06-23 05:36:31
【问题描述】:

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

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

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

}
?>

它适用于静态订单...但我想动态获取。

【问题讨论】:

    标签: magento search dynamic magento-1.9


    【解决方案1】:

    首先,您需要创建一个表单,将其发布到包含上述代码的自定义控制器

    然后用

    更新你的代码
    $orderNumber = $this->getRequest()->getParams('field_name');;
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
    

    看到这个How to get post data variables after submition a form in magento

    【讨论】:

      【解决方案2】:

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

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

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

      在模板文件中,您可以使用上面指定的代码。但如果你想让它动态需要使用以下方式获取提交的订单号:

      $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> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-09
        • 2013-05-26
        • 2013-02-13
        • 2012-03-05
        • 2023-04-02
        • 1970-01-01
        • 2017-01-17
        • 1970-01-01
        相关资源
        最近更新 更多