When magento2 store has 3rd parties system integration then we might be need to store 3rd parties data in magento to make relationships.
We might be need additional attribute to save 3rd parties data in magento 2. Here is post for create new customer attribute in magento2.
https://www.magedad.com/magento-2-create-a-customer-attribute-programmatically-using-setup-data-patch/
1. Get Custom Customer Attribute Value Programatically
/* Magento\Customer\Api\CustomerRepositoryInterface */
$customer = $this->customerRepository->getById($customerId);
$externalIdAttribute = $customer->getCustomAttribute('external_id');
if ($externalIdAttribute) {
$externalId = $externalIdAttribute->getValue();
}
2. Save Custom Customer Attribute Value Programatically
/* Magento\Customer\Api\CustomerRepositoryInterface */
$customer = $this->customerRepository->getById($customerId);
$customer->setCustomAttribute('external_id', 'ABC123');
$this->customerRepository->save($customer);
That’s it. We also have other customer related post might be it’s help to you.
- How to create customer using REST API?
- Create a customer address attribute programmatically using setup data patch
You can follow this link for more help.
I hope this blog is useful to set/get customer attribute value in magento2 and save. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.
Keep liking 👍 Keep sharing 📣 Keep loving ❤️ Keep inspiring 🤩