/** * @param CustomerInterface $entity * @param array $arguments * @return CustomerInterface * @throws \Exception * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute($entity, $arguments = []) { $metadata = $this->metadataPool->getMetadata(ExtensionAttributeInterface::class); $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName()); $id = $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where('customer_id = ?', $entity->getId())->limit(1)); $extensionAttribute = $this->extensionAttributeFactory->create(); $extensionAttribute = $this->entityManager->load($extensionAttribute, $id); $customerExtension = $this->customerExtensionFactory->create(['data' => ['extension_attribute' => $extensionAttribute]]); $entity->setExtensionAttributes($customerExtension); return $entity; }
/** * @param Customer $customer * @param $customerDataObject * @return \Magento\Customer\Model\Data\Customer */ public function afterGetDataModel(Customer $customer, $customerDataObject) { $openpayCustomerId = $this->customerHelper->getOpenpayCustomerId($customerDataObject); if (!is_null($openpayCustomerId)) { $openpayCards = $this->getCardsFromOpenpay($openpayCustomerId); $openpayCustomer = $this->getCustomerFromOpenpay($openpayCustomerId); $extensionAttributes = $this->customerExtensionFactory->create()->setOpenpayCard($openpayCards)->setOpenpayCustomer($openpayCustomer); $customerDataObject->setExtensionAttributes($extensionAttributes); } return $customerDataObject; }