Exemplo 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());
 }
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $shippingAssignmentMock = $this->getMock('Magento\\Quote\\Api\\Data\\ShippingAssignmentInterface');
     $methods = ['getShippingDiscountAmount', 'getShippingTaxCalculationAmount', 'setShippingTaxCalculationAmount', 'getShippingAmount', 'setBaseShippingTaxCalculationAmount', 'getBaseShippingAmount', 'getBaseShippingDiscountAmount'];
     $totalsMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address\\Total', $methods, [], '', false);
     $shippingMock = $this->getMock('Magento\\Quote\\Api\\Data\\ShippingInterface');
     $shippingAssignmentMock->expects($this->once())->method('getShipping')->willReturn($shippingMock);
     $shippingMock->expects($this->once())->method('getAddress')->willReturn($this->address);
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $totalsMock->expects($this->any())->method('getShippingTaxCalculationAmount')->willReturn($shippingAmount);
     $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));
     $totalsMock->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $totalsMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $totalsMock->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $totalsMock->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($shippingAssignmentMock, $totalsMock, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }
 /**
  * @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)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $itemMock = $this->getMock('Magento\\Tax\\Api\\Data\\QuoteDetailsItemInterface');
     $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));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($baseShippingAmount);
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $this->quoteDetailsItemBuilderMock->expects($this->once())->method('setDiscountAmount')->with($shippingAmount);
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setType')->willReturnSelf();
     $this->taxClassKeyBuilderMock->expects($this->any())->method('setValue')->with($shippingTaxClass)->willReturnSelf();
     $this->quoteDetailsItemBuilderMock->expects($this->once())->method('create')->willReturn($itemMock);
     $this->assertEquals($itemMock, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
 }
Exemplo n.º 4
0
 /**
  * Collect tax totals for quote address
  *
  * @param   Address $address
  * @return  $this
  */
 public function collect(Address $address)
 {
     parent::collect($address);
     $this->clearValues($address);
     $items = $this->_getAddressItems($address);
     if (!$items) {
         return $this;
     }
     $baseTaxDetails = $this->getQuoteTaxDetails($address, true);
     $taxDetails = $this->getQuoteTaxDetails($address, false);
     //Populate address and items with tax calculation results
     $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
     if (isset($itemsByType[self::ITEM_TYPE_PRODUCT])) {
         $this->processProductItems($address, $itemsByType[self::ITEM_TYPE_PRODUCT]);
     }
     if (isset($itemsByType[self::ITEM_TYPE_SHIPPING])) {
         $shippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_ITEM];
         $baseShippingTaxDetails = $itemsByType[self::ITEM_TYPE_SHIPPING][self::ITEM_CODE_SHIPPING][self::KEY_BASE_ITEM];
         $this->processShippingTaxInfo($address, $shippingTaxDetails, $baseShippingTaxDetails);
     }
     //Process taxable items that are not product or shipping
     $this->processExtraTaxables($address, $itemsByType);
     //Save applied taxes for each item and the quote in aggregation
     $this->processAppliedTaxes($address, $itemsByType);
     if ($this->includeExtraTax()) {
         $this->_addAmount($address->getExtraTaxAmount());
         $this->_addBaseAmount($address->getBaseExtraTaxAmount());
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Collect tax totals for shipping. The result can be used to calculate discount on shipping
  *
  * @param   Address $address
  * @return  $this
  */
 public function collect(Address $address)
 {
     parent::collect($address);
     $items = $this->_getAddressItems($address);
     if (!$items) {
         return $this;
     }
     //Add shipping
     $shippingDataObject = $this->getShippingDataObject($address, false);
     $baseShippingDataObject = $this->getShippingDataObject($address, true);
     if ($shippingDataObject == null || $baseShippingDataObject == null) {
         return $this;
     }
     $quoteDetails = $this->prepareQuoteDetails($address, [$shippingDataObject]);
     $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails, $address->getQuote()->getStore()->getStoreId());
     $baseQuoteDetails = $this->prepareQuoteDetails($address, [$baseShippingDataObject]);
     $baseTaxDetails = $this->taxCalculationService->calculateTax($baseQuoteDetails, $address->getQuote()->getStore()->getStoreId());
     $this->processShippingTaxInfo($address, $taxDetails->getItems()[self::ITEM_CODE_SHIPPING], $baseTaxDetails->getItems()[self::ITEM_CODE_SHIPPING]);
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Calculate tax on product items. The result will be used to determine shipping
  * and discount later.
  *
  * @param   Address $address
  * @return  $this
  */
 public function collect(Address $address)
 {
     parent::collect($address);
     $items = $this->_getAddressItems($address);
     if (!$items) {
         return $this;
     }
     $priceIncludesTax = $this->_config->priceIncludesTax($address->getQuote()->getStore());
     //Setup taxable items
     $itemDataObjects = $this->mapItems($address, $priceIncludesTax, false);
     $quoteDetails = $this->prepareQuoteDetails($address, $itemDataObjects);
     $taxDetails = $this->taxCalculationService->calculateTax($quoteDetails, $address->getQuote()->getStore()->getStoreId());
     $itemDataObjects = $this->mapItems($address, $priceIncludesTax, true);
     $baseQuoteDetails = $this->prepareQuoteDetails($address, $itemDataObjects);
     $baseTaxDetails = $this->taxCalculationService->calculateTax($baseQuoteDetails, $address->getQuote()->getStore()->getStoreId());
     $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
     if (isset($itemsByType[self::ITEM_TYPE_PRODUCT])) {
         $this->processProductItems($address, $itemsByType[self::ITEM_TYPE_PRODUCT]);
     }
     return $this;
 }
 /**
  * @param array $addressData
  * @param bool $useBaseCurrency
  * @param string $shippingTaxClass
  * @param bool $shippingPriceInclTax
  * @dataProvider getShippingDataObjectDataProvider
  */
 public function testGetShippingDataObject(array $addressData, $useBaseCurrency, $shippingTaxClass, $shippingPriceInclTax)
 {
     $baseShippingAmount = $addressData['base_shipping_amount'];
     $shippingAmount = $addressData['shipping_amount'];
     $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));
     $this->address->expects($this->atLeastOnce())->method('getShippingDiscountAmount')->willReturn($shippingAmount);
     if ($shippingAmount) {
         if ($useBaseCurrency && $shippingAmount != 0) {
             $this->address->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn($baseShippingAmount);
             $expectedDiscountAmount = $baseShippingAmount;
         } else {
             $this->address->expects($this->never())->method('getBaseShippingDiscountAmount');
             $expectedDiscountAmount = $shippingAmount;
         }
     }
     foreach ($addressData as $key => $value) {
         $this->address->setData($key, $value);
     }
     $this->assertEquals($this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($this->address, $useBaseCurrency));
     if ($shippingAmount) {
         $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount());
     }
 }
Exemplo n.º 8
0
 /**
  * Class constructor
  *
  * @param \Magento\Tax\Model\Config $taxConfig
  * @param \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService
  * @param \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory
  * @param \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory
  * @param \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory
  * @param CustomerAddressFactory $customerAddressFactory
  * @param CustomerAddressRegionFactory $customerAddressRegionFactory
  * @param \Magento\Tax\Helper\Data $taxData
  */
 public function __construct(\Magento\Tax\Model\Config $taxConfig, \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService, \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory, \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory, \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory, CustomerAddressFactory $customerAddressFactory, CustomerAddressRegionFactory $customerAddressRegionFactory, \Magento\Tax\Helper\Data $taxData)
 {
     $this->setCode('tax');
     $this->_taxData = $taxData;
     parent::__construct($taxConfig, $taxCalculationService, $quoteDetailsDataObjectFactory, $quoteDetailsItemDataObjectFactory, $taxClassKeyDataObjectFactory, $customerAddressFactory, $customerAddressRegionFactory);
 }