获取具有相同字段的不同字段值的magento订单集合

时间:2014-01-10 06:51:06

标签: php magento collections

您好我想获得具有相同字段的多个字段值的订单集合。我已经尝试使用addFieldToFilter获取各个字段值的集合('status':pening&'status':processing)并且我合并了两个收集到一个集合。现在我遇到的问题就像我无法访问结果集合一样,它的低谷错误就像getMethod一样无法调用非对象。给我任何建议。

这是我的代码:

$shippedCollection = array();
$processingCollection = array();
$orderSCollection = Mage::getModel('sales/order')->getCollection();
$shippedCollection = $orderSCollection->addFieldToFilter('status','delivered_carrier');
$orderPCollection = Mage::getModel('sales/order')->getCollection();
$processingCollection = $orderPCollection->addFieldToFilter('status','processing');
$order = array_merge($shippedCollection->getAllIds(),$processingCollection->getAllIds());

$order->getData('increment_id');

2 个答案:

答案 0 :(得分:1)

你好检查下面的代码可能会对你有所帮助

$order_collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', array('in' => array('delivered_carrier','pending')));
echo count($order_collection->getAllIds());

答案 1 :(得分:0)

你必须要知道一件重要的事情:

collection !== array

您合并了数组,而函数array_merge()也返回了数组,这就是您在最后一行收到错误的原因。

以下是使用不同的值过滤您的集合并循环遍历它的代码。

$ordersCollection = Mage::getModel('sales/order')->getCollection();
$filteredCollection = $ordersCollection
        ->addFieldToFilter('status', array('in' => array('pending', 'processing'))); //set statuses which you want

foreach ($filteredCollection as $order) {
    echo '<pre>'.$order->getIncrementId();
}

有关馆藏的更多信息,请转到this article

希望你会发现这有用,欢呼!