8 use Magento\Customer\Api\Data\AddressInterfaceFactory as CustomerAddressFactory;
9 use Magento\Customer\Api\Data\RegionInterfaceFactory as CustomerAddressRegionFactory;
78 Json $serializer =
null 81 $this->_taxData = $taxData;
109 if (!$shippingAssignment->getItems()) {
117 $itemsByType = $this->organizeItemTaxDetailsByType($taxDetails, $baseTaxDetails);
118 if (isset($itemsByType[self::ITEM_TYPE_PRODUCT])) {
119 $this->processProductItems($shippingAssignment, $itemsByType[self::ITEM_TYPE_PRODUCT],
$total);
122 if (isset($itemsByType[self::ITEM_TYPE_SHIPPING])) {
124 $baseShippingTaxDetails =
130 $this->processExtraTaxables(
$total, $itemsByType);
133 $this->processAppliedTaxes(
$total, $shippingAssignment, $itemsByType);
136 $total->addTotalAmount(
'extra_tax',
$total->getExtraTaxAmount());
137 $total->addBaseTotalAmount(
'extra_tax',
$total->getBaseExtraTaxAmount());
151 $total->setTotalAmount(
'subtotal', 0);
152 $total->setBaseTotalAmount(
'subtotal', 0);
153 $total->setTotalAmount(
'tax', 0);
154 $total->setBaseTotalAmount(
'tax', 0);
155 $total->setTotalAmount(
'shipping', 0);
156 $total->setBaseTotalAmount(
'shipping', 0);
157 $total->setTotalAmount(
'discount_tax_compensation', 0);
158 $total->setBaseTotalAmount(
'discount_tax_compensation', 0);
159 $total->setTotalAmount(
'shipping_discount_tax_compensation', 0);
160 $total->setBaseTotalAmount(
'shipping_discount_tax_compensation', 0);
161 $total->setSubtotalInclTax(0);
162 $total->setBaseSubtotalInclTax(0);
163 $total->setShippingInclTax(0);
164 $total->setBaseShippingInclTax(0);
165 $total->setShippingTaxAmount(0);
166 $total->setBaseShippingTaxAmount(0);
167 $total->setShippingAmountForDiscount(0);
168 $total->setBaseShippingAmountForDiscount(0);
169 $total->setBaseShippingAmountForDiscount(0);
170 $total->setTotalAmount(
'extra_tax', 0);
171 $total->setBaseTotalAmount(
'extra_tax', 0);
184 $address = $shippingAssignment->getShipping()->getAddress();
186 $priceIncludesTax = $this->_config->priceIncludesTax(
$address->getQuote()->getStore());
187 $itemDataObjects = $this->
mapItems($shippingAssignment, $priceIncludesTax, $useBaseCurrency);
190 $shippingDataObject = $this->getShippingDataObject($shippingAssignment,
$total, $useBaseCurrency);
191 if ($shippingDataObject !=
null) {
192 $itemDataObjects[] = $shippingDataObject;
197 $this->quoteDetailsItemDataObjectFactory,
201 if (!empty($quoteExtraTaxables)) {
202 $itemDataObjects = array_merge($itemDataObjects, $quoteExtraTaxables);
208 $taxDetails = $this->taxCalculationService
209 ->calculateTax($quoteDetails,
$address->getQuote()->getStore()->getStoreId());
223 \
Magento\
Tax\Api\Data\QuoteDetailsItemInterfaceFactory $itemDataObjectFactory,
227 $itemDataObjects = [];
228 $extraTaxables =
$address->getAssociatedTaxables();
229 if (!$extraTaxables) {
233 foreach ($extraTaxables as $extraTaxable) {
234 if ($useBaseCurrency) {
239 $itemDataObjects[] = $itemDataObjectFactory->create()
240 ->setCode($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_CODE])
241 ->setType($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_TYPE])
242 ->setQuantity($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_QUANTITY])
244 $this->taxClassKeyDataObjectFactory->create()
246 ->setValue($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_TAX_CLASS_ID])
248 ->setUnitPrice($unitPrice)
249 ->setIsTaxIncluded($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_PRICE_INCLUDES_TAX])
250 ->setAssociatedItemCode($extraTaxable[self::KEY_ASSOCIATED_TAXABLE_ASSOCIATION_ITEM_CODE]);
253 return $itemDataObjects;
266 $extraTaxableDetails = [];
267 foreach ($itemsByType as $itemType => $itemTaxDetails) {
268 if ($itemType != self::ITEM_TYPE_PRODUCT and $itemType != self::ITEM_TYPE_SHIPPING) {
269 foreach ($itemTaxDetails as $itemCode => $itemTaxDetail) {
275 $appliedTaxes = $taxDetails->getAppliedTaxes();
276 $baseAppliedTaxes = $baseTaxDetails->getAppliedTaxes();
278 $associatedItemCode = $taxDetails->getAssociatedItemCode();
281 $extraTaxableDetails[$itemType][$associatedItemCode][] = [
282 self::KEY_TAX_DETAILS_TYPE => $taxDetails->getType(),
283 self::KEY_TAX_DETAILS_CODE => $taxDetails->getCode(),
284 self::KEY_TAX_DETAILS_PRICE_EXCL_TAX => $taxDetails->getPrice(),
285 self::KEY_TAX_DETAILS_PRICE_INCL_TAX => $taxDetails->getPriceInclTax(),
286 self::KEY_TAX_DETAILS_BASE_PRICE_EXCL_TAX => $baseTaxDetails->getPrice(),
287 self::KEY_TAX_DETAILS_BASE_PRICE_INCL_TAX => $baseTaxDetails->getPriceInclTax(),
288 self::KEY_TAX_DETAILS_ROW_TOTAL => $taxDetails->getRowTotal(),
289 self::KEY_TAX_DETAILS_ROW_TOTAL_INCL_TAX => $taxDetails->getRowTotalInclTax(),
290 self::KEY_TAX_DETAILS_BASE_ROW_TOTAL => $baseTaxDetails->getRowTotal(),
291 self::KEY_TAX_DETAILS_BASE_ROW_TOTAL_INCL_TAX => $baseTaxDetails->getRowTotalInclTax(),
292 self::KEY_TAX_DETAILS_TAX_PERCENT => $taxDetails->getTaxPercent(),
293 self::KEY_TAX_DETAILS_ROW_TAX => $taxDetails->getRowTax(),
294 self::KEY_TAX_DETAILS_BASE_ROW_TAX => $baseTaxDetails->getRowTax(),
295 self::KEY_TAX_DETAILS_APPLIED_TAXES => $appliedTaxesArray,
298 $total->addTotalAmount(
'tax', $taxDetails->getRowTax());
299 $total->addBaseTotalAmount(
'tax', $baseTaxDetails->getRowTax());
305 $total->setExtraTaxableDetails($extraTaxableDetails);
322 $applied =
$total->getAppliedTaxes();
323 if (is_string($applied)) {
324 $applied = $this->serializer->unserialize($applied);
334 if ($this->_config->displayCartTaxWithGrandTotal(
$store) &&
$total->getGrandTotal()) {
340 'title' =>
__(
'Tax'),
341 'full_info' => $applied ? $applied : [],
349 if ($this->_config->displayCartSubtotalBoth(
$store) || $this->_config->displayCartSubtotalInclTax(
$store)) {
350 if (
$total->getSubtotalInclTax() > 0) {
351 $subtotalInclTax =
$total->getSubtotalInclTax();
357 'code' =>
'subtotal',
358 'title' =>
__(
'Subtotal'),
359 'value' => $subtotalInclTax,
360 'value_incl_tax' => $subtotalInclTax,
361 'value_excl_tax' =>
$total->getSubtotal(),
378 protected function enhanceTotalData(
383 $shippingTaxAmount = 0;
384 $discountTaxCompensation = 0;
386 $subtotalInclTax =
$total->getSubtotalInclTax();
387 $computeSubtotalInclTax =
true;
388 if (
$total->getSubtotalInclTax() > 0) {
389 $computeSubtotalInclTax =
false;
395 $shippingTaxAmount +=
$address->getShippingTaxAmount();
396 $discountTaxCompensation +=
$address->getDiscountTaxCompensationAmount();
397 if ($computeSubtotalInclTax) {
398 $subtotalInclTax +=
$address->getSubtotalInclTax();
403 $total->setShippingTaxAmount($shippingTaxAmount);
404 $total->setDiscountTaxCompensationAmount($discountTaxCompensation);
405 $total->setSubtotalInclTax($subtotalInclTax);
419 $calculationSequence = $this->_taxData->getCalculationSequence(
$store);
420 switch ($calculationSequence) {
422 $config[
'before'][] =
'discount';
425 $config[
'after'][] =
'discount';
clearValues(Address\Total $total)
fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
$taxClassKeyDataObjectFactory
const KEY_ASSOCIATED_TAXABLE_UNIT_PRICE
const KEY_ASSOCIATED_TAXABLE_BASE_UNIT_PRICE
const CALC_TAX_BEFORE_DISCOUNT_ON_INCL
$customerAddressRegionFactory
getQuoteTaxDetails($shippingAssignment, $total, $useBaseCurrency)
convertAppliedTaxes($appliedTaxes, $baseAppliedTaxes, $extraInfo=[])
mapItems(ShippingAssignmentInterface $shippingAssignment, $priceIncludesTax, $useBaseCurrency)
__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, Json $serializer=null)
mapQuoteExtraTaxables(\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, Address $address, $useBaseCurrency)
$_discountTaxCompensationes
prepareQuoteDetails(ShippingAssignmentInterface $shippingAssignment, $itemDataObjects)
$quoteDetailsItemDataObjectFactory
processShippingTaxInfo(ShippingAssignmentInterface $shippingAssignment, QuoteAddress\Total $total, $shippingTaxDetails, $baseShippingTaxDetails)
processConfigArray($config, $store)
collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
$quoteDetailsDataObjectFactory