Magento - 按SKU对包装单上的物品进行分类

时间:2015-05-27 13:27:08

标签: php arrays magento sorting multidimensional-array

我试图通过SKU对包装单上的物品进行分类。我已经使用此功能获得自定义包装单模块,该模块返回项目:

class Devweb_Packslip_Model_Order_Shipment extends Mage_Sales_Model_Order_Shipment
{
    public function setOrder(Mage_Sales_Model_Order $order)
    {
        parent::setOrder($order);

        $this->_items = array();
        $items = $order->getAllItems();
        foreach ($items as $item) {
            $shipmentItem = Mage::getModel('sales/order_shipment_item');
            $shipmentItem->setShipment($this);
            $shipmentItem->setProductId($item->getProductId());
            $shipmentItem->setOrderItem($item);
            $shipmentItem->setQty($item->getQtyToShip());
            $shipmentItem->setSku($item->getSku());
            $skuArray[] = $shipmentItem->getSku();
            if (!$shipmentItem->getName()) {
                $shipmentItem->setName($item->getName());
            }
            $this->_items[] = $shipmentItem;
        }

    }
}

所以我基本上需要排序$ items og $ this-> _items 我一直在四处搜寻,我不确定我是怎么做的。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

如果换掉线 $items = $order->getAllItems();

代码$items = Mage::getModel('sales/order_item')->getCollection()->setOrderFilter($order)->setOrder('sku','asc');然后应该可以使用