I have created one 'test' text customer attribute. I have added input field on frontend customer register form. I can able to save this attribute value by override createPost.php from my custom module.

But I think this is not proper way to save value by override controller. There is any way to save customer attribute using plugin or observer?

  • Please share your observer code
    – Arunendra
    Jan 11, 2017 at 6:10
  • Right now i have no observer code i have done it with override createpost controller Jan 11, 2017 at 6:12
  • You have mentioned that "I have also used customer save after" that's whay i have asked
    – Arunendra
    Jan 11, 2017 at 6:14
  • Yes I have tried it but at that time it was not working so i used second solution by override controller Jan 11, 2017 at 6:30

1 Answer 1


You can do this by observer.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="customer_register_success">
        <observer name="sr_customer_account_createPost" instance="SR\StackExchange\Observer\CustomerRegisterSuccess" />


namespace SR\StackExchange\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use Magento\Customer\Api\CustomerRepositoryInterface;

class CustomerRegisterSuccess implements ObserverInterface
    /** @var CustomerRepositoryInterface */
    protected $customerRepository;

     * @param CustomerRepositoryInterface $customerRepository
    public function __construct(
        CustomerRepositoryInterface $customerRepository
    ) {
        $this->customerRepository = $customerRepository;

     * Manages redirect
    public function execute(Observer $observer)
        $accountController = $observer->getAccountController();
        $customer = $observer->getCustomer();
        $request = $accountController->getRequest();
        $customer_number = $request->getParam('customer_number');
        $customer->setCustomAttribute('customer_number', $customer_number);

NB: here 'customer_number' is custom attribute

  • how do we get customer id here please reply me thanks Nov 20, 2017 at 11:32
  • 1
    @SohelRana: PHP Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Customer\Model\ResourceModel\CustomerRepository\Interceptor::save() must implement interface Magento\Customer\Api\Data\CustomerInterface Jul 10, 2018 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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