0

I have a custom attribute for customers but when I try to set any value to this attribute it does not save.

I have this code:

public function getAllow(){
  $customer = Mage::getSingleton('customer/session')->getCustomer();    
  $customer->setAllowboms("0");
  $customer->save();
  return $customer->getAllowboms();
}

When I call the function getAllow() return the value 0 but if I comment $customer->setAllowBoms('0'); and $customer->save(); don't return any value.

  • what is the type of the attribute or any default value set? – Prasanta Hatui May 7 '18 at 7:15
1

To save the customer attribute you have to initiate customer model object and then set the attribute and save the model as shown below

$customerId=1;
$customer =Mage::getModel('customer/customer')->load($customerId);
$customer->setAllowboms("0");
$customer->save();

After that you can retrieve that attribute value from customer session as shown below:

public function getAllow(){
 $customer = Mage::getSingleton('customer/session')->getCustomer();    
 return $customer->getAllowboms();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.