Skip to content

Commit a52b207

Browse files
committed
Merge branch 'issue-35981' of github.com:rogerdz/magento2 into 2.4-develop-prs
2 parents f342fd8 + 92f049e commit a52b207

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\SalesRule\Model\Rule\Condition;
87

98
/**
@@ -22,7 +21,7 @@ class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
2221
protected function _addSpecialAttributes(array &$attributes)
2322
{
2423
parent::_addSpecialAttributes($attributes);
25-
$attributes['quote_item_qty'] = __('Quantity in cart');
24+
$attributes['parent::quote_item_qty'] = __('Quantity in cart');
2625
$attributes['quote_item_price'] = __('Price in cart');
2726
$attributes['quote_item_row_total'] = __('Row total in cart');
2827

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getNewChildSelectOptions()
4545
$pAttributes = [];
4646
$iAttributes = [];
4747
foreach ($productAttributes as $code => $label) {
48-
if (strpos($code, 'quote_item_') === 0) {
48+
if (strpos($code, 'quote_item_') === 0 || strpos($code, 'parent::quote_item_') === 0) {
4949
$iAttributes[] = [
5050
'value' => \Magento\SalesRule\Model\Rule\Condition\Product::class . '|' . $code,
5151
'label' => $label,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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\SalesRule\Test\Unit\Model\Rule\Condition\Product;
9+
10+
use Magento\Rule\Model\Condition\Context;
11+
use Magento\SalesRule\Model\Rule\Condition\Product as SalesRuleProduct;
12+
use Magento\SalesRule\Model\Rule\Condition\Product\Combine;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class CombineTest extends TestCase
17+
{
18+
/**
19+
* @var Combine
20+
*/
21+
private $model;
22+
23+
/**
24+
* @var SalesRuleProduct|MockObject
25+
*/
26+
private $ruleConditionMock;
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
$contextMock = $this->getMockBuilder(Context::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$this->ruleConditionMock = $this->getMockBuilder(SalesRuleProduct::class)
37+
->setMethods(['loadAttributeOptions', 'getAttributeOption'])
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$this->model = new Combine(
41+
$contextMock,
42+
$this->ruleConditionMock,
43+
[]
44+
);
45+
}
46+
47+
/**
48+
* @return void
49+
*/
50+
public function testGetNewChildSelectOptions()
51+
{
52+
$this->ruleConditionMock->expects($this->any())
53+
->method('loadAttributeOptions')
54+
->willReturn($this->ruleConditionMock);
55+
$this->ruleConditionMock->expects($this->any())
56+
->method('getAttributeOption')
57+
->willReturn([
58+
'parent::quote_item_qty' => __('Quantity in cart'),
59+
'name' => __('Name')
60+
]);
61+
$this->assertEquals([
62+
[
63+
'value' => '',
64+
'label' => __('Please choose a condition to add.')],
65+
[
66+
'value' => Combine::class,
67+
'label' => __('Conditions Combination'),
68+
],
69+
[
70+
'label' => __('Cart Item Attribute'),
71+
'value' => [
72+
[
73+
'value' => SalesRuleProduct::class . '|' . 'parent::quote_item_qty',
74+
'label' => __('Quantity in cart'),
75+
]
76+
]
77+
],
78+
[
79+
'label' => __('Product Attribute'),
80+
'value' => [
81+
[
82+
'value' => SalesRuleProduct::class . '|' . 'name',
83+
'label' => __('Name'),
84+
]
85+
]
86+
]
87+
], $this->model->getNewChildSelectOptions());
88+
}
89+
}

0 commit comments

Comments
 (0)