0

Every time I need to clear cache when saving customer attributes using the following code.

$customerData->setCustomAttribute('custom_name', $name); $customermodel->updateData($customerData);

what is the proper solution to save customer custom attributes in Magento2?

0

use Factory and try the following code

$customerData->setCustomAttribute('custom_name', $name);            
$customerModel = $this->customerFactory->create()->updateData(
        $customerData
    );
  • I tried this way but still need to clear cache $customerFactory= $ob->create('Magento\Customer\Model\CustomerFactory'); $customerData->setCustomAttribute('custom_name', $name); $customerModel = $customerFactory->create()->updateData( $customerData ); $customerResource = $objectManager->create ('\Magento\Customer\Model\ResourceModel\CustomerFactory')->create(); $customerResource->saveAttribute($customerModel, 'custom_name'); – Vamsi Jul 12 '18 at 13:44

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.