Last active
August 12, 2019 15:42
-
-
Save willboudle/aa835947fd5a72dc55b4 to your computer and use it in GitHub Desktop.
Magento walk() method example - for large collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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