2017-12-18 283 views
1

我正在为Magento 1开发PDF发票解决方案。我们希望发票显示按stock_location排序的产品。我们所有的地点都以A,B,C等字母开头,然后是一些数字。Magento - 按地区排列发票产品

我希望发票能够按字母顺序显示产品,因此当我们找到从A到Z开始的产品时,您可以从上到下了解。我只是不知道如何解决这个问题?

foreach ($invoice->getAllItems() as $item){ 
    if ($item->getOrderItem()->getParentItem()) { 
     continue; 
    } 
    /* Draw item */ 
    $this->_drawItem($item, $page, $order); 
    $page = end($pdf->pages); 
} 

其他人都想要这个,也许有一个线索,我应该去? :)

  • 感谢您的时间。
+0

也许把所有的位置放在数组中,并按字母顺序排序 – Cezary

+0

不知道我得到的可能性。数据不会在数据发送的同一文件中处理。是否可以调用一些我不知道的magento函数?已添加代码发布 –

+0

没有人愿意?它只是让收集订单所有产品变得更容易。 :) –

回答

0

我不知道如何能做到这一点在Magento,但我分享一些想法,你怎么能做到这一点在PHP会这样。希望它会帮助你

$response[] = array(
         'product_id' => $stock->product_id, 
         'product_name' => $stock->product_name, 
         'stock_id' => $stock->stock_id, 
         'stock_location' => $stock->stock_location, 

         ); 
        } 

       foreach ($response as $rec) { 
        $stock_location[] = $rec['stock_location']; 
        $title[] = strtolower($rec['product_name']); 
       } 
       //print_r($stock_location); 

       array_multisort($stock_location, SORT_ASC, SORT_NUMERIC, $title, SORT_ASC, SORT_STRING, $response); 

       print_r($response); 
0

找到了解决办法:

$items = $invoice->getAllItems(); 
     $sortedItems = array(); 

     foreach ($items as $item) { 
      $prod = Mage::getModel('catalog/product')->load($item->getProductId()); 
      $sortedItems[$prod->getStockLocation()] = $item; 
     } 

     ksort($sortedItems); 

     foreach ($sortedItems as $item){ 
      if ($item->getOrderItem()->getParentItem()) { 
       continue; 
      } 
      /* Draw item */ 
      $this->_drawItem($item, $page, $order); 
      $page = end($pdf->pages); 
     }