public function testCalculateWithTaxNotInPrice()
 {
     $mockItem = $this->getMockItem();
     $mockItem->expects($this->once())->method('getIsTaxIncluded')->will($this->returnValue(false));
     $this->mockConfig->expects($this->once())->method('applyTaxAfterDiscount')->will($this->returnValue(true));
     $this->mockCalculationTool->expects($this->once())->method('getRate')->with($this->addressRateRequest)->will($this->returnValue(self::RATE));
     $this->mockCalculationTool->expects($this->once())->method('getAppliedRates')->withAnyParameters()->will($this->returnValue([['id' => 0, 'percent' => 0, 'rates' => []]]));
     $this->assertSame($this->taxDetailsItem, $this->model->calculate($mockItem, self::QUANTITY));
     $this->assertEquals(self::CODE, $this->taxDetailsItem->getCode());
     $this->assertEquals(self::TYPE, $this->taxDetailsItem->getType());
     $this->assertEquals(0.0, $this->taxDetailsItem->getRowTax());
 }
 /**
  * Update tax related fields for shipping
  *
  * @param ShippingAssignmentInterface $shippingAssignment
  * @param QuoteAddress\Total $total
  * @param TaxDetailsItemInterface $shippingTaxDetails
  * @param TaxDetailsItemInterface $baseShippingTaxDetails
  * @return $this
  */
 protected function processShippingTaxInfo(ShippingAssignmentInterface $shippingAssignment, QuoteAddress\Total $total, $shippingTaxDetails, $baseShippingTaxDetails)
 {
     $total->setTotalAmount('shipping', $shippingTaxDetails->getRowTotal());
     $total->setBaseTotalAmount('shipping', $baseShippingTaxDetails->getRowTotal());
     $total->setTotalAmount('shipping_discount_tax_compensation', $shippingTaxDetails->getDiscountTaxCompensationAmount());
     $total->setBaseTotalAmount('shipping_discount_tax_compensation', $baseShippingTaxDetails->getDiscountTaxCompensationAmount());
     $total->setShippingInclTax($shippingTaxDetails->getRowTotalInclTax());
     $total->setBaseShippingInclTax($baseShippingTaxDetails->getRowTotalInclTax());
     $total->setShippingTaxAmount($shippingTaxDetails->getRowTax());
     $total->setBaseShippingTaxAmount($baseShippingTaxDetails->getRowTax());
     //Add the shipping tax to total tax amount
     $total->addTotalAmount('tax', $shippingTaxDetails->getRowTax());
     $total->addBaseTotalAmount('tax', $baseShippingTaxDetails->getRowTax());
     if ($this->_config->discountTax($shippingAssignment->getShipping()->getAddress()->getQuote()->getStore())) {
         $total->setShippingAmountForDiscount($shippingTaxDetails->getRowTotalInclTax());
         $total->setBaseShippingAmountForDiscount($baseShippingTaxDetails->getRowTotalInclTax());
     }
     return $this;
 }
 /**
  * Add row total item amount to subtotal
  *
  * @param array $taxDetailsData
  * @param TaxDetailsItemInterface $item
  * @return array
  */
 protected function aggregateItemData($taxDetailsData, TaxDetailsItemInterface $item)
 {
     $taxDetailsData[TaxDetailsInterface::KEY_SUBTOTAL] = $taxDetailsData[TaxDetailsInterface::KEY_SUBTOTAL] + $item->getRowTotal();
     $taxDetailsData[TaxDetailsInterface::KEY_TAX_AMOUNT] = $taxDetailsData[TaxDetailsInterface::KEY_TAX_AMOUNT] + $item->getRowTax();
     $taxDetailsData[TaxDetailsInterface::KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT] = $taxDetailsData[TaxDetailsInterface::KEY_DISCOUNT_TAX_COMPENSATION_AMOUNT] + $item->getDiscountTaxCompensationAmount();
     $itemAppliedTaxes = $item->getAppliedTaxes();
     if ($itemAppliedTaxes === null) {
         return $taxDetailsData;
     }
     $appliedTaxes = $taxDetailsData[TaxDetailsInterface::KEY_APPLIED_TAXES];
     foreach ($itemAppliedTaxes as $taxId => $itemAppliedTax) {
         if (!isset($appliedTaxes[$taxId])) {
             //convert rate data object to array
             $rates = [];
             $rateDataObjects = $itemAppliedTax->getRates();
             foreach ($rateDataObjects as $rateDataObject) {
                 $rates[$rateDataObject->getCode()] = [AppliedTaxRateInterface::KEY_CODE => $rateDataObject->getCode(), AppliedTaxRateInterface::KEY_TITLE => $rateDataObject->getTitle(), AppliedTaxRateInterface::KEY_PERCENT => $rateDataObject->getPercent()];
             }
             $appliedTaxes[$taxId] = [AppliedTaxInterface::KEY_AMOUNT => $itemAppliedTax->getAmount(), AppliedTaxInterface::KEY_PERCENT => $itemAppliedTax->getPercent(), AppliedTaxInterface::KEY_RATES => $rates, AppliedTaxInterface::KEY_TAX_RATE_KEY => $itemAppliedTax->getTaxRateKey()];
         } else {
             $appliedTaxes[$taxId][AppliedTaxInterface::KEY_AMOUNT] += $itemAppliedTax->getAmount();
         }
     }
     $taxDetailsData[TaxDetailsInterface::KEY_APPLIED_TAXES] = $appliedTaxes;
     return $taxDetailsData;
 }
 /**
  * Update tax related fields for shipping
  *
  * @param QuoteAddress $address
  * @param TaxDetailsItemInterface $shippingTaxDetails
  * @param TaxDetailsItemInterface $baseShippingTaxDetails
  * @return $this
  */
 protected function processShippingTaxInfo(QuoteAddress $address, $shippingTaxDetails, $baseShippingTaxDetails)
 {
     $address->setTotalAmount('shipping', $shippingTaxDetails->getRowTotal());
     $address->setBaseTotalAmount('shipping', $baseShippingTaxDetails->getRowTotal());
     $address->setTotalAmount('shipping_hidden_tax', $shippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setBaseTotalAmount('shipping_hidden_tax', $baseShippingTaxDetails->getDiscountTaxCompensationAmount());
     $address->setShippingInclTax($shippingTaxDetails->getRowTotalInclTax());
     $address->setBaseShippingInclTax($baseShippingTaxDetails->getRowTotalInclTax());
     $address->setShippingTaxAmount($shippingTaxDetails->getRowTax());
     $address->setBaseShippingTaxAmount($baseShippingTaxDetails->getRowTax());
     //Add the shipping tax to total tax amount
     $address->addTotalAmount('tax', $shippingTaxDetails->getRowTax());
     $address->addBaseTotalAmount('tax', $baseShippingTaxDetails->getRowTax());
     if ($this->_config->discountTax($address->getQuote()->getStore())) {
         $address->setShippingAmountForDiscount($shippingTaxDetails->getRowTotalInclTax());
         $address->setBaseShippingAmountForDiscount($baseShippingTaxDetails->getRowTotalInclTax());
     }
     return $this;
 }