示例#1
0
 public function testToFlatArray()
 {
     $expectedResultWithoutStreet = ['id' => 1, 'default_shipping' => false, 'default_billing' => true, 'firstname' => 'John', 'lastname' => 'Doe', 'city' => 'Austin', 'country_id' => 'US', 'region_id' => 1, 'region' => 'Texas', 'region_code' => 'TX'];
     $expectedResultWithStreet = array_merge($expectedResultWithoutStreet, ['street' => ['7700 W Parmer Ln', 'Austin, TX']]);
     $this->extensibleObjectConverter->expects($this->once())->method('toFlatArray')->willReturn($expectedResultWithoutStreet);
     $addressData = $this->createAddressMock();
     $result = $this->addressMapper->toFlatArray($addressData);
     $this->assertEquals($expectedResultWithStreet, $result);
 }
 /**
  * @param string $type
  * @return string
  */
 public function getAddressesHtmlSelect($type)
 {
     if ($this->isCustomerLoggedIn()) {
         $options = [];
         try {
             $addresses = $this->_getCustomer()->getAddresses();
         } catch (NoSuchEntityException $e) {
             $addresses = [];
         }
         foreach ($addresses as $address) {
             $builtOutputAddressData = $this->addressMapper->toFlatArray($address);
             $label = $this->_addressConfig->getFormatByCode(AddressConfig::DEFAULT_ADDRESS_FORMAT)->getRenderer()->renderArray($builtOutputAddressData);
             $options[] = ['value' => $address->getId(), 'label' => $label];
         }
         $addressId = $this->getAddress()->getCustomerAddressId();
         if (empty($addressId)) {
             try {
                 if ($type == 'billing') {
                     $addressId = $this->_getCustomer()->getDefaultBilling();
                 } else {
                     $addressId = $this->_getCustomer()->getDefaultShipping();
                 }
             } catch (NoSuchEntityException $e) {
                 // Do nothing
             }
         }
         $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName($type . '_address_id')->setId($type . ':address-select')->setClass('address-select')->setValue($addressId)->setOptions($options);
         $select->addOption('', __('New Address'));
         return $select->getHtml();
     }
     return '';
 }
示例#3
0
 /**
  * Represent customer address in HTML format.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getAddressAsHtml(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $formatTypeRenderer = $this->_customerAddressHelper->getFormatTypeRenderer('html');
     $result = '';
     if ($formatTypeRenderer) {
         $result = $formatTypeRenderer->renderArray($this->addressMapper->toFlatArray($address));
     }
     return $result;
 }
示例#4
0
 /**
  * Render an address as HTML and return the result
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getAddressHtml(\Magento\Customer\Api\Data\AddressInterface $address = null)
 {
     if ($address !== null) {
         /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
         $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
         return $renderer->renderArray($this->addressMapper->toFlatArray($address));
     }
     return '';
 }
示例#5
0
 /**
  * Represent customer address in 'online' format.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getAddressAsString(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $formatTypeRenderer = $this->_addressHelper->getFormatTypeRenderer('oneline');
     $result = '';
     if ($formatTypeRenderer) {
         $result = $formatTypeRenderer->renderArray($this->addressMapper->toFlatArray($address));
     }
     return $this->escapeHtml($result);
 }
示例#6
0
 /**
  * Retrieve billing address html
  *
  * @return \Magento\Framework\Phrase|string
  */
 public function getBillingAddressHtml()
 {
     try {
         $address = $this->accountManagement->getDefaultBillingAddress($this->getCustomer()->getId());
     } catch (NoSuchEntityException $e) {
         return __('The customer does not have default billing address.');
     }
     if ($address === null) {
         return __('The customer does not have default billing address.');
     }
     return $this->addressHelper->getFormatTypeRenderer('html')->renderArray($this->addressMapper->toFlatArray($address));
 }
 /**
  * Put existing customer data into the backend session
  */
 protected function setupExistingCustomerData()
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $this->_customerRepository->getById(1);
     $this->_customerData = ['customer_id' => $customer->getId(), 'account' => $this->customerMapper->toFlatArray($customer)];
     $this->_customerData['account']['id'] = $customer->getId();
     /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
     $addresses = $customer->getAddresses();
     foreach ($addresses as $addressData) {
         $this->_customerData['address'][$addressData->getId()] = $this->addressMapper->toFlatArray($addressData);
         $this->_customerData['address'][$addressData->getId()]['id'] = $addressData->getId();
     }
     $this->_backendSession->setCustomerData($this->_customerData);
 }
