I would like to save the attribute value without saving its parent. I created a new client attribute through my sql module / setup file ( ref ), and now I want to populate this attribute for each of the existing clients. I created a Backend model for an attribute that detects null values during the loading of an object (afterLoad) and generates content, but I hesitate to save the object at this point in the process.
class Aligent_Referral_Model_Customer_Attribute_Backend_Referralcode extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { public function afterLoad($oCustomer) { $vAttrCode = $this->getAttribute()->getAttributeCode(); $vValue = $oCustomer->getData($vAttrCode); if (empty($vValue)){ $oCustomer->setData($vAttrCode, Mage::helper('referral')->generateRafCode($oCustomer)); } return $this; } }
Ideally, I would like to name something like $this->getAttribute()->setValue('blah')->save() in this afterLoad method afterLoad that it does not rely on the user click save.
I could write a script that downloads a collection of all clients and walks through them to set the value, but there are more than 50,000 clients, and I am concerned about the impact of performance on execution on the production server ...
Any thoughts appreciated.
Jd
php attributes magento entity-attribute-value
Jonathan day
source share