I followed this post to create my custom entity. Now I registered an observer on the "customer_register_success" event and tried to save additional data in my custom entity. That doesn't work and I get the following error message:

Fatal error: Call to undefined method Magento\Customer\Api\Data\CustomerExtension::save()

What is wrong?

Here is my code of the observer:

public function __construct(
        \Psr\Log\LoggerInterface $logger, //log injection
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
        \Magento\Customer\Api\Data\CustomerExtensionFactory $customerExtensionFactory
) {

    $this->_logger = $logger;


    $this->_customerRepository = $customerRepository;
    $this->_customerExtensionFactory = $customerExtensionFactory;


public function execute(\Magento\Framework\Event\Observer $observer) {


    try { 

        //Get Customer object
        $event = $observer->getEvent();
        $customer = $event->getCustomer();      

        //Get Controller
        $controller = $event->getAccountController();

        //Get Additional Data from Controller
        $userName = $controller->getRequest()->getParam("user_name", "");

        //Create Customer Extension object
        $model = $this->_customerExtensionFactory->create(['customer_id' => $customer->getId()]);

        //Set User Name

        //Save Customer Extension object
    catch(\Exception $e)


1 Answer 1


The CustomerExtension is not a model and thus doesn't have any ability to save itself, it is basically just a data container for extension attributes on for the CustomerInterface. You would need to utilize the CustomerRepository in order to save the data.

In working with extension attributes you may have defined in a extension_attributes.xml more on DevDocs, here are some of the pieces involved:

// Get the entity Interface from the entity Repository
$entity = $this->entityRepositoryInterface->get($entityId);

// Get existing ExtensionAttributes or create one
$entityExtension = $entity->getExtensionAttributes();
if ($entityExtension == null) {
    $entityExtension = $this->entityExtensionFactory->create();

// Set a value on your attribute

// Set the ExtensionAttributes back to the entity

// Save the entity using the repository
  • Unfortunately I added an Extension Module named CustomerExtension. There was the Problem...
    – ClassMP
    Jan 27, 2016 at 7: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.