Skip to content

Commit 2ffc8c9

Browse files
author
Robert He
committed
Merge branch 'FearlessKiwis-MAGETWO-44044-minicart-subtotal-tax' of https://github.corp.magento.com/magento-fearless-kiwis/magento2ce into develop-PR
2 parents 8fe7ae0 + 2bb6a71 commit 2ffc8c9

File tree

5 files changed

+72
-13
lines changed

5 files changed

+72
-13
lines changed

app/code/Magento/Tax/CustomerData/CheckoutTotalsJsLayoutDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getData()
6161
protected function getTotalsConfig()
6262
{
6363
return [
64-
'display_subtotal_incl_tax' => (int)$this->taxConfig->displayCartSubtotalInclTax(),
64+
'display_cart_subtotal_incl_tax' => (int)$this->taxConfig->displayCartSubtotalInclTax(),
6565
'display_cart_subtotal_excl_tax' => (int)$this->taxConfig->displayCartSubtotalExclTax(),
6666
];
6767
}

app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function __construct(
8888
* @param ShippingAssignmentInterface $shippingAssignment
8989
* @param Address\Total $total
9090
* @return $this
91+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
9192
*/
9293
public function collect(
9394
\Magento\Quote\Model\Quote $quote,
@@ -291,13 +292,18 @@ protected function processExtraTaxables(Address\Total $total, Array $itemsByType
291292
* @param Address\Total $total
292293
* @return array|null
293294
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
295+
* @SuppressWarnings(PHPMD.NPathComplexity)
294296
*/
295297
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
296298
{
297299
$totals = [];
298300
$store = $quote->getStore();
299301
$applied = $total->getAppliedTaxes();
300302
$amount = $total->getTaxAmount();
303+
if ($amount == null) {
304+
$this->enhanceTotalData($quote, $total);
305+
$amount = $total->getTaxAmount();
306+
}
301307
$taxAmount = $amount + $total->getTotalAmount('discount_tax_compensation');
302308

303309
$area = null;
@@ -340,6 +346,44 @@ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Qu
340346
return $totals;
341347
}
342348

349+
/**
350+
* Adds minimal tax information to the "total" data structure
351+
*
352+
* @param \Magento\Quote\Model\Quote $quote
353+
* @param Address\Total $total
354+
* @return null
355+
*/
356+
protected function enhanceTotalData(
357+
\Magento\Quote\Model\Quote $quote,
358+
\Magento\Quote\Model\Quote\Address\Total $total
359+
) {
360+
$taxAmount = 0;
361+
$shippingTaxAmount = 0;
362+
$discountTaxCompensation = 0;
363+
364+
$subtotalInclTax = $total->getSubtotalInclTax();
365+
$computeSubtotalInclTax = true;
366+
if ($total->getSubtotalInclTax() > 0) {
367+
$computeSubtotalInclTax = false;
368+
}
369+
370+
/** @var \Magento\Quote\Model\Quote\Address $address */
371+
foreach ($quote->getAllAddresses() as $address) {
372+
$taxAmount += $address->getTaxAmount();
373+
$shippingTaxAmount += $address->getShippingTaxAmount();
374+
$discountTaxCompensation += $address->getDiscountTaxCompensationAmount();
375+
if ($computeSubtotalInclTax) {
376+
$subtotalInclTax += $address->getSubtotalInclTax();
377+
}
378+
}
379+
380+
$total->setTaxAmount($taxAmount);
381+
$total->setShippingTaxAmount($shippingTaxAmount);
382+
$total->setDiscountTaxCompensationAmount($discountTaxCompensation); // accessed via 'discount_tax_compensation'
383+
$total->setSubtotalInclTax($subtotalInclTax);
384+
return;
385+
}
386+
343387
/**
344388
* Process model configuration array.
345389
* This method can be used for changing totals collect sort order

app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/TaxTest.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,16 @@ public function dataProviderMapQuoteExtraTaxablesArray()
576576
/**
577577
* Tests the specific method
578578
*
579-
* @param string $itemData
579+
* @param string $appliedTaxesData
580580
* @param array $addressData
581581
*
582582
* @dataProvider dataProviderFetchArray
583583
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
584584
*/
585585
public function testFetch($appliedTaxesData, $addressData)
586586
{
587-
$methods = ['getAppliedTaxes', 'getTaxAmount', 'getTotalAmount', 'getGrandTotal', 'getSubtotalInclTax'];
587+
$taxAmount = 8;
588+
$methods = ['getAppliedTaxes', 'getTotalAmount', 'getGrandTotal', 'getSubtotalInclTax'];
588589
$totalsMock = $this->getMock('Magento\Quote\Model\Quote\Address\Total', $methods, [], '', false);
589590
$taxConfig = $this->getMockBuilder('\Magento\Tax\Model\Config')
590591
->disableOriginalConstructor()
@@ -632,10 +633,6 @@ public function testFetch($appliedTaxesData, $addressData)
632633
->expects($this->once())
633634
->method('getAppliedTaxes')
634635
->will($this->returnValue($appliedTaxes));
635-
$address
636-
->expects($this->any())
637-
->method('getQuote')
638-
->will($this->returnValue($quote));
639636
$totalsMock
640637
->expects($this->any())
641638
->method('getGrandTotal')
@@ -644,10 +641,17 @@ public function testFetch($appliedTaxesData, $addressData)
644641
->expects($this->any())
645642
->method('getStore')
646643
->will($this->returnValue($store));
644+
$quote->expects($this->any())
645+
->method('getAllAddresses')
646+
->will($this->returnValue([$address]));
647+
$address
648+
->expects($this->any())
649+
->method('getQuote')
650+
->will($this->returnValue($quote));
647651
$address
648652
->expects($this->any())
649653
->method('getTaxAmount')
650-
->will($this->returnValue(8));
654+
->will($this->returnValue($taxAmount));
651655
$address
652656
->expects($this->any())
653657
->method('getCustomAttributesCodes')
@@ -658,7 +662,10 @@ public function testFetch($appliedTaxesData, $addressData)
658662
$address->setData($key, $value);
659663
}
660664

661-
$taxTotalsCalcModel->fetch($quote, $totalsMock);
665+
$this->assertNull($totalsMock->getTaxAmount());
666+
$totalsArray = $taxTotalsCalcModel->fetch($quote, $totalsMock);
667+
$this->assertArrayHasKey('value', $totalsArray[0]);
668+
$this->assertEquals($taxAmount, $totalsArray[0]['value']);
662669
}
663670

664671
/**

app/code/Magento/Tax/Test/Unit/Setup/TaxSetupTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ class TaxSetupTest extends \PHPUnit_Framework_TestCase
1919

2020
protected function setUp()
2121
{
22-
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2322
$this->typeConfigMock = $this->getMock('Magento\Catalog\Model\ProductTypes\ConfigInterface');
23+
24+
$salesSetup = $this->getMock('\Magento\Sales\Setup\SalesSetup', [], [], '', false);
25+
$salesSetupFactory = $this->getMock('Magento\Sales\Setup\SalesSetupFactory', ['create'], [], '', false);
26+
$salesSetupFactory->expects($this->any())->method('create')->will($this->returnValue($salesSetup));
27+
28+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2429
$this->taxSetup = $helper->getObject(
2530
'Magento\Tax\Setup\TaxSetup',
26-
['productTypeConfig' => $this->typeConfigMock]
31+
[
32+
'productTypeConfig' => $this->typeConfigMock,
33+
'salesSetupFactory' => $salesSetupFactory,
34+
]
2735
);
2836
}
2937

app/code/Magento/Tax/view/frontend/web/template/checkout/minicart/subtotal/totals.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<span class="price-wrapper" data-bind="html: cart().subtotal_excl_tax"></span>
1111
<!-- /ko -->
1212

13-
<!-- ko if: !display_cart_subtotal_excl_tax && display_subtotal_incl_tax -->
13+
<!-- ko if: !display_cart_subtotal_excl_tax && display_cart_subtotal_incl_tax -->
1414
<span class="price-wrapper" data-bind="html: cart().subtotal_incl_tax"></span>
1515
<!-- /ko -->
1616

17-
<!-- ko if: !display_cart_subtotal_excl_tax && !display_subtotal_incl_tax -->
17+
<!-- ko if: !display_cart_subtotal_excl_tax && !display_cart_subtotal_incl_tax -->
1818
<span class="price-wrapper price-including-tax"
1919
data-bind="attr: { 'data-label': $t('Incl. Tax') }, html: cart().subtotal_incl_tax">
2020
</span>

0 commit comments

Comments
 (0)