2015-05-28 25 views
0

我從sales_flat_order獲得3000多個實體ID,並且必須獲取每個相應訂單的項目。目前我使用此代碼加載任何3000+訂單及其項目:在Magento中加載很多訂單 - 允許的內存大小已耗盡

$orderItems = Mage::getModel('sales/order')->load($orderIdInForEach)->getAllItems(); 

這不是一個好主意,因爲我遇到了內存問題。有沒有更好的方法來做到這一點?

謝謝!

回答

1

加載多個項目的最佳方法是使用fetchItem方法進行收集。

$collection = $orderItems = Mage::getModel('sales/order'); 
while(($order = $collection->fetchItem())) { 
    //Do your thing here without loading all orders 
    //that match the above collection filters. 

    //Get current order items 
    $orderItems = $order->getAllItems(); 
} 

fetchitem方法從數據庫中獲取只有一個記錄,而不是所有的,這將導致內存執行問題的對象。我希望這有助於爲你解決問題。

相關問題