Exemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function testCreateAddressFromModelWithCustomerId()
 {
     $defaultBillingId = 1;
     $defaultShippingId = 1;
     $customerId = 1;
     $attributeCode = 'attribute_code';
     $addressModelMock = $this->getAddressMockForCreate();
     $addressModelMock->expects($this->once())->method('getId')->will($this->returnValue(null));
     $addressModelMock->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId));
     $addressModelMock->expects($this->any())->method('getParentId');
     $getData = function ($key, $index = null) use($attributeCode, $customerId) {
         $result = null;
         switch ($key) {
             case $attributeCode:
                 $result = 'some_data';
                 break;
             case 'customer_id':
                 $result = $customerId;
                 break;
         }
         return $result;
     };
     $addressModelMock->expects($this->any())->method('getData')->will($this->returnCallback($getData));
     $attributeMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array('getAttributeCode'), array(), '', false);
     $attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $addressMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Address', array(), array(), '', false);
     $this->addressMetadataServiceMock->expects($this->once())->method('getAllAttributesMetadata')->will($this->returnValue(array($attributeMock)));
     $this->addressBuilderMock->expects($this->once())->method('create')->will($this->returnValue($addressMock));
     $this->addressBuilderMock->expects($this->once())->method('setCustomerId')->with($this->equalTo($customerId));
     $this->assertEquals($addressMock, $this->model->createAddressFromModel($addressModelMock, $defaultBillingId, $defaultShippingId));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function validateAddresses($addresses)
 {
     $inputException = new InputException();
     foreach ($addresses as $key => $address) {
         $addressModel = $this->addressConverter->createAddressModel($address);
         $inputException = $this->_validate($addressModel, $inputException, $key);
     }
     if ($inputException->wasErrorAdded()) {
         throw $inputException;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function render(AbstractAddress $address, $format = null)
 {
     $address = $this->_addressConverter->createAddressFromModel($address, 0, 0);
     return $this->renderArray(\Magento\Customer\Service\V1\Data\AddressConverter::toFlatArray($address), $format);
 }
Exemplo n.º 4
0
 /**
  * Get Data Object addresses of the customer
  *
  * TODO: Refactor to use addressDataObject property is used instead of customer model MAGETWO-19930
  *
  * @return AddressDataObject[]
  */
 public function getCustomerAddressData()
 {
     $customer = $this->getCustomerData();
     $addresses = $this->getCustomer()->getAddresses();
     $addressDataObjects = array();
     foreach ($addresses as $address) {
         $addressDataObjects[] = $this->_addressConverter->createAddressFromModel($address, $customer->getDefaultBilling(), $customer->getDefaultShipping());
     }
     return $addressDataObjects;
 }
Exemplo n.º 5
0
 /**
  * Get product price with all tax settings processing
  *
  * @param   \Magento\Catalog\Model\Product $product
  * @param   float $price inputted product price
  * @param   bool $includingTax return price include tax flag
  * @param   null|Address $shippingAddress
  * @param   null|Address $billingAddress
  * @param   null|int $ctc customer tax class
  * @param   null|string|bool|int|Store $store
  * @param   bool $priceIncludesTax flag what price parameter contain tax
  * @param   bool $roundPrice
  * @return  float
  */
 public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
 {
     if (!$price) {
         return $price;
     }
     $store = $this->_storeManager->getStore($store);
     if ($this->_taxConfig->needPriceConversion($store)) {
         if (is_null($priceIncludesTax)) {
             $priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
         }
         $shippingAddressDataObject = null;
         if ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $shippingAddressDataObject = $this->_addressConverter->createAddressFromModel($shippingAddress, null, null);
         }
         $billingAddressDataObject = null;
         if ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $billingAddressDataObject = $this->_addressConverter->createAddressFromModel($billingAddress, null, null);
         }
         $item = $this->_quoteDetailsItemBuilder->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($product->getTaxClassId())->create())->setTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price)->create();
         $quoteDetails = $this->_quoteDetailsBuilder->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($ctc)->create())->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId())->create();
         $storeId = null;
         if ($store) {
             $storeId = $store->getId();
         }
         $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId);
         $items = $taxDetails->getItems();
         $taxDetailsItem = array_shift($items);
         if (!is_null($includingTax)) {
             if ($includingTax) {
                 $price = $taxDetailsItem->getPriceInclTax();
             } else {
                 $price = $taxDetailsItem->getPrice();
             }
         } else {
             switch ($this->_taxConfig->getPriceDisplayType($store)) {
                 case Config::DISPLAY_TYPE_EXCLUDING_TAX:
                 case Config::DISPLAY_TYPE_BOTH:
                     $price = $taxDetailsItem->getPrice();
                     break;
                 case Config::DISPLAY_TYPE_INCLUDING_TAX:
                     $price = $taxDetailsItem->getPriceInclTax();
                     break;
                 default:
                     break;
             }
         }
     }
     if ($roundPrice) {
         return $store->roundPrice($price);
     } else {
         return $price;
     }
 }