3

Is it possible to programmatically set the value of a custom customer attribute? I have scoured the internet for an answer to this, but to no avail :(.

I know that you can access one using this method:

$customer = Mage::getSingleton('customer/session')->getCustomer();
$measurements_taken = $customer->getResource()->getAttribute('measurements_taken')->getFrontend()->getValue($customer);

but I'm not too sure on how to set the value of this attribute. I tried the following:

$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->setMeasurementsTaken('TO_CHECK');
$customer->saveAttribute($customer,'measurements_taken');

but it throws an error saying something about an invalid method.

1
  • 1
    complete error please ......................... Commented May 31, 2013 at 8:24

1 Answer 1

3

After making your updates,

$customer->save();

or

$customer->setMeasurementsTaken('TO_CHECK')->save();
Sign up to request clarification or add additional context in comments.

5 Comments

it won't help with his error "an error saying something about an invalid method" ...
@Bixi How will it not help? Mage_Customer_Model_Session::getCustomer() returns an instance of Mage_Customer_Model_Customer, which does not have a saveAttribute() method but does have a save() method.
I tried this, and it didn't throw any errors! However, it did not change the attribute's value in the back-end :(
@NateTheGreatt You may need to set some additional scope-related info based on your local configuration. You can debug this in Mage_Customer_Model_Resource_Customer::_beforeSave()
I realized that it was a drop-down select attribute! Changing it to a text field attribute worked like a charm :). However, for the sake of knowledge, do you know how to change a drop-down select attribute?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.