2013-03-15 73 views
0

我正在开发modulemagento,其中我显示了网页上的所有订单以及每个订单,我展示了完整的订单信息,包括与该订单相关的购买产品。我能够显示所有订单,但我不明白,其中有多个产品的订单仅显示单个产品,而当我在销售订单下选择销售 - >订单时,显示多于一个产品那里。无法获取Magento中的所有订单项目?

这里是我的代码:

public function indexAction() 
{ 
    $model = Mage::getModel('sales/order'); 
    $product_model = Mage::getModel('catalog/product'); 

    $collection = $model->getCollection() 
    ->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing'))); 

    $data = array(); 
    $orderArr = array(); 

    $records = 0; 
    foreach($collection as $order) 
    { 
     $data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details 
     $data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details 

     $data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount 
     $items_obj = $model->loadByIncrementId($order['increment_id']); // get all items 
     $items = $items_obj->getAllItems(); 

     $data[$records]['order_data']['order_id'] = $order['increment_id']; 

     $i = 0; 
     $productData = array(); 
     $orderProductArr = array(); 
     foreach($items as $itemId => $item) 
     { 
      $_product = $product_model->load($item->getProductId()); // getting product details here to get description 

      $taxClassId = $_product->getData("tax_class_id"); 
      $taxClass = $_product->getData("tax_class_name"); 

      $taxRate = $order['tax_amount']; 

      $orderProductArr[$i]['web_id'] = $item->getProductId(); 
      $orderProductArr[$i]['quantity'] = $item->getQtyToInvoice(); 
      $orderProductArr[$i]['price'] = $item->getPrice(); 
      $orderProductArr[$i]['description'] = $_product->getDescription(); 
      $orderProductArr[$i]['currency'] = $order['order_currency_code']; 
      $orderProductArr[$i]['tax_id'] = $taxClassId; 
      $orderProductArr[$i]['tax_amt'] = $taxRate; 
      $orderProductArr[$i]['total_amt'] = ($item->getPrice()*$item->getQtyToInvoice())+($taxRate); 

      $productData[$i]['title'] = $item->getName(); 
      $productData[$i]['web_product_id'] = $item->getProductId(); 
      $productData[$i]['price'] = $item->getPrice(); 
      $productData[$i]['product_sku'] = $item->getSku(); 
      $productData[$i]['tax_class'] = $taxClassId; 
      $productData[$i]['description'] = $_product->getDescription(); 

      $tax_arr[$i]['tax_id'] = $taxClassId; 
      $tax_arr[$i]['tax_class'] = $taxClassId; 
      $tax_arr[$i]['tax_amt'] = $taxRate; 

      $i++; 
     } 

     $data[$records]['order_data']['product_details'] = $orderProductArr; 
     $data[$records]['order_data']['order_product_details'] = $productData; 
     $data[$records]['order_data']['tax_arr'] = $tax_arr; 
     $data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount(); 
     $data[$records]['order_data']['order_details'] = $order->toArray(); 
     unset($orderProductArr); 
     unset($productData); 
     $records++; 
    } 

    echo "<pre>"; 
    print_r($data); 
    echo "</pre>"; 

} 

任何人都可以请帮我这个?

任何帮助,将不胜感激。

谢谢。

+0

@ R,S你能帮帮我吗? – 2013-03-15 13:21:29

+0

$ order ['increment_id']给我100000108这是正确的,我得到的项目增量ID作为我的函数说loadByIncrementId。 – 2013-03-15 13:26:07

+0

@ R.S是否有任何其他方式获取magento中所有订单的产品? – 2013-03-15 13:33:37

回答

1

我在我的模块中使用了这个。它可能会帮助你。

负载磁订单和产品系列

$resource_model = Mage::getResourceModel('sales/order_collection'); 
$product_model = Mage::getModel('catalog/product'); 

环通过指令集

$records = 0; 
    $productData = array(); 
    $orderProductArr = array(); 

    foreach($resource_model as $all_orders) 
    { 
     if($all_orders['status']!="canceled" && $all_orders['status']!="fraud") 
     { 
      $i = 0; 
      $items = $all_orders->getAllVisibleItems(); 

      foreach($items as $item) 
      { 
       $_product = $product_model->load($item->getProductId()); // getting product details here to get description 

       $taxClassId = $_product->getData("tax_class_id"); 
       $taxClass = $_product->getData("tax_class_name"); 

       $taxRate = $order['tax_amount']; 

       $orderProductArr[$i]['web_id'] = $item->getProductId(); 
       $orderProductArr[$i]['quantity'] = $item->getQtyToInvoice(); 
       $orderProductArr[$i]['price'] = $item->getPrice(); 
       $orderProductArr[$i]['description'] = $_product->getDescription(); 
       $orderProductArr[$i]['currency'] = $order['order_currency_code']; 
       $orderProductArr[$i]['tax_id'] = $taxClassId; 
       $orderProductArr[$i]['tax_amt'] = $taxRate; 
       $orderProductArr[$i]['total_amt'] = ($item->getPrice()*$item->getQtyToInvoice())+($taxRate); 

       $productData[$i]['title'] = $item->getName(); 
       $productData[$i]['web_product_id'] = $item->getProductId(); 
       $productData[$i]['price'] = $item->getPrice(); 
       $productData[$i]['product_sku'] = $item->getSku(); 
       $productData[$i]['tax_class'] = $taxClassId; 
       $productData[$i]['description'] = $_product->getDescription(); 

       $tax_arr[$i]['tax_id'] = $taxClassId; 
       $tax_arr[$i]['tax_class'] = $taxClassId; 
       $tax_arr[$i]['tax_amt'] = $taxRate; 

       $i++; 
       unset($items); 
      }  
      $data[$records]['order_data']['product_details'] = $orderProductArr; 
      $data[$records]['order_data']['order_product_details'] = $productData; 
      $data[$records]['order_data']['tax_arr'] = $tax_arr; 
      unset($orderProductArr); 
      unset($productData); 
      unset($tax_arr); 
      $records++; 
     }  
    } 
+0

谢谢,它的工作就像我想要的一样。 – 2013-03-16 05:10:51

+0

它运作良好。谢谢。 – jdhaar 2013-08-03 05:38:46

相关问题