/**
  * Transfer data from an address validation address to a customer address.
  *
  * @param CustomerAddressInterface
  * @param AddressInterface|null
  * @return CustomerAddressInterface
  */
 public function transferDataAddressToCustomerAddress(CustomerAddressInterface $customerAddress, AddressInterface $dataAddress = null)
 {
     if ($dataAddress) {
         $region = $customerAddress->getRegion();
         $region->setRegionCode($dataAddress->getRegionCode())->setRegionId($dataAddress->getRegionId())->setRegion($dataAddress->getRegionName());
         $customerAddress->setStreet($dataAddress->getStreet())->setCity($dataAddress->getCity())->setCountryId($dataAddress->getCountryId())->setPostcode($dataAddress->getPostcode())->setRegion($region);
     }
     return $customerAddress;
 }
Exemplo n.º 2
0
 public function testExecuteWithException()
 {
     $addressId = 1;
     $customerId = 2;
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId);
     $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true);
     $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address);
     $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
     $this->address->expects($this->once())->method('getCustomerId')->willReturn(34);
     $exception = new \Exception('Exception');
     $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.'));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf();
     $this->assertSame($this->resultRedirect, $this->model->execute());
 }
 protected function prepareMocksForUpdateDefaultBilling()
 {
     $this->prepareMocksForProcessAddressData();
     $addressData = ['postcode' => '07294', 'firstname' => 'Firstname', 'lastname' => 'Lastname'];
     $this->customerData->expects($this->once())->method('getAddresses')->willReturn([$this->address]);
     $this->address->expects($this->once())->method('isDefaultBilling')->willReturn(true);
     $this->dataObjectHelper->expects($this->at(0))->method('populateWithArray')->with($this->address, $addressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
 }
Exemplo n.º 4
0
 /**
  * Get URL of page, at which customer billing address can be set.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getSetAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     return $this->getUrl('*/*/setBilling', ['id' => $address->getId()]);
 }
Exemplo n.º 5
0
 /**
  * Retrieve the Url for editing the specified address.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getAddressEditUrl($address)
 {
     return $this->_urlBuilder->getUrl('customer/address/edit', ['_secure' => true, 'id' => $address->getId()]);
 }
Exemplo n.º 6
0
 /**
  * This method is necessary because a customer address does not have a getData() method to retrieve all the address
  * fields.
  *
  * @param CustomerAddressInterface $customerAddress
  * @return array
  */
 protected function getCustomerAddressData(CustomerAddressInterface $customerAddress)
 {
     $customerAddressData = [CustomerAddressInterface::COUNTRY_ID => $customerAddress->getCountryId(), CustomerAddressInterface::STREET => $customerAddress->getStreet(), CustomerAddressInterface::POSTCODE => $customerAddress->getPostcode(), CustomerAddressInterface::CITY => $customerAddress->getCity(), CustomerAddressInterface::COMPANY => $customerAddress->getCompany(), CustomerAddressInterface::CUSTOM_ATTRIBUTES => $customerAddress->getCustomAttributes(), CustomerAddressInterface::CUSTOMER_ID => $customerAddress->getCustomerId(), CustomerAddressInterface::EXTENSION_ATTRIBUTES_KEY => $customerAddress->getExtensionAttributes(), CustomerAddressInterface::FAX => $customerAddress->getFax(), CustomerAddressInterface::FIRSTNAME => $customerAddress->getFirstname(), CustomerAddressInterface::ID => $customerAddress->getId(), CustomerAddressInterface::LASTNAME => $customerAddress->getLastname(), CustomerAddressInterface::MIDDLENAME => $customerAddress->getMiddlename(), CustomerAddressInterface::PREFIX => $customerAddress->getPrefix(), CustomerAddressInterface::REGION => $customerAddress->getRegion(), CustomerAddressInterface::REGION_ID => $customerAddress->getRegionId(), CustomerAddressInterface::STREET => $customerAddress->getStreet(), CustomerAddressInterface::SUFFIX => $customerAddress->getSuffix(), CustomerAddressInterface::TELEPHONE => $customerAddress->getTelephone(), CustomerAddressInterface::VAT_ID => $customerAddress->getVatId(), CustomerAddressInterface::DEFAULT_BILLING => $customerAddress->isDefaultBilling(), CustomerAddressInterface::DEFAULT_SHIPPING => $customerAddress->isDefaultShipping()];
     return $customerAddressData;
 }
