예제 #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();
 }
예제 #2
0
 public function testValidateWithValidAddress()
 {
     $addressCustomer = 100;
     $addressId = 100;
     /** Address data object */
     $addressData = $this->addressDataBuilder->setId($addressId)->setCompany('eBay Inc')->setCustomerId($addressCustomer)->create();
     /** Customer mock */
     $this->customerFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->customerMock));
     $this->customerMock->expects($this->once())->method('load')->with($addressCustomer);
     $this->customerMock->expects($this->once())->method('getId')->will($this->returnValue($addressCustomer));
     /** Quote address mock */
     $this->addressFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->quoteAddressMock));
     $this->quoteAddressMock->expects($this->once())->method('load')->with($addressId);
     $this->quoteAddressMock->expects($this->once())->method('getId')->will($this->returnValue($addressId));
     $this->quoteAddressMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($addressCustomer));
     /** Validate */
     $this->model->validate($addressData);
 }