コード例 #1
0
 /**
  * @return array
  */
 public function getList()
 {
     if (!$this->attributes) {
         $this->attributes = $this->getListForEntity($this->customerMetadata->getAllAttributesMetadata(), CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customerMetadataManagement);
         $this->attributes = array_merge($this->attributes, $this->getListForEntity($this->addressMetadata->getAllAttributesMetadata(), AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $this->addressMetadataManagement));
     }
     return $this->attributeFilter->filter($this->attributes);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function renderArray($addressAttributes, $format = null)
 {
     switch ($this->getType()->getCode()) {
         case 'html':
             $dataFormat = ElementFactory::OUTPUT_FORMAT_HTML;
             break;
         case 'pdf':
             $dataFormat = ElementFactory::OUTPUT_FORMAT_PDF;
             break;
         case 'oneline':
             $dataFormat = ElementFactory::OUTPUT_FORMAT_ONELINE;
             break;
         default:
             $dataFormat = ElementFactory::OUTPUT_FORMAT_TEXT;
             break;
     }
     $attributesMetadata = $this->_addressMetadataService->getAllAttributesMetadata();
     $data = [];
     foreach ($attributesMetadata as $attributeMetadata) {
         if (!$attributeMetadata->isVisible()) {
             continue;
         }
         $attributeCode = $attributeMetadata->getAttributeCode();
         if ($attributeCode == 'country_id' && isset($addressAttributes['country_id'])) {
             $data['country'] = $this->_countryFactory->create()->loadByCode($addressAttributes['country_id'])->getName();
         } elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) {
             $data['region'] = __($addressAttributes['region']);
         } elseif (isset($addressAttributes[$attributeCode])) {
             $value = $addressAttributes[$attributeCode];
             $dataModel = $this->_elementFactory->create($attributeMetadata, $value, 'customer_address');
             $value = $dataModel->outputValue($dataFormat);
             if ($attributeMetadata->getFrontendInput() == 'multiline') {
                 $values = $dataModel->outputValue(ElementFactory::OUTPUT_FORMAT_ARRAY);
                 // explode lines
                 foreach ($values as $k => $v) {
                     $key = sprintf('%s%d', $attributeCode, $k + 1);
                     $data[$key] = $v;
                 }
             }
             $data[$attributeCode] = $value;
         }
     }
     if ($this->getType()->getEscapeHtml()) {
         foreach ($data as $key => $value) {
             $data[$key] = $this->escapeHtml($value);
         }
     }
     $format = $format !== null ? $format : $this->getFormatArray($addressAttributes);
     return $this->filterManager->template($format, ['variables' => $data]);
 }
コード例 #3
0
ファイル: AbstractAddress.php プロジェクト: opexsw/magento2
 /**
  * Create address data object based on current address model.
  *
  * @param int|null $defaultBillingAddressId
  * @param int|null $defaultShippingAddressId
  * @return AddressInterface
  * @deprecated Use Api/Data/AddressInterface as a result of service operations. Don't rely on the model to provide
  * the instance of Api/Data/AddressInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getDataModel($defaultBillingAddressId = null, $defaultShippingAddressId = null)
 {
     $addressId = $this->getId();
     $attributes = $this->metadataService->getAllAttributesMetadata();
     $addressData = [];
     foreach ($attributes as $attribute) {
         $code = $attribute->getAttributeCode();
         if ($this->getData($code) !== null) {
             if ($code === AddressInterface::STREET) {
                 $addressData[$code] = $this->getDataUsingMethod($code);
             } else {
                 $addressData[$code] = $this->getData($code);
             }
         }
     }
     /** @var RegionInterface $region */
     $region = $this->regionDataFactory->create();
     $region->setRegion($this->getRegion())->setRegionCode($this->getRegionCode())->setRegionId($this->getRegionId());
     $addressData[AddressData::REGION] = $region;
     $addressDataObject = $this->addressDataFactory->create();
     $this->dataObjectHelper->populateWithArray($addressDataObject, $addressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     if ($addressId) {
         $addressDataObject->setId($addressId);
     }
     if ($this->getCustomerId() || $this->getParentId()) {
         $customerId = $this->getCustomerId() ?: $this->getParentId();
         $addressDataObject->setCustomerId($customerId);
         if ($defaultBillingAddressId == $addressId) {
             $addressDataObject->setIsDefaultBilling(true);
         }
         if ($defaultShippingAddressId == $addressId) {
             $addressDataObject->setIsDefaultShipping(true);
         }
     }
     return $addressDataObject;
 }
