Skip to content

Commit 1e7e38a

Browse files
committed
Merge branch 'MAGETWO-97396' into 2.3-develop-pr17
2 parents 66b7ff4 + 5444854 commit 1e7e38a

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Plugin\Tax\Model\Sales\Total\Quote;
9+
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
use Magento\Quote\Model\Quote\Item\AbstractItem;
12+
use Magento\Tax\Api\Data\QuoteDetailsItemInterface;
13+
use Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory;
14+
15+
/**
16+
* Plugin for CommonTaxCollector to apply Tax Class ID from child item for configurable product
17+
*/
18+
class CommonTaxCollector
19+
{
20+
/**
21+
* Apply Tax Class ID from child item for configurable product
22+
*
23+
* @param \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector $subject
24+
* @param QuoteDetailsItemInterface $result
25+
* @param QuoteDetailsItemInterfaceFactory $itemDataObjectFactory
26+
* @param AbstractItem $item
27+
* @return QuoteDetailsItemInterface
28+
*
29+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
30+
*/
31+
public function afterMapItem(
32+
\Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector $subject,
33+
QuoteDetailsItemInterface $result,
34+
QuoteDetailsItemInterfaceFactory $itemDataObjectFactory,
35+
AbstractItem $item
36+
) : QuoteDetailsItemInterface {
37+
if ($item->getProduct()->getTypeId() === Configurable::TYPE_CODE && $item->getHasChildren()) {
38+
$childItem = $item->getChildren()[0];
39+
$result->getTaxClassKey()->setValue($childItem->getProduct()->getTaxClassId());
40+
}
41+
42+
return $result;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Test\Unit\Plugin\Tax\Model\Sales\Total\Quote;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\ConfigurableProduct\Plugin\Tax\Model\Sales\Total\Quote\CommonTaxCollector as CommonTaxCollectorPlugin;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Quote\Model\Quote\Item\AbstractItem;
15+
use Magento\Tax\Api\Data\QuoteDetailsItemInterface;
16+
use Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory;
17+
use Magento\Tax\Api\Data\TaxClassKeyInterface;
18+
use Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector;
19+
use PHPUnit\Framework\MockObject\MockObject;
20+
21+
/**
22+
* Test for CommonTaxCollector plugin
23+
*/
24+
class CommonTaxCollectorTest extends \PHPUnit\Framework\TestCase
25+
{
26+
/**
27+
* @var ObjectManager
28+
*/
29+
private $objectManager;
30+
31+
/**
32+
* @var CommonTaxCollectorPlugin
33+
*/
34+
private $commonTaxCollectorPlugin;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function setUp()
40+
{
41+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
42+
$this->commonTaxCollectorPlugin = $this->objectManager->getObject(CommonTaxCollectorPlugin::class);
43+
}
44+
45+
/**
46+
* Test to apply Tax Class Id from child item for configurable product
47+
*/
48+
public function testAfterMapItem()
49+
{
50+
$childTaxClassId = 10;
51+
52+
/** @var Product|MockObject $childProductMock */
53+
$childProductMock = $this->createPartialMock(
54+
Product::class,
55+
['getTaxClassId']
56+
);
57+
$childProductMock->method('getTaxClassId')->willReturn($childTaxClassId);
58+
/* @var AbstractItem|MockObject $quoteItemMock */
59+
$childQuoteItemMock = $this->createMock(
60+
AbstractItem::class
61+
);
62+
$childQuoteItemMock->method('getProduct')->willReturn($childProductMock);
63+
64+
/** @var Product|MockObject $productMock */
65+
$productMock = $this->createPartialMock(
66+
Product::class,
67+
['getTypeId']
68+
);
69+
$productMock->method('getTypeId')->willReturn(Configurable::TYPE_CODE);
70+
/* @var AbstractItem|MockObject $quoteItemMock */
71+
$quoteItemMock = $this->createPartialMock(
72+
AbstractItem::class,
73+
['getProduct', 'getHasChildren', 'getChildren', 'getQuote', 'getAddress', 'getOptionByCode']
74+
);
75+
$quoteItemMock->method('getProduct')->willReturn($productMock);
76+
$quoteItemMock->method('getHasChildren')->willReturn(true);
77+
$quoteItemMock->method('getChildren')->willReturn([$childQuoteItemMock]);
78+
79+
/* @var TaxClassKeyInterface|MockObject $taxClassObjectMock */
80+
$taxClassObjectMock = $this->createMock(TaxClassKeyInterface::class);
81+
$taxClassObjectMock->expects($this->once())->method('setValue')->with($childTaxClassId);
82+
83+
/* @var QuoteDetailsItemInterface|MockObject $quoteDetailsItemMock */
84+
$quoteDetailsItemMock = $this->createMock(QuoteDetailsItemInterface::class);
85+
$quoteDetailsItemMock->method('getTaxClassKey')->willReturn($taxClassObjectMock);
86+
87+
$this->commonTaxCollectorPlugin->afterMapItem(
88+
$this->createMock(CommonTaxCollector::class),
89+
$quoteDetailsItemMock,
90+
$this->createMock(QuoteDetailsItemInterfaceFactory::class),
91+
$quoteItemMock
92+
);
93+
}
94+
}

app/code/Magento/ConfigurableProduct/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"magento/module-sales-rule": "*",
2626
"magento/module-product-video": "*",
2727
"magento/module-configurable-sample-data": "*",
28-
"magento/module-product-links-sample-data": "*"
28+
"magento/module-product-links-sample-data": "*",
29+
"magento/module-tax": "*"
2930
},
3031
"type": "magento2-module",
3132
"license": [

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,7 @@
245245
<type name="Magento\SalesRule\Model\Rule\Condition\Product">
246246
<plugin name="apply_rule_on_configurable_children" type="Magento\ConfigurableProduct\Plugin\SalesRule\Model\Rule\Condition\Product" />
247247
</type>
248+
<type name="Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector">
249+
<plugin name="apply_tax_class_id" type="Magento\ConfigurableProduct\Plugin\Tax\Model\Sales\Total\Quote\CommonTaxCollector" />
250+
</type>
248251
</config>

0 commit comments

Comments
 (0)