Skip to content

Instantly share code, notes, and snippets.

@willboudle
Last active August 12, 2019 15:42
Show Gist options
  • Select an option

  • Save willboudle/aa835947fd5a72dc55b4 to your computer and use it in GitHub Desktop.

Select an option

Save willboudle/aa835947fd5a72dc55b4 to your computer and use it in GitHub Desktop.
Magento walk() method example - for large collection
public function uppercaseAction()
{
// get customer collection
$customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect(array('firstname'), 'inner');
// call iterator walk method with collection query string and callback method as parameters
Mage::getSingleton('core/resource_iterator')->walk($customers->getSelect(), array(array($this, 'customerCallback')));
}
// callback method
public function customerCallback($args)
{
$customer = Mage::getModel('customer/customer’); // get customer model
$customer->setData($args['row']); // map data to customer model
$customer->setFirstname(strtoupper($customer->getFirstname())); // set value of firstname attribute
$customer->getResource()->saveAttribute($customer, 'firstname'); // save only changed attribute instead of whole object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment