1

I have to add custom Dropdown attribute to customer. Which have 3 options like Pending, Approved and Disapproved. So when we save customer i have to save this field value.

For this i have added field in the database table and created Dropdown in admin side form. but i am not understanding how to save this field data.

When status is changed also i have to send email. I am thinking to override Save controller of admin but not sure.

Please help me.

  • Please suggest me best way to do this. – Magecode Apr 17 '18 at 7:47
0

You have to add attribute to the customer not Column to the Database.

Please refer to this article to add attribute to the customer in correct way,

https://webkul.com/blog/how-to-create-customer-custom-attribute-in-magento-2-0/

in this article they added text attribute, you need to add select type instead for your case

when you create the attribute in the correct way, you will find it in the admin customer page and will be saved automatically as any other value.

for sending email you need to use the events, there is event (customer_save_after)

You have to check the original value and the new value, if the values are not the same that mean you changed the value of this attribute, if the value is changed then you can send email to the customer

it should be like this

{
    $oCustomer = $observer->getCustomer();
    $origin_data = $oCustomer->getOrigData("{your_attribute}");
    $new_data = $oCustomer->getData("your_attribute");
    // send email here
}

Hope this will help you

  • It's giving error Call to undefined method Magento\Customer\Model\Data\Customer::getOrigData() Call to undefined method Magento\Customer\Model\Data\Customer::getData() – Magecode Apr 20 '18 at 7:40

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.