Skip to content

Commit a5330a7

Browse files
authored
Merge pull request #3813 from magento-tsg-csl3/2.3-develop-pr17
[TSG-CSL3] For 2.3 (pr17)
2 parents 61e17e5 + 4344124 commit a5330a7

File tree

16 files changed

+422
-58
lines changed

16 files changed

+422
-58
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @method Quote setOrderId($orderId)
2525
* @method int getOrderId()
2626
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2728
* @since 100.0.2
2829
*/
2930
class Quote extends \Magento\Framework\Session\SessionManager
@@ -149,7 +150,8 @@ public function getQuote()
149150
$this->_quote = $this->quoteFactory->create();
150151
if ($this->getStoreId()) {
151152
if (!$this->getQuoteId()) {
152-
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
153+
$customerGroupId = $this->groupManagement->getDefaultGroup($this->getStoreId())->getId();
154+
$this->_quote->setCustomerGroupId($customerGroupId);
153155
$this->_quote->setIsActive(false);
154156
$this->_quote->setStoreId($this->getStoreId());
155157

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ public function testGetQuoteWithoutQuoteId()
267267
$cartInterfaceMock->expects($this->atLeastOnce())->method('getId')->willReturn($quoteId);
268268
$defaultGroup = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)->getMock();
269269
$defaultGroup->expects($this->any())->method('getId')->will($this->returnValue($customerGroupId));
270-
$this->groupManagementMock->expects($this->any())->method('getDefaultGroup')->willReturn($defaultGroup);
270+
$this->groupManagementMock
271+
->method('getDefaultGroup')
272+
->with($storeId)
273+
->willReturn($defaultGroup);
271274

272275
$dataCustomerMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
273276
->disableOriginalConstructor()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\CatalogInventory\Ui\DataProvider\Product;
9+
10+
use Magento\Framework\Data\Collection;
11+
use Magento\Ui\DataProvider\AddFieldToCollectionInterface;
12+
13+
/**
14+
* Add quantity_and_stock_status field to collection
15+
*/
16+
class AddQuantityAndStockStatusFieldToCollection implements AddFieldToCollectionInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function addField(Collection $collection, $field, $alias = null)
22+
{
23+
$collection->joinField(
24+
'quantity_and_stock_status',
25+
'cataloginventory_stock_item',
26+
'is_in_stock',
27+
'product_id=entity_id',
28+
'{{table}}.stock_id=1',
29+
'left'
30+
);
31+
}
32+
}

app/code/Magento/CatalogInventory/etc/adminhtml/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<arguments>
2424
<argument name="addFieldStrategies" xsi:type="array">
2525
<item name="qty" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFieldToCollection</item>
26+
<item name="quantity_and_stock_status" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityAndStockStatusFieldToCollection</item>
2627
</argument>
2728
<argument name="addFilterStrategies" xsi:type="array">
2829
<item name="qty" xsi:type="object">Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection</item>

app/code/Magento/Checkout/view/frontend/templates/cart/noItems.phtml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
$block->escapeUrl($block->getContinueShoppingUrl())) ?></p>
1414
<?= $block->getChildHtml('shopping.cart.table.after') ?>
1515
</div>
16+
<script type="text/x-magento-init">
17+
{
18+
"*": {
19+
"Magento_Checkout/js/empty-cart": {}
20+
}
21+
}
22+
</script>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Customer/js/customer-data'
8+
], function (customerData) {
9+
'use strict';
10+
11+
var cartData = customerData.get('cart');
12+
13+
if (cartData().items && cartData().items.length !== 0) {
14+
customerData.reload(['cart'], false);
15+
}
16+
});
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)