Skip to content

Commit 3b39071

Browse files
Merge remote-tracking branch 'remotes/github/MC-10971' into EPAM-PR-41
2 parents e6d8d6e + 069d343 commit 3b39071

File tree

10 files changed

+292
-21
lines changed

10 files changed

+292
-21
lines changed

app/code/Magento/Catalog/Model/Api/SearchCriteria/CollectionProcessor/ConditionProcessor/ConditionBuilder/EavAttributeCondition.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,38 @@ public function build(Filter $filter): string
5858
$conditionValue = $this->mapConditionValue($conditionType, $filter->getValue());
5959

6060
// NOTE: store scope was ignored intentionally to perform search across all stores
61-
$attributeSelect = $this->resourceConnection->getConnection()
62-
->select()
63-
->from(
64-
[$tableAlias => $attribute->getBackendTable()],
65-
$tableAlias . '.' . $attribute->getEntityIdField()
66-
)->where(
67-
$this->resourceConnection->getConnection()->prepareSqlCondition(
68-
$tableAlias . '.' . $attribute->getIdFieldName(),
69-
['eq' => $attribute->getAttributeId()]
70-
)
71-
)->where(
72-
$this->resourceConnection->getConnection()->prepareSqlCondition(
73-
$tableAlias . '.value',
74-
[$conditionType => $conditionValue]
75-
)
76-
);
61+
if ($conditionType == 'is_null') {
62+
$entityResourceModel = $attribute->getEntity();
63+
$attributeSelect = $this->resourceConnection->getConnection()
64+
->select()
65+
->from(
66+
[Collection::MAIN_TABLE_ALIAS => $entityResourceModel->getEntityTable()],
67+
Collection::MAIN_TABLE_ALIAS . '.' . $entityResourceModel->getEntityIdField()
68+
)->joinLeft(
69+
[$tableAlias => $attribute->getBackendTable()],
70+
$tableAlias . '.' . $attribute->getEntityIdField() . '=' . Collection::MAIN_TABLE_ALIAS .
71+
'.' . $entityResourceModel->getEntityIdField() . ' AND ' . $tableAlias . '.' .
72+
$attribute->getIdFieldName() . '=' . $attribute->getAttributeId(),
73+
''
74+
)->where($tableAlias . '.value is null');
75+
} else {
76+
$attributeSelect = $this->resourceConnection->getConnection()
77+
->select()
78+
->from(
79+
[$tableAlias => $attribute->getBackendTable()],
80+
$tableAlias . '.' . $attribute->getEntityIdField()
81+
)->where(
82+
$this->resourceConnection->getConnection()->prepareSqlCondition(
83+
$tableAlias . '.' . $attribute->getIdFieldName(),
84+
['eq' => $attribute->getAttributeId()]
85+
)
86+
)->where(
87+
$this->resourceConnection->getConnection()->prepareSqlCondition(
88+
$tableAlias . '.value',
89+
[$conditionType => $conditionValue]
90+
)
91+
);
92+
}
7793

7894
return $this->resourceConnection
7995
->getConnection()
@@ -86,6 +102,8 @@ public function build(Filter $filter): string
86102
}
87103

