1

我试图在下面的函数中找到一种方法来过滤 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();
    }
}

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

4

1 回答 1

4

要获取示例代码中所示的增量 ID,无需循环:

$invoiceCollection = $order->getInvoiceCollection();

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

$incrementIds = $invoiceCollection->getColumnValues('increment_id');
于 2012-07-11T08:41:43.783 回答