Example #1
0
 /**
  * @param \Magento\Sales\Model\Quote\Address $address
  * @return \Magento\Checkout\Service\V1\Data\Cart\Address
  */
 public function convertModelToDataObject(\Magento\Sales\Model\Quote\Address $address)
 {
     $data = [Address::KEY_COUNTRY_ID => $address->getCountryId(), Address::KEY_ID => $address->getId(), Address::KEY_CUSTOMER_ID => $address->getCustomerId(), Address::KEY_REGION => array(Region::KEY_REGION => $address->getRegion(), Region::KEY_REGION_ID => $address->getRegionId(), Region::KEY_REGION_CODE => $address->getRegionCode()), Address::KEY_STREET => $address->getStreet(), Address::KEY_COMPANY => $address->getCompany(), Address::KEY_TELEPHONE => $address->getTelephone(), Address::KEY_FAX => $address->getFax(), Address::KEY_POSTCODE => $address->getPostcode(), Address::KEY_CITY => $address->getCity(), Address::KEY_FIRSTNAME => $address->getFirstname(), Address::KEY_LASTNAME => $address->getLastname(), Address::KEY_MIDDLENAME => $address->getMiddlename(), Address::KEY_PREFIX => $address->getPrefix(), Address::KEY_SUFFIX => $address->getSuffix(), Address::KEY_EMAIL => $address->getEmail(), Address::KEY_VAT_ID => $address->getVatId()];
     foreach ($this->metadataService->getCustomAttributesMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $method = 'get' . SimpleDataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $data[Address::CUSTOM_ATTRIBUTES_KEY][] = [AttributeValue::ATTRIBUTE_CODE => $attributeCode, AttributeValue::VALUE => $address->{$method}()];
     }
     return $this->addressBuilder->populateWithArray($data)->create();
 }
Example #2
0
 /**
  * Import customer address to quote address
  */
 public function testImportCustomerAddressDataWithCustomer()
 {
     $customerIdFromFixture = 1;
     $customerEmailFromFixture = '*****@*****.**';
     $city = 'TestCity';
     $street = 'Street1';
     /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder */
     $addressBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
     $addressData = $addressBuilder->setCustomerId($customerIdFromFixture)->setCity($city)->setStreet([$street])->create();
     $this->_address->setQuote($this->_quote);
     $this->_address->importCustomerAddressData($addressData);
     $this->assertEquals($customerEmailFromFixture, $this->_address->getEmail(), 'Email was imported incorrectly.');
     $this->assertEquals($city, $this->_address->getCity(), 'City was imported incorrectly.');
     $this->assertEquals($street, $this->_address->getStreetFull(), 'Imported street is invalid.');
 }
Example #3
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  \Magento\Sales\Model\Quote\Address $value
  * @return boolean
  * @throws Zend_Validate_Exception If validation of $value is impossible
  */
 public function isValid($value)
 {
     $messages = array();
     $email = $value->getEmail();
     if (!empty($email) && !\Zend_Validate::is($email, 'EmailAddress')) {
         $messages['invalid_email_format'] = 'Invalid email format';
     }
     $countryId = $value->getCountryId();
     if (!empty($countryId)) {
         $country = $this->countryFactory->create();
         $country->load($countryId);
         if (!$country->getId()) {
             $messages['invalid_country_code'] = 'Invalid country code';
         }
     }
     $this->_addMessages($messages);
     return empty($messages);
 }