コード例 #4
0
 /**
  * Initialize form object
  *
  * @return $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function initForm()
 {
     $customerData = $this->_backendSession->getCustomerData();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset('address_fieldset', ['legend' => __("Edit Customer's Address")]);
     $account = $customerData['account'];
     $address = $this->addressDataFactory->create();
     if (!empty($account) && isset($account['store_id'])) {
         $address->setCountryId($this->_directoryHelper->getDefaultCountry($this->_storeManager->getStore($account['store_id'])));
     } else {
         $address->setCountryId($this->_directoryHelper->getDefaultCountry());
     }
     $addressForm = $this->_metadataFormFactory->create('customer_address', 'adminhtml_customer_address', $this->addressMapper->toFlatArray($address));
     $attributes = $addressForm->getAttributes();
     if (isset($attributes['street'])) {
         if ($attributes['street']->getMultilineCount() <= 0) {
             $attributes['street']->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT);
         }
     }
     foreach ($attributes as $key => $attribute) {
         $attributes[$key]->setFrontendLabel(__($attribute->getFrontendLabel()))->setIsVisible(false);
     }
     $this->_setFieldset($attributes, $fieldset);
     $regionElement = $form->getElement('region');
     if ($regionElement) {
         $regionElement->setRenderer($this->_regionFactory->create());
     }
     $regionElement = $form->getElement('region_id');
     if ($regionElement) {
         $regionElement->setNoDisplay(true);
     }
     $country = $form->getElement('country_id');
     if ($country) {
         $country->addClass('countries');
     }
     $postcode = $form->getElement('postcode');
     if ($postcode) {
         $postcode->removeClass('required-entry')->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
     }
     if ($this->isReadonly()) {
         foreach ($this->_addressMetadataService->getAllAttributesMetadata() as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
     $customerStoreId = null;
     if (!empty($account) && isset($account['id']) && isset($account['website_id'])) {
         $customerStoreId = $this->_storeManager->getWebsite($account['website_id'])->getDefaultStore()->getId();
     }
     $prefixElement = $form->getElement('prefix');
     if ($prefixElement) {
         $prefixOptions = $this->options->getNamePrefixOptions($customerStoreId);
         if (!empty($prefixOptions)) {
             $fieldset->removeField($prefixElement->getId());
             $prefixField = $fieldset->addField($prefixElement->getId(), 'select', $prefixElement->getData(), '^');
             $prefixField->setValues($prefixOptions);
         }
     }
     $suffixElement = $form->getElement('suffix');
     if ($suffixElement) {
         $suffixOptions = $this->options->getNameSuffixOptions($customerStoreId);
         if (!empty($suffixOptions)) {
             $fieldset->removeField($suffixElement->getId());
             $suffixField = $fieldset->addField($suffixElement->getId(), 'select', $suffixElement->getData(), $form->getElement('lastname')->getId());
             $suffixField->setValues($suffixOptions);
         }
     }
     $customerDataObject = $this->customerDataFactory->create();
     $this->dataObjectHelper->populateWithArray($customerDataObject, $account, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->assign('customer', $customerDataObject);
     $addressCollection = [];
     foreach ($customerData['address'] as $key => $addressData) {
         $addressDataObject = $this->addressDataFactory->create();
         $this->dataObjectHelper->populateWithArray($addressDataObject, $addressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
         $addressCollection[$key] = $addressDataObject;
     }
     $this->assign('addressCollection', $addressCollection);
     $form->setValues($this->addressMapper->toFlatArray($address));
     $this->setForm($form);
     return $this;
 }