repository = $repository; $this->config = $config; } /** * Load the Vertex Customer Code into the Customer Data Provider for use in the Admin form * * @see DataProvider::getData() Intercepted method * @param DataProvider $subject * @param array $data * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetData(AbstractDataProvider $subject, $data) { if (empty($data) || !$this->config->isVertexActive()) { return $data; } $customerIds = []; foreach ($data as $fieldData) { if (!isset($fieldData['customer']['entity_id'])) { continue; } $customerIds[] = $fieldData['customer']['entity_id']; } $customerCodes = $this->repository->getListByCustomerIds($customerIds); foreach ($data as $dataKey => $fieldData) { if (!isset($fieldData['customer']['entity_id'], $customerCodes[$fieldData['customer']['entity_id']])) { continue; } $entityId = $fieldData['customer']['entity_id']; $customerCode = $customerCodes[$entityId]->getCustomerCode(); $data[$dataKey]['customer']['extension_attributes']['vertex_customer_code'] = $customerCode; } return $data; } }