2012-07-10 32 views
0

我試圖找到一種方法來過濾getInvoiceCollection的結果在下面的功能:過濾收集發票通過created_at在Magento

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

可以添加以下命令 - $過濾器> 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(); 
    } 
} 

什麼是「正確的方法」去做這件事?

回答

3

爲了得到增量IDS作爲示例代碼顯示沒有必要循環:

$invoiceCollection = $order->getInvoiceCollection(); 

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

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