Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
 public function testPopulateBeforeSaveData()
 {
     /** Preconditions */
     $customerId = 1;
     $customerAddressId = 1;
     $this->_address->setQuote($this->_quote);
     $this->assertNotEquals($customerId, $this->_address->getCustomerId(), "Precondition failed: Customer ID was not set.");
     $this->assertNotEquals(1, $this->_address->getQuoteId(), "Precondition failed: Quote ID was not set.");
     $this->assertNotEquals($customerAddressId, $this->_address->getCustomerAddressId(), "Precondition failed: Customer address ID was not set.");
     /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder */
     $addressBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
     $customerAddressData = $addressBuilder->setId($customerAddressId)->create();
     $this->_address->setCustomerAddressData($customerAddressData);
     $this->_address->save();
     $this->assertEquals($customerId, $this->_address->getCustomerId());
     $this->assertEquals($this->_quote->getId(), $this->_address->getQuoteId());
     $this->assertEquals($customerAddressId, $this->_address->getCustomerAddressId());
 }
Ejemplo n.º 3
0
 /**
  * Convert quote address to order address
  *
  * @param   \Magento\Sales\Model\Quote\Address $address
  * @return  \Magento\Sales\Model\Order\Address
  */
 public function addressToOrderAddress(\Magento\Sales\Model\Quote\Address $address)
 {
     $orderAddress = $this->_orderAddressFactory->create()->setStoreId($address->getStoreId())->setAddressType($address->getAddressType())->setCustomerId($address->getCustomerId())->setCustomerAddressId($address->getCustomerAddressId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_quote_address', 'to_order_address', $address, $orderAddress);
     $this->_eventManager->dispatch('sales_convert_quote_address_to_order_address', array('address' => $address, 'order_address' => $orderAddress));
     return $orderAddress;
 }