88104
/**
105+
* Get attribute entity by its code
106+
*
89107
* @param string $field
90108
* @return Attribute
91109
* @throws \Magento\Framework\Exception\LocalizedException

app/code/Magento/Catalog/Test/Mftf/Data/ProductAttributeData.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,25 @@
115115
<data key="used_for_sort_by">true</data>
116116
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
117117
</entity>
118+
<entity name="productYesNoAttribute" type="ProductAttribute">
119+
<data key="attribute_code" unique="suffix">attribute</data>
120+
<data key="frontend_input">boolean</data>
121+
<data key="scope">global</data>
122+
<data key="is_required">false</data>
123+
<data key="is_unique">false</data>
124+
<data key="is_searchable">true</data>
125+
<data key="is_visible">true</data>
126+
<data key="is_visible_in_advanced_search">true</data>
127+
<data key="is_visible_on_front">true</data>
128+
<data key="is_filterable">true</data>
129+
<data key="is_filterable_in_search">true</data>
130+
<data key="used_in_product_listing">true</data>
131+
<data key="is_used_for_promo_rules">true</data>
132+
<data key="is_comparable">true</data>
133+
<data key="is_used_in_grid">true</data>
134+
<data key="is_visible_in_grid">true</data>
135+
<data key="is_filterable_in_grid">true</data>
136+
<data key="used_for_sort_by">true</data>
137+
<requiredEntity type="FrontendLabel">ProductAttributeFrontendLabel</requiredEntity>
138+
</entity>
118139
</entities>

app/code/Magento/CatalogRule/Model/Rule/Condition/ConditionsToSearchCriteriaMapper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function mapConditionsToSearchCriteria(CombinedCondition $conditions): Se
7171
}
7272

7373
/**
74+
* Convert condition to filter group
75+
*
7476
* @param ConditionInterface $condition
7577
* @return null|\Magento\Framework\Api\CombinedFilterGroup|\Magento\Framework\Api\Filter
7678
* @throws InputException
@@ -89,6 +91,8 @@ private function mapConditionToFilterGroup(ConditionInterface $condition)
8991
}
9092

9193
/**
94+
* Convert combined condition to filter group
95+
*
9296
* @param Combine $combinedCondition
9397
* @return null|\Magento\Framework\Api\CombinedFilterGroup
9498
* @throws InputException
@@ -121,6 +125,8 @@ private function mapCombinedConditionToFilterGroup(CombinedCondition $combinedCo
121125
}
122126

123127
/**
128+
* Convert simple condition to filter group
129+
*
124130
* @param ConditionInterface $productCondition
125131
* @return FilterGroup|Filter
126132
* @throws InputException
@@ -139,6 +145,8 @@ private function mapSimpleConditionToFilterGroup(ConditionInterface $productCond
139145
}
140146

141147
/**
148+
* Convert simple condition with array value to filter group
149+
*
142150
* @param ConditionInterface $productCondition
143151
* @return FilterGroup
144152
* @throws InputException
@@ -161,6 +169,8 @@ private function processSimpleConditionWithArrayValue(ConditionInterface $produc
161169
}
162170

163171
/**
172+
* Get glue for multiple values by operator
173+
*
164174
* @param string $operator
165175
* @return string
166176
*/
@@ -211,6 +221,8 @@ private function reverseSqlOperatorInFilter(Filter $filter)
211221
}
212222

213223
/**
224+
* Convert filters array into combined filter group
225+
*
214226
* @param array $filters
215227
* @param string $combinationMode
216228
* @return FilterGroup
@@ -227,6 +239,8 @@ private function createCombinedFilterGroup(array $filters, string $combinationMo
227239
}
228240

229241
/**
242+
* Creating of filter object by filtering params
243+
*
230244
* @param string $field
231245
* @param string $value
232246
* @param string $conditionType
@@ -264,6 +278,7 @@ private function mapRuleOperatorToSQLCondition(string $ruleOperator): string
264278
'!{}' => 'nlike', // does not contains
265279
'()' => 'in', // is one of
266280
'!()' => 'nin', // is not one of
281+
'<=>' => 'is_null'
267282
];
268283

269284
if (!array_key_exists($ruleOperator, $operatorsMap)) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Catalog Rule Product Condition data model
9-
*/
107
namespace Magento\CatalogRule\Model\Rule\Condition;
118

129
/**
10+
* Catalog Rule Product Condition data model
11+
*
1312
* @method string getAttribute() Returns attribute code
1413
*/
1514
class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
@@ -29,6 +28,9 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
2928

3029
$oldAttrValue = $model->getData($attrCode);
3130
if ($oldAttrValue === null) {
31+
if ($this->getOperator() === '<=>') {
32+
return true;
33+
}
3234
return false;
3335
}
3436

app/code/Magento/CatalogRule/Test/Mftf/ActionGroup/CatalogPriceRuleActionGroup.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,39 @@
3636
<waitForPageLoad stepKey="waitForApplied"/>
3737
</actionGroup>
3838

