Magento - 按位置对PDF发票产品进行排序

问题描述 投票:1回答:2

我正在为PDF发票制作Magento 1的解决方案。我们希望发票显示按stock_location排序的产品。我们所有的位置都以字母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);
}

其他任何人都想要这个,也许有一个线索我应该走哪条路? :)

  • 谢谢你的时间。
php magento pdf stock invoice
2个回答
0
投票

我不知道怎么能在Magento做到这一点,但我分享一些想法,你怎么能在PHP中这样做尝试这样.hope它会对你有所帮助

$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);
        }
© www.soinside.com 2019 - 2024. All rights reserved.