通过magento中的created_at过滤发票集合

时间:2012-07-10 23:46:24

标签: magento collections filtering

我正在尝试在下面的函数中找到一种过滤getInvoiceCollection结果的方法:

// "eachInvoice" is each of the Invoice object of the order "$orders"
if ($order->hasInvoices()) {
    foreach ($order->getInvoiceCollection() as $eachInvoice) {
        $invoiceIncrementId = $eachInvoice->getIncrementId();
    }
}

可以将以下过滤器添加到$ order-> getInvoiceCollection()

 $order->getInvoiceCollection()
->addAttributeToFilter('created_at', array(
    'from' => $from_date,
    'to' => $today, 
    'date' => true,));

所以整个函数都是,这是正确的方法,它似乎不是正确的。

// "eachInvoice" is each of the Invoice object of the order "$orders"
    if ($order->hasInvoices()) {
    foreach ($order->getInvoiceCollection()$order->getInvoiceCollection()
    ->addAttributeToFilter('created_at', array( 'from' => $from_date,
    'to' => $today, 'date' => true,)) as $eachInvoice) {
        $invoiceIncrementId = $eachInvoice->getIncrementId();
    }
}

这样做的“正确方法”是什么?

1 个答案:

答案 0 :(得分:3)

要获得示例代码中显示的增量ID,则无需循环:

$invoiceCollection = $order->getInvoiceCollection();

$invoiceCollection
        ->addAttributeToFilter('created_at', array(
            'from'  => $from,
            'to'    => $to,                    
        ));

$incrementIds = $invoiceCollection->getColumnValues('increment_id');