I am trying to load Magento\Customer\Api\Data\CustomerExtensionFactory in a plugin using the ObjectManager injected in the Plugin constructor. The file var\generation\Magento\Customer\Api\Data\CustomerExtensionFactory.php does exist. When I run $this->customerExtensionFactory = $objectManager->get(self::CUSTOMER_EXTENSION_FACTORY_PATH); in my Plugin it throws an error: "Notice: Undefined index: instance in \/vagrant\/data\/magento2\/lib\/internal\/Magento\/Framework\/ObjectManager\/Factory\/AbstractFactory.php on line 222"
My Plugin code is this:
<?php namespace My\Module\Model\Plugin\Card; use Magento\Customer\Api\Data\CustomerExtensionFactory; use Magento\Customer\Model\Customer; use Magento\Framework\ObjectManager\ObjectManager; class MyPlugin { const CUSTOMER_EXTENSION_FACTORY_PATH = 'Magento\Customer\Api\Data\CustomerExtensionFactory'; /** * @var \Magento\Customer\Api\Data\CustomerExtensionFactory */ protected $customerExtensionFactory; public function __construct(ObjectManager $objectManager) { /** * @var \Magento\Customer\Api\Data\CustomerExtensionFactory */ $this->customerExtensionFactory = $objectManager->get(self::CUSTOMER_EXTENSION_FACTORY_PATH); } public function afterGetDataModel(Customer $customer, $customerDataObject) { $extension = $this->customerExtensionFactory->create()->setOpenpayCard('aaa-123'); $customerDataObject->setExtensionAttributes($extension); return $customerDataObject; } } Any ideas on what that may be?