0

I'm trying to run an update script to a module as i've changed the way our warehouse module works. I need to update all orders in a collection of orders if it meets a certain requirement. I know that i can save each order as it goes through, but i'd prefer to save the entire collection once it has updated all values. $collection->save(); causes the page to go white with no errors thrown. Can anyone see where i'm going wrong. Here is my script.

    <?php

$installer = $this;

$_last_export_date = Mage::getStoreConfig('warehouse/runtime/sales_last_export');

$collection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*');

foreach($collection as $order) {
    if($order->getCreatedAt() < $_last_export_date) {
       $order->setPointbidExported(1);
    }
}

//$collection->walk('save');

$collection->save();

EDIT ==========================

Thank you Marius for your response, I don't have the authority to answer my own question at this time so a comment will have to do.

I found this error in my apache logs "Found an error : PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 235929601 bytes)" So i don't think there was anything wrong with my method. For those interested my solution was to just directly query the database using sql. See below :

<?php

$installer = $this;

$_last_export_date = Mage::getStoreConfig('warehouse/runtime/sales_last_export');

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query('UPDATE sales_flat_order SET pointbid_exported = 1 WHERE created_at < '.'"'.$_last_export_date.'"'); 

This then wont exceed the allowed memory size as it doesn't use PHP to process.

1 Answer 1

1

Try this.

$_last_export_date = Mage::getStoreConfig('warehouse/runtime/sales_last_export');
$collection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('*');
$resourceModel = Mage::getResourceModel('sales/order');
foreach($collection as $order) {
    if($order->getCreatedAt() < $_last_export_date) {
       $order->setPointbidExported(1);
       $resourceModel->saveAttribute($order, 'pointbid_exported');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.