【问题标题】:Magento - Sort PDF Invoice products by locationMagento - 按位置对 PDF 发票产品进行排序
【发布时间】:2017-12-18 12:11:05
【问题描述】:

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

我希望发票按字母顺序显示产品,这样当我们找到产品时,我们会从 A 到 Z 开始,这样您就可以从上到下知道。就是不知道怎么解决?

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

其他人曾经想要这个,也许知道我应该走哪条路? :)

  • 感谢您的宝贵时间。

【问题讨论】:

  • 也许将所有位置都放在数组中并按字母顺序排序
  • 不确定我是否有这种可能性。数据未在与发送数据相同的文件中处理。是否可以在我不知道的 magento 中调用某些函数?添加代码发布
  • 没有其他人想要这个?它只是使收集订单的所有产品变得更加容易。 :)

标签: php magento pdf stock invoice


【解决方案1】:

我不知道如何在 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);

【讨论】:

    【解决方案2】:

    找到解决办法:

    $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);
            }
    

    【讨论】:

      猜你喜欢
      • 2014-06-09
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 2015-01-31
      相关资源
      最近更新 更多