示例#8
0
 /**
  * Retrieve options for addresses dropdown
  *
  * @return array
  */
 public function getAddressOptions()
 {
     $options = $this->getData('address_options');
     if ($options === null) {
         $options = [];
         $addresses = [];
         try {
             $addresses = $this->customerRepository->getById($this->getCustomerId())->getAddresses();
         } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
             /** Customer does not exist */
         }
         /** @var \Magento\Customer\Api\Data\AddressInterface $address */
         foreach ($addresses as $address) {
             $label = $this->_addressConfig->getFormatByCode(AddressConfig::DEFAULT_ADDRESS_FORMAT)->getRenderer()->renderArray($this->addressMapper->toFlatArray($address));
             $options[] = ['value' => $address->getId(), 'label' => $label];
         }
         $this->setData('address_options', $options);
     }
     return $options;
 }
示例#9
0
 /**
  * Get order data jason
  *
  * @return string
  */
 public function getOrderDataJson()
 {
     $data = [];
     if ($this->getCustomerId()) {
         $data['customer_id'] = $this->getCustomerId();
         $data['addresses'] = [];
         $addresses = $this->customerRepository->getById($this->getCustomerId())->getAddresses();
         foreach ($addresses as $address) {
             $addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address', $this->addressMapper->toFlatArray($address));
             $data['addresses'][$address->getId()] = $addressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON);
         }
     }
     if ($this->getStoreId() !== null) {
         $data['store_id'] = $this->getStoreId();
         $currency = $this->_localeCurrency->getCurrency($this->getStore()->getCurrentCurrencyCode());
         $symbol = $currency->getSymbol() ? $currency->getSymbol() : $currency->getShortName();
         $data['currency_symbol'] = $symbol;
         $data['shipping_method_reseted'] = !(bool) $this->getQuote()->getShippingAddress()->getShippingMethod();
         $data['payment_method'] = $this->getQuote()->getPayment()->getMethod();
     }
     return $this->_jsonEncoder->encode($data);
 }
示例#10
0
 /**
  * Import quote address data from customer address Data Object.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return $this
  */
 public function importCustomerAddressData(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $this->_objectCopyService->copyFieldsetToTarget('customer_address', 'to_quote_address', $this->addressMapper->toFlatArray($address), $this);
     $quote = $this->getQuote();
     if ($address->getCustomerId() && (!empty($quote) && $address->getCustomerId() == $quote->getCustomerId())) {
         $customer = $quote->getCustomer();
         $this->setEmail($customer->getEmail());
     }
     return $this;
 }
示例#11
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function render(AddressModelInterface $address, $format = null)
 {
     $address = $address->getDataModel(0, 0);
     return $this->renderArray($this->addressMapper->toFlatArray($address), $format);
 }
示例#12
0
 /**
  * Render an address as HTML and return the result
  *
  * @param AddressInterface $address
  * @return string
  */
 protected function _getAddressHtml($address)
 {
     /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
     $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
     return $renderer->renderArray($this->addressMapper->toFlatArray($address));
 }
示例#13
0
 /**
  * Format the given address to the given type
  *
  * @param AddressInterface $address
  * @param string $type
  * @return string
  */
 public function format(AddressInterface $address, $type)
 {
     return $this->_addressHelper->getFormatTypeRenderer($type)->renderArray($this->addressMapper->toFlatArray($address));
 }
示例#14
0
 /**
  * Set additional customer address data
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 private function getCustomerAddressInline($address)
 {
     $builtOutputAddressData = $this->addressMapper->toFlatArray($address);
     return $this->addressConfig->getFormatByCode(\Magento\Customer\Model\Address\Config::DEFAULT_ADDRESS_FORMAT)->getRenderer()->renderArray($builtOutputAddressData);
 }