39+
40+
<actionGroup name="createCatalogPriceRule">
41+
<arguments>
42+
<argument name="catalogRule" defaultValue="_defaultCatalogRule"/>
43+
</arguments>
44+
45+
<click stepKey="addNewRule" selector="{{AdminGridMainControls.add}}"/>
46+
<fillField selector="{{AdminNewCatalogPriceRule.ruleName}}" userInput="{{catalogRule.name}}" stepKey="fillName" />
47+
<fillField selector="{{AdminNewCatalogPriceRule.description}}" userInput="{{catalogRule.description}}" stepKey="fillDescription" />
48+
<selectOption selector="{{AdminNewCatalogPriceRule.websites}}" parameterArray="{{catalogRule.website_ids}}" stepKey="selectSite" />
49+
<click stepKey="openActionDropdown" selector="{{AdminNewCatalogPriceRule.actionsTab}}"/>
50+
<fillField stepKey="fillDiscountValue" selector="{{AdminNewCatalogPriceRuleActions.discountAmount}}" userInput="{{catalogRule.discount_amount}}"/>
51+
52+
<scrollToTopOfPage stepKey="scrollToTop"/>
53+
<waitForPageLoad stepKey="waitForApplied"/>
54+
</actionGroup>
55+
56+
<actionGroup name="CreateCatalogPriceRuleConditionWithAttribute">
57+
<arguments>
58+
<argument name="attributeName" type="string"/>
59+
<argument name="targetValue" type="string"/>
60+
<argument name="targetSelectValue" type="string"/>
61+
</arguments>
62+
63+
<click selector="{{AdminNewCatalogPriceRule.conditionsTab}}" stepKey="openConditionsTab"/>
64+
<waitForPageLoad stepKey="waitForConditionTabOpened"/>
65+
<click selector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" stepKey="addNewCondition"/>
66+
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.conditionSelect('1')}}" userInput="{{attributeName}}" stepKey="selectTypeCondition"/>
67+
<waitForElement selector="{{AdminNewCatalogPriceRuleConditions.targetEllipsisValue('1', targetValue)}}" stepKey="waitForIsTarget"/>
68+
<click selector="{{AdminNewCatalogPriceRuleConditions.targetEllipsisValue('1', 'is')}}" stepKey="clickOnIs"/>
69+
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.targetSelect('1')}}" userInput="{{targetSelectValue}}" stepKey="selectTargetCondition"/>
70+
</actionGroup>
71+
3972
<!-- Apply all of the saved catalog price rules -->
4073
<actionGroup name="applyCatalogPriceRules">
4174
<amOnPage stepKey="goToPriceRulePage" url="{{CatalogRulePage.url}}"/>
@@ -77,4 +110,8 @@
77110
<actionGroup name="selectGeneralCustomerGroupActionGroup">
78111
<selectOption selector="{{AdminNewCatalogPriceRule.customerGroups}}" userInput="General" stepKey="selectCustomerGroup"/>
79112
</actionGroup>
113+
114+
<actionGroup name="selectNotLoggedInCustomerGroupActionGroup">
115+
<selectOption selector="{{AdminNewCatalogPriceRule.customerGroups}}" userInput="NOT LOGGED IN" stepKey="selectCustomerGroup"/>
116+
</actionGroup>
80117
</actionGroups>

app/code/Magento/CatalogRule/Test/Mftf/Data/CatalogRuleData.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,21 @@
7777
<data key="simple_action">by_percent</data>
7878
<data key="discount_amount">96</data>
7979
</entity>
80+
81+
<entity name="CatalogRuleWithAllCustomerGroups" type="catalogRule">
82+
<data key="name" unique="suffix">CatalogPriceRule</data>
83+
<data key="description">Catalog Price Rule Description</data>
84+
<data key="is_active">1</data>
85+
<array key="customer_group_ids">
86+
<item>0</item>
87+
<item>1</item>
88+
<item>2</item>
89+
<item>3</item>
90+
</array>
91+
<array key="website_ids">
92+
<item>1</item>
93+
</array>
94+
<data key="simple_action">by_percent</data>
95+
<data key="discount_amount">10</data>
96+
</entity>
8097
</entities>

app/code/Magento/CatalogRule/Test/Mftf/Section/AdminNewCatalogPriceRuleSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<element name="newCondition" type="button" selector=".rule-param.rule-param-new-child"/>
4242
<element name="conditionSelect" type="select" selector="select#conditions__{{var}}__new_child" parameterized="true"/>
4343
<element name="targetEllipsis" type="button" selector="//li[{{var}}]//a[@class='label'][text() = '...']" parameterized="true"/>
44+
<element name="targetEllipsisValue" type="button" selector="//ul[@id='conditions__{{var}}__children']//a[contains(text(), '{{var1}}')]" parameterized="true" timeout="30"/>
45+
<element name="targetSelect" type="select" selector="//ul[@id='conditions__{{var}}__children']//select" parameterized="true" timeout="30"/>
4446
<element name="targetInput" type="input" selector="input#conditions__{{var1}}--{{var2}}__value" parameterized="true"/>
4547
<element name="applyButton" type="button" selector="#conditions__{{var1}}__children li:nth-of-type({{var2}}) a.rule-param-apply" parameterized="true"/>
4648
</section>

0 commit comments

Comments
 (0)