Skip to content

Commit b72f5c3

Browse files
committed
MAGETWO-65458: Cart Rules are not excluding Bundle Products
1 parent b1e02d8 commit b72f5c3

File tree

4 files changed

+123
-19
lines changed

4 files changed

+123
-19
lines changed

app/code/Magento/Bundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"suggest": {
2727
"magento/module-webapi": "*",
2828
"magento/module-bundle-sample-data": "*",
29-
"magento/module-sales-rule": "101.0.*"
29+
"magento/module-sales-rule": "*"
3030
},
3131
"type": "magento2-module",
3232
"license": [

app/code/Magento/SalesRule/Model/RulesApplier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class RulesApplier
4242
* @param \Magento\SalesRule\Model\Rule\Action\Discount\CalculatorFactory $calculatorFactory
4343
* @param \Magento\Framework\Event\ManagerInterface $eventManager
4444
* @param \Magento\SalesRule\Model\Utility $utility
45-
* @param ChildrenValidationLocator $childrenValidationLocator
45+
* @param ChildrenValidationLocator|null $childrenValidationLocator
4646
*/
4747
public function __construct(
4848
\Magento\SalesRule\Model\Rule\Action\Discount\CalculatorFactory $calculatorFactory,
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\SalesRule\Test\Unit\Model\Quote;
10+
11+
use Magento\SalesRule\Model\Quote\ChildrenValidationLocator;
12+
use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Catalog\Model\Product;
15+
16+
/**
17+
* Test for Magento\SalesRule\Model\Quote\ChildrenValidationLocator
18+
*/
19+
class ChildrenValidationLocatorTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var array
23+
*/
24+
private $productTypeChildrenValidationMap;
25+
26+
/**
27+
* @var ObjectManager
28+
*/
29+
private $objectManager;
30+
31+
/**
32+
* @var ChildrenValidationLocator
33+
*/
34+
private $model;
35+
36+
/**
37+
* @var QuoteItem|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $quoteItemMock;
40+
41+
/**
42+
* @var Product|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $productMock;
45+
46+
protected function setUp()
47+
{
48+
$this->objectManager = new ObjectManager($this);
49+
50+
$this->productTypeChildrenValidationMap = [
51+
'type1' => true,
52+
'type2' => false,
53+
];
54+
55+
$this->quoteItemMock = $this->getMockBuilder(QuoteItem::class)
56+
->disableOriginalConstructor()
57+
->setMethods(['getProduct'])
58+
->getMockForAbstractClass();
59+
60+
$this->productMock = $this->getMockBuilder(Product::class)
61+
->disableOriginalConstructor()
62+
->setMethods(['getTypeId'])
63+
->getMock();
64+
65+
$this->model = $this->objectManager->getObject(
66+
ChildrenValidationLocator::class,
67+
[
68+
'productTypeChildrenValidationMap' => $this->productTypeChildrenValidationMap,
69+
]
70+
);
71+
}
72+
73+
/**
74+
* @dataProvider productTypeDataProvider
75+
* @param string $type
76+
* @param bool $expected
77+
*
78+
* @return void
79+
*/
80+
public function testIsChildrenValidationRequired(string $type, bool $expected): void
81+
{
82+
$this->quoteItemMock->expects($this->once())
83+
->method('getProduct')
84+
->willReturn($this->productMock);
85+
86+
$this->productMock->expects($this->once())
87+
->method('getTypeId')
88+
->willReturn($type);
89+
90+
$this->assertEquals($this->model->isChildrenValidationRequired($this->quoteItemMock), $expected);
91+
}
92+
93+
/**
94+
* @return array
95+
*/
96+
public function productTypeDataProvider(): array
97+
{
98+
return [
99+
['type1', true],
100+
['type2', false],
101+
['type3', true],
102+
];
103+
}
104+
}

dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_sku_exclude.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'website_ids' => [
3636
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
3737
\Magento\Store\Model\StoreManagerInterface::class
38-
)->getWebsite()->getId()
38+
)->getWebsite()->getId(),
3939
],
4040
]
4141
);
@@ -49,24 +49,24 @@
4949
'aggregator' => 'all',
5050
'conditions' =>
5151
[
52-
[
53-
'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
54-
'attribute' => null,
55-
'operator' => null,
56-
'value' => '1',
57-
'is_value_processed' => null,
58-
'aggregator' => 'all',
59-
'conditions' =>
52+
[
53+
'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
54+
'attribute' => null,
55+
'operator' => null,
56+
'value' => '1',
57+
'is_value_processed' => null,
58+
'aggregator' => 'all',
59+
'conditions' =>
60+
[
6061
[
61-
[
62-
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
63-
'attribute' => 'sku',
64-
'operator' => '!=',
65-
'value' => 'product-bundle',
66-
'is_value_processed' => false,
67-
],
62+
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
63+
'attribute' => 'sku',
64+
'operator' => '!=',
65+
'value' => 'product-bundle',
66+
'is_value_processed' => false,
6867
],
69-
],
68+
],
69+
],
7070
],
7171
]);
7272

0 commit comments

Comments
 (0)