Esempio n. 1
0
 public function testConvertModelToDataObject()
 {
     $addressMockMethods = ['getCountryId', 'getId', 'getCustomerId', 'getRegion', 'getRegionId', 'getRegionCode', 'getStreet', 'getCompany', 'getTelephone', 'getFax', 'getPostcode', 'getFirstname', 'getMiddlename', 'getLastname', 'getPrefix', 'getSuffix', 'getEmail', 'getVatId', 'getCustomField', 'getCity', '__wakeup'];
     $addressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', $addressMockMethods, [], '', false);
     $addressMock->expects($this->atLeastOnce())->method('getCountryId')->will($this->returnValue(1));
     $addressMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(2));
     $addressMock->expects($this->atLeastOnce())->method('getCustomerId')->will($this->returnValue(3));
     $addressMock->expects($this->atLeastOnce())->method('getRegion')->will($this->returnValue('Alabama'));
     $addressMock->expects($this->atLeastOnce())->method('getRegionId')->will($this->returnValue(4));
     $addressMock->expects($this->atLeastOnce())->method('getRegionCode')->will($this->returnValue('aa'));
     $addressMock->expects($this->atLeastOnce())->method('getStreet')->will($this->returnValue('street'));
     $addressMock->expects($this->atLeastOnce())->method('getCompany')->will($this->returnValue('company'));
     $addressMock->expects($this->atLeastOnce())->method('getTelephone')->will($this->returnValue('123-123'));
     $addressMock->expects($this->atLeastOnce())->method('getFax')->will($this->returnValue('234-234'));
     $addressMock->expects($this->atLeastOnce())->method('getPostcode')->will($this->returnValue('80010'));
     $addressMock->expects($this->atLeastOnce())->method('getCity')->will($this->returnValue('Town'));
     $addressMock->expects($this->atLeastOnce())->method('getFirstname')->will($this->returnValue('Vasya'));
     $addressMock->expects($this->atLeastOnce())->method('getMiddlename')->will($this->returnValue('Vasya'));
     $addressMock->expects($this->atLeastOnce())->method('getLastname')->will($this->returnValue('Pupkin'));
     $addressMock->expects($this->atLeastOnce())->method('getPrefix')->will($this->returnValue('prefix'));
     $addressMock->expects($this->atLeastOnce())->method('getSuffix')->will($this->returnValue('suffix'));
     $addressMock->expects($this->atLeastOnce())->method('getEmail')->will($this->returnValue('*****@*****.**'));
     $addressMock->expects($this->atLeastOnce())->method('getVatId')->will($this->returnValue(5));
     $addressMock->expects($this->atLeastOnce())->method('getCustomField')->will($this->returnValue('custom_value'));
     $testData = [Address::KEY_COUNTRY_ID => 1, Address::KEY_ID => 2, Address::KEY_CUSTOMER_ID => 3, Address::KEY_REGION => [Region::REGION => 'Alabama', Region::REGION_ID => 4, Region::REGION_CODE => 'aa'], Address::KEY_STREET => 'street', Address::KEY_COMPANY => 'company', Address::KEY_TELEPHONE => '123-123', Address::KEY_FAX => '234-234', Address::KEY_POSTCODE => '80010', Address::KEY_CITY => 'Town', Address::KEY_FIRSTNAME => 'Vasya', Address::KEY_LASTNAME => 'Pupkin', Address::KEY_MIDDLENAME => 'Vasya', Address::KEY_PREFIX => 'prefix', Address::KEY_SUFFIX => 'suffix', Address::KEY_EMAIL => '*****@*****.**', Address::KEY_VAT_ID => 5, Address::CUSTOM_ATTRIBUTES_KEY => [['attribute_code' => 'custom_field', 'value' => 'custom_value']]];
     $this->metadataServiceMock->expects($this->any())->method('getCustomAttributesMetadata')->will($this->returnValue([new \Magento\Framework\Object(['attribute_code' => 'custom_field'])]));
     $this->addressBuilderMock->expects($this->once())->method('populateWithArray')->with($testData)->will($this->returnValue($this->addressBuilderMock));
     $this->addressBuilderMock->expects($this->once())->method('create')->will($this->returnValue('Expected value'));
     $this->assertEquals('Expected value', $this->model->convertModelToDataObject($addressMock));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getAddress($cartId)
 {
     $storeId = $this->storeManager->getStore()->getId();
     /** @var  \Magento\Sales\Model\Quote\Address $address */
     $address = $this->quoteLoader->load($cartId, $storeId)->getBillingAddress();
     return $this->addressConverter->convertModelToDataObject($address);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function getAddress($cartId)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     if ($quote->isVirtual()) {
         throw new NoSuchEntityException('Cart contains virtual product(s) only. Shipping address is not applicable');
     }
     /** @var \Magento\Sales\Model\Quote\Address $address */
     $address = $quote->getShippingAddress();
     return $this->addressConverter->convertModelToDataObject($address);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function getAddress($cartId)
 {
     /** @var  \Magento\Sales\Model\Quote\Address $address */
     $address = $this->quoteRepository->get($cartId)->getBillingAddress();
     return $this->addressConverter->convertModelToDataObject($address);
 }