Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function setAddress($cartId, $addressData)
 {
     /** @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 = $this->quoteAddressFactory->create();
     $this->addressValidator->validate($addressData);
     if ($addressData->getId()) {
         $address->load($addressData->getId());
     }
     $address = $this->addressConverter->convertDataObjectToModel($addressData, $address);
     $address->setSameAsBilling(0);
     $address->setCollectShippingRates(true);
     $quote->setShippingAddress($address);
     $quote->setDataChanges(true);
     try {
         $quote->save();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new InputException('Unable to save address. Please, check input data.');
     }
     return $quote->getShippingAddress()->getId();
 }
Exemplo 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);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function setAddress($cartId, $addressData)
 {
     /** @var \Magento\Sales\Model\Quote $quote */
     $quote = $this->quoteRepository->get($cartId);
     /** @var \Magento\Sales\Model\Quote\Address $address */
     $address = $this->quoteAddressFactory->create();
     $this->addressValidator->validate($addressData);
     if ($addressData->getId()) {
         $address->load($addressData->getId());
     }
     $address = $this->addressConverter->convertDataObjectToModel($addressData, $address);
     $quote->setBillingAddress($address);
     $quote->setDataChanges(true);
     try {
         $quote->save();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         throw new InputException('Unable to save address. Please, check input data.');
     }
     return $quote->getBillingAddress()->getId();
 }
Exemplo n.º 5
0
 public function testConvertDataObjectToModel()
 {
     $dataObjectMock = $this->getMock('Magento\\Checkout\\Service\\V1\\Data\\Cart\\Address', [], [], '', false);
     $methods = ['setData', 'setStreet', 'setRegionId', 'setRegion', '__wakeUp'];
     $addressMock = $this->getMock('Magento\\Sales\\Model\\Quote\\Address', $methods, [], '', false);
     $attributeValueMock = $this->getMock('\\Magento\\Framework\\Service\\Data\\AttributeValue', [], [], '', false);
     $attributeValueMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue('value_code'));
     $attributeValueMock->expects($this->once())->method('getValue')->will($this->returnValue('value'));
     $addressData = ['some_code' => 'some_value'];
     $regionMock = $this->getMock('Magento\\Checkout\\Service\\V1\\Data\\Cart\\Address\\Region', [], [], '', false);
     $dataObjectMock->expects($this->once())->method('__toArray')->will($this->returnValue($addressData));
     $valueMap = [[$addressData, null], ['attribute_value', 'value']];
     $addressMock->expects($this->any())->method('setData')->will($this->returnValueMap($valueMap));
     $dataObjectMock->expects($this->once())->method('getCustomAttributes')->will($this->returnValue([$attributeValueMock]));
     $dataObjectMock->expects($this->once())->method('getStreet')->will($this->returnValue('street'));
     $addressMock->expects($this->once())->method('setStreet')->with('street');
     $dataObjectMock->expects($this->any())->method('getRegion')->will($this->returnValue($regionMock));
     $regionMock->expects($this->once())->method('getRegionId')->will($this->returnValue('regionId'));
     $regionMock->expects($this->once())->method('getRegion')->will($this->returnValue('region'));
     $addressMock->expects($this->once())->method('setRegionId')->with('regionId');
     $addressMock->expects($this->once())->method('setRegion')->with('region');
     $this->model->convertDataObjectToModel($dataObjectMock, $addressMock);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getAddress($cartId)
 {
     /** @var  \Magento\Sales\Model\Quote\Address $address */
     $address = $this->quoteRepository->get($cartId)->getBillingAddress();
     return $this->addressConverter->convertModelToDataObject($address);
 }