/** * @param float $initialAmount * @param float $delta * @param float $updatedAmount * @dataProvider addBaseTotalAmountDataProvider */ public function testAddBaseTotalAmount($initialAmount, $delta, $updatedAmount) { $code = 'turbo'; $this->model->setBaseTotalAmount($code, $initialAmount); $this->assertSame($this->model, $this->model->addBaseTotalAmount($code, $delta)); $this->assertEquals($updatedAmount, $this->model->getBaseTotalAmount($code)); }
/** * Aggregate item discount information to total data and related properties * * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @param \Magento\Quote\Model\Quote\Address\Total $total * @return $this */ protected function aggregateItemDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item, \Magento\Quote\Model\Quote\Address\Total $total) { $total->addTotalAmount($this->getCode(), -$item->getDiscountAmount()); $total->addBaseTotalAmount($this->getCode(), -$item->getBaseDiscountAmount()); return $this; }
/** * Process everything other than product or shipping, save the result in quote * * @param Address\Total $total * @param array $itemsByType * @return $this * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function processExtraTaxables(Address\Total $total, array $itemsByType) { $extraTaxableDetails = []; foreach ($itemsByType as $itemType => $itemTaxDetails) { if ($itemType != self::ITEM_TYPE_PRODUCT and $itemType != self::ITEM_TYPE_SHIPPING) { foreach ($itemTaxDetails as $itemCode => $itemTaxDetail) { /** @var \Magento\Tax\Api\Data\TaxDetailsInterface $taxDetails */ $taxDetails = $itemTaxDetail[self::KEY_ITEM]; /** @var \Magento\Tax\Api\Data\TaxDetailsInterface $baseTaxDetails */ $baseTaxDetails = $itemTaxDetail[self::KEY_BASE_ITEM]; $appliedTaxes = $taxDetails->getAppliedTaxes(); $baseAppliedTaxes = $baseTaxDetails->getAppliedTaxes(); $associatedItemCode = $taxDetails->getAssociatedItemCode(); $appliedTaxesArray = $this->convertAppliedTaxes($appliedTaxes, $baseAppliedTaxes); $extraTaxableDetails[$itemType][$associatedItemCode][] = [self::KEY_TAX_DETAILS_TYPE => $taxDetails->getType(), self::KEY_TAX_DETAILS_CODE => $taxDetails->getCode(), self::KEY_TAX_DETAILS_PRICE_EXCL_TAX => $taxDetails->getPrice(), self::KEY_TAX_DETAILS_PRICE_INCL_TAX => $taxDetails->getPriceInclTax(), self::KEY_TAX_DETAILS_BASE_PRICE_EXCL_TAX => $baseTaxDetails->getPrice(), self::KEY_TAX_DETAILS_BASE_PRICE_INCL_TAX => $baseTaxDetails->getPriceInclTax(), self::KEY_TAX_DETAILS_ROW_TOTAL => $taxDetails->getRowTotal(), self::KEY_TAX_DETAILS_ROW_TOTAL_INCL_TAX => $taxDetails->getRowTotalInclTax(), self::KEY_TAX_DETAILS_BASE_ROW_TOTAL => $baseTaxDetails->getRowTotal(), self::KEY_TAX_DETAILS_BASE_ROW_TOTAL_INCL_TAX => $baseTaxDetails->getRowTotalInclTax(), self::KEY_TAX_DETAILS_TAX_PERCENT => $taxDetails->getTaxPercent(), self::KEY_TAX_DETAILS_ROW_TAX => $taxDetails->getRowTax(), self::KEY_TAX_DETAILS_BASE_ROW_TAX => $baseTaxDetails->getRowTax(), self::KEY_TAX_DETAILS_APPLIED_TAXES => $appliedTaxesArray]; $total->addTotalAmount('tax', $taxDetails->getRowTax()); $total->addBaseTotalAmount('tax', $baseTaxDetails->getRowTax()); //TODO: save applied taxes for the item } } } $total->setExtraTaxableDetails($extraTaxableDetails); return $this; }
/** * 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; }
/** * Process row amount based on FPT total amount configuration setting * * @param \Magento\Quote\Model\Quote\Address\Total $total * @param float $rowValueExclTax * @param float $baseRowValueExclTax * @param float $rowValueInclTax * @param float $baseRowValueInclTax * @return $this */ protected function processTotalAmount($total, $rowValueExclTax, $baseRowValueExclTax, $rowValueInclTax, $baseRowValueInclTax) { if ($this->weeeData->includeInSubtotal($this->_store)) { $total->addTotalAmount('subtotal', $rowValueExclTax); $total->addBaseTotalAmount('subtotal', $baseRowValueExclTax); } else { $total->addTotalAmount('weee', $rowValueExclTax); $total->addBaseTotalAmount('weee', $baseRowValueExclTax); } $total->setSubtotalInclTax($total->getSubtotalInclTax() + $rowValueInclTax); $total->setBaseSubtotalInclTax($total->getBaseSubtotalInclTax() + $baseRowValueInclTax); return $this; }