0

I am working on extension and need to set customer custom attribute value. I tried the following code, but it's not working , can you please help me with this.

$customer = $this->customerFactory->create(); $customer->setId($observer->getEvent()->getCustomer()->getId()); $customerData = $customer->getDataModel(); $customerData->setCustomAttribute('mobilenumber','123465798'); $customer->updateData($customerData); $customer->save(); 
1

1 Answer 1

1

Try using below code,

//declare repository protected $repository; //inside your function $this->repository = $this->_objectManager->create('Magento\Customer\Api\AddressRepositoryInterface'); $customerId = 5; //get customer id $address = $this->repository->getById($customerId); $customerData = $address; // change phone # $customerData->setMobilenumber('12345678'); $customerDataSave = $this->repository->save($customerData); 
2
  • Thank you for answer, full solution not work for me, but i can get idea from your code, so Thank you so much. Commented May 17, 2016 at 14:17
  • @bharatdesai please post the solution as answer Commented Dec 30, 2016 at 10:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.