Skip to content

Commit 82b7b99

Browse files
committed
Merge remote-tracking branch 'origin/MC-30391' into 2.4-develop-pr11
2 parents fd48ead + 1bb9a79 commit 82b7b99

File tree

4 files changed

+117
-5
lines changed

4 files changed

+117
-5
lines changed

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Combine.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ private function validateEntity($cond, \Magento\Framework\Model\AbstractModel $e
145145
private function retrieveValidateEntities($attributeScope, \Magento\Framework\Model\AbstractModel $entity)
146146
{
147147
if ($attributeScope === 'parent') {
148-
$validateEntities = [$entity];
148+
$parentItem = $entity->getParentItem();
149+
$validateEntities = $parentItem ? [$parentItem] : [$entity];
149150
} elseif ($attributeScope === 'children') {
150151
$validateEntities = $entity->getChildren() ?: [$entity];
151152
} else {

dev/tests/integration/testsuite/Magento/SalesRule/Model/Rule/Condition/ProductTest.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\SalesRule\Model\Rule\Condition;
88

9+
use Magento\Framework\Registry;
10+
use Magento\SalesRule\Model\Rule;
11+
912
/**
1013
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1114
*/
@@ -50,8 +53,8 @@ public function testValidateCategorySalesRuleIncludesChildren($categoryId, $expe
5053
->load('test_cart_with_configurable', 'reserved_order_id');
5154

5255
// Load the SalesRule looking for products in a specific category
53-
/** @var $rule \Magento\SalesRule\Model\Rule */
54-
$rule = $this->objectManager->get(\Magento\Framework\Registry::class)
56+
/** @var $rule Rule */
57+
$rule = $this->objectManager->get(Registry::class)
5558
->registry('_fixture/Magento_SalesRule_Category');
5659

5760
// Prepare the parent product with the given category setting
@@ -80,8 +83,8 @@ public function testValidateSalesRuleExcludesBundleChildren(): void
8083
->load('test_cart_with_bundle_and_options', 'reserved_order_id');
8184

8285
// Load the SalesRule looking for excluding products with selected sku
83-
/** @var $rule \Magento\SalesRule\Model\Rule */
84-
$rule = $this->objectManager->get(\Magento\Framework\Registry::class)
86+
/** @var $rule Rule */
87+
$rule = $this->objectManager->get(Registry::class)
8588
->registry('_fixture/Magento_SalesRule_Sku_Exclude');
8689

8790
$this->assertEquals(false, $rule->validate($quote));
@@ -127,4 +130,25 @@ public function testValidateQtySalesRuleWithConfigurable()
127130
$rule->validate($quote->getBillingAddress())
128131
);
129132
}
133+
134+
/**
135+
* Ensure that SalesRules filtering on quote items quantity validates configurable product parent category correctly
136+
*
137+
* @magentoDataFixture Magento/ConfigurableProduct/_files/quote_with_configurable_product.php
138+
* @magentoDataFixture Magento/SalesRule/_files/rules_parent_category.php
139+
*/
140+
public function testValidateParentCategoryWithConfigurable()
141+
{
142+
$quote = $this->getQuote('test_cart_with_configurable');
143+
$registry = $this->objectManager->get(Registry::class);
144+
/** @var Rule $rule */
145+
$rule = $this->objectManager->create(Rule::class);
146+
$ruleId = $registry->registry('50% Off on Configurable parent category');
147+
$rule->load($ruleId);
148+
149+
$this->assertFalse(
150+
$rule->validate($quote->getBillingAddress()),
151+
'Cart price rule validation failed.'
152+
);
153+
}
130154
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
use Magento\Framework\Registry;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
/** @var Registry $registry */
12+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
13+
/** @var \Magento\SalesRule\Model\Rule $rule */
14+
$salesRule = Bootstrap::getObjectManager()->create(\Magento\SalesRule\Model\Rule::class);
15+
$salesRule->setData(
16+
[
17+
'name' => '50% Off on Configurable parent category',
18+
'is_active' => 1,
19+
'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID],
20+
'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON,
21+
'simple_action' => 'by_percent',
22+
'discount_amount' => 50,
23+
'discount_step' => 0,
24+
'stop_rules_processing' => 1,
25+
'website_ids' => [
26+
Bootstrap::getObjectManager()->get(
27+
\Magento\Store\Model\StoreManagerInterface::class
28+
)->getWebsite()->getId()
29+
]
30+
]
31+
);
32+
33+
$salesRule->getConditions()->loadArray([
34+
'type' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
35+
'attribute' => null,
36+
'operator' => null,
37+
'value' => '1',
38+
'is_value_processed' => null,
39+
'aggregator' => 'all',
40+
'conditions' =>
41+
[
42+
[
43+
'type' => \Magento\SalesRule\Model\Rule\Condition\Product\Subselect::class,
44+
'attribute' => 'qty',
45+
'operator' => '==',
46+
'value' => '1',
47+
'is_value_processed' => null,
48+
'aggregator' => 'all',
49+
'conditions' =>
50+
[
51+
[
52+
'type' => \Magento\SalesRule\Model\Rule\Condition\Product::class,
53+
'attribute' => 'category_ids',
54+
'attribute_scope' => 'parent',
55+
'operator' => '!=',
56+
'value' => '2',
57+
'is_value_processed' => false,
58+
],
59+
],
60+
],
61+
],
62+
]);
63+
64+
$salesRule->save();
65+
$registry->unregister('50% Off on Configurable parent category');
66+
$registry->register('50% Off on Configurable parent category', $salesRule->getRuleId());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
use Magento\SalesRule\Model\Rule;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Framework\Registry;
11+
12+
/** @var Registry $registry */
13+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
14+
$rule = Bootstrap::getObjectManager()->get(Rule::class);
15+
16+
/** @var Rule $rule */
17+
$ruleId = $registry->registry('50% Off on Configurable parent category');
18+
$rule->load($ruleId);
19+
if ($rule->getId()) {
20+
$rule->delete();
21+
}

0 commit comments

Comments
 (0)