Magento: save model object attribute value

Save a single attribute value of a customer, using the saveAttribute function. This is more efficient than save for saving only one attribute value.

$customer = Mage::getSingleton('customer/customer')->load(12345);
$customer->setEmail('dummy@dummy.com');
$customer->getResource()->saveAttribute($customer,'email');

Save multiple attributes of a customer, using the setData() to set the values, and then call save()

$customer = Mage::getSingleton('customer/customer')->load(12345);
$data = array('email'=>'dummy@dummy.com','firstname'=>'dummy'); // email and firstname are the attribute_code of the the customer object
$customer->setData($data);
$customer->save();

Search within Codexpedia

Custom Search

Search the entire web

Custom Search