Exemplo n.º 7
0
 /**
  * @param AddressInterface $address
  * @return $this
  */
 public function initAddressForm(AddressInterface $address)
 {
     $form = $this->initForm()->getForm();
     $postcode = $form->getElement('postcode');
     if ($postcode) {
         $postcode->removeClass('required-entry')->setRequired(!$this->_directoryHelper->isZipCodeOptional($address->getCountryId()));
     }
     $form->addValues($this->addressMapper->toFlatArray($address))->setHtmlIdPrefix("_item{$address->getId()}")->setFieldNameSuffix('address[' . $address->getId() . ']');
     $this->addValuesToNamePrefixElement($address->getPrefix())->addValuesToNameSuffixElement($address->getSuffix());
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Get request object with information necessary for getting tax rate
  *
  * Request object contain:
  *  country_id (->getCountryId())
  *  region_id (->getRegionId())
  *  postcode (->getPostcode())
  *  customer_class_id (->getCustomerClassId())
  *  store (->getStore())
  *
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $shippingAddress
  * @param null|bool|\Magento\Framework\Object|CustomerAddress $billingAddress
  * @param null|int $customerTaxClass
  * @param null|int|\Magento\Store\Model\Store $store
  * @param int $customerId
  * @return  \Magento\Framework\Object
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null, $customerId = null)
 {
     if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
         return $this->getRateOriginRequest($store);
     }
     $address = new \Magento\Framework\Object();
     $basedOn = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') {
         $basedOn = 'default';
     } else {
         if (($billingAddress === null || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === null || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') {
             if ($customerId) {
                 try {
                     $defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 try {
                     $defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 if ($basedOn == 'billing' && isset($defaultBilling) && $defaultBilling->getCountryId()) {
                     $billingAddress = $defaultBilling;
                 } elseif ($basedOn == 'shipping' && isset($defaultShipping) && $defaultShipping->getCountryId()) {
                     $shippingAddress = $defaultShipping;
                 } else {
                     $basedOn = 'default';
                 }
             } else {
                 $basedOn = 'default';
             }
         }
     }
     switch ($basedOn) {
         case 'billing':
             $address = $billingAddress;
             break;
         case 'shipping':
             $address = $shippingAddress;
             break;
         case 'origin':
             $address = $this->getRateOriginRequest($store);
             break;
         case 'default':
             $address->setCountryId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setRegionId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setPostcode($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store));
             break;
         default:
             break;
     }
     if ($customerTaxClass === null || $customerTaxClass === false) {
         if ($customerId) {
             $customerData = $this->customerRepository->getById($customerId);
             $customerTaxClass = $this->customerGroupRepository->getById($customerData->getGroupId())->getTaxClassId();
         } else {
             $customerTaxClass = $this->customerGroupManagement->getNotLoggedInGroup()->getTaxClassId();
         }
     }
     $request = new \Magento\Framework\Object();
     //TODO: Address is not completely refactored to use Data objects
     if ($address->getRegion() instanceof AddressRegion) {
         $regionId = $address->getRegion()->getRegionId();
     } else {
         $regionId = $address->getRegionId();
     }
     $request->setCountryId($address->getCountryId())->setRegionId($regionId)->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass);
     return $request;
 }
 /**
  * Store the original customer address data.
  *
  * @param CustomerAddressInterface
  * @return self
  */
 public function setOriginalCustomerAddress(CustomerAddressInterface $address)
 {
     $region = $address->getRegion() ?: $this->customerRegionFactory->create();
     $addressData = ['id' => $address->getId(), 'customer_id' => $address->getCustomerId(), 'region' => ['region_id' => $region->getRegionId(), 'region_code' => $region->getRegionCode(), 'region' => $region->getRegion()], 'country_id' => $address->getCountryId(), 'street' => $address->getStreet(), 'company' => $address->getCompany(), 'telephone' => $address->getTelephone(), 'fax' => $address->getFax(), 'postcode' => $address->getPostcode(), 'city' => $address->getCity(), 'firstname' => $address->getFirstname(), 'lastname' => $address->getLastname(), 'middlename' => $address->getMiddlename(), 'prefix' => $address->getPrefix(), 'suffix' => $address->getSuffix(), 'vat_id' => $address->getVatId(), 'is_default_shipping' => $address->isDefaultShipping(), 'is_default_billing' => $address->isDefaultBilling()];
     $this->sessionManager->setOriginalCustomerAddressData($addressData);
 }
Exemplo n.º 10
0
 /**
  * Delete customer address.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return bool true on success
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function delete(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $addressId = $address->getId();
     $address = $this->addressRegistry->retrieve($addressId);
     $customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
     $customerModel->getAddressesCollection()->clear();
     $this->addressResource->delete($address);
     $this->addressRegistry->remove($addressId);
     return true;
 }
Exemplo n.º 11
0
 /**
  * Return the specified numbered street line.
  *
  * @param int $lineNumber
  * @return string
  */
 public function getStreetLine($lineNumber)
 {
     $street = $this->_address->getStreet();
     return isset($street[$lineNumber - 1]) ? $street[$lineNumber - 1] : '';
 }
 /**
  * Format the address object to match an expected format.
  *
  * @param AddressInterface
  * @return string
  */
 protected function formatAddressData(AddressInterface $address)
 {
     return implode(' ', $address->getStreet()) . ' ' . $address->getCity() . ', ' . $address->getRegion()->getRegion() . ', ' . $address->getPostcode() . ' ' . $this->getCountryName($address->getCountryId());
 }