Ejemplo n.º 1
0
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool shippingPriceInclTax
  * @param array $expectedValue
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax, array $expectedValue)
 {
     $this->taxConfig->expects($this->any())->method('getShippingTaxClass')->with($this->store)->will($this->returnValue($shippingTaxClass));
     $this->taxConfig->expects($this->any())->method('shippingPriceIncludesTax')->with($this->store)->will($this->returnValue($shippingPriceInclTax));
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency);
     $this->assertEquals($expectedValue, $shippingDataObject->__toArray());
     //call it again, make sure we get the same output
     $shippingDataObject = $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency);
     $this->assertEquals($expectedValue, $shippingDataObject->__toArray());
 }
Ejemplo n.º 2
0
 /**
  * Convert address data object to quote address model
  *
  * @param \Magento\Checkout\Service\V1\Data\Cart\Address $dataObject
  * @param \Magento\Sales\Model\Quote\Address $address
  * @return \Magento\Sales\Model\Quote\Address
  */
 public function convertDataObjectToModel($dataObject, $address)
 {
     $address->setData($dataObject->__toArray());
     //set custom attributes
     $customAttributes = $dataObject->getCustomAttributes();
     /** @var \Magento\Framework\Service\Data\AttributeValue $attributeData */
     foreach ($customAttributes as $attributeData) {
         $address->setData($attributeData->getAttributeCode(), $attributeData->getValue());
     }
     //set fields with custom logic
     $address->setStreet($dataObject->getStreet());
     $address->setRegionId($dataObject->getRegion()->getRegionId());
     $address->setRegion($dataObject->getRegion()->getRegion());
     return $address;
 }
Ejemplo n.º 3
0
 /**
  * Set and validate Quote address
  * All errors added to _errors
  *
  * @param \Magento\Sales\Model\Quote\Address $address
  * @param array $data
  * @return $this
  */
 protected function _setQuoteAddress(\Magento\Sales\Model\Quote\Address $address, array $data)
 {
     $isAjax = !$this->getIsValidate();
     // Region is a Data Object, so it is represented by an array. validateData() doesn't understand arrays, so we
     // need to merge region data with address data. This is going to be removed when we switch to use address Data
     // Object instead of the address model.
     // Note: if we use getRegion() here it will pull region from db using the region_id
     $data = isset($data['region']) && is_array($data['region']) ? array_merge($data, $data['region']) : $data;
     $addressForm = $this->_metadataFormFactory->create(AddressMetadataServiceInterface::ENTITY_TYPE_ADDRESS, 'adminhtml_customer_address', $data, $isAjax, CustomerForm::DONT_IGNORE_INVISIBLE, array());
     // prepare request
     // save original request structure for files
     if ($address->getAddressType() == \Magento\Sales\Model\Quote\Address::TYPE_SHIPPING) {
         $requestData = array('order' => array('shipping_address' => $data));
         $requestScope = 'order/shipping_address';
     } else {
         $requestData = array('order' => array('billing_address' => $data));
         $requestScope = 'order/billing_address';
     }
     $request = $addressForm->prepareRequest($requestData);
     $addressData = $addressForm->extractData($request, $requestScope);
     if ($this->getIsValidate()) {
         $errors = $addressForm->validateData($addressData);
         if ($errors !== true) {
             if ($address->getAddressType() == \Magento\Sales\Model\Quote\Address::TYPE_SHIPPING) {
                 $typeName = __('Shipping Address: ');
             } else {
                 $typeName = __('Billing Address: ');
             }
             foreach ($errors as $error) {
                 $this->_errors[] = $typeName . $error;
             }
             $address->setData($addressForm->restoreData($addressData));
         } else {
             $address->setData($addressForm->compactData($addressData));
         }
     } else {
         $address->addData($addressForm->restoreData($addressData));
     }
     return $this;
 }