Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,52 @@ public function build(Filter $filter): string
{
$attribute = $this->getAttributeByCode($filter->getField());
$tableAlias = 'ca_' . $attribute->getAttributeCode();
$entityIdField = $attribute->getEntityIdField();
$isNegative = $this->isNegativeConditionType($filter->getConditionType());

$conditionType = $this->mapConditionType($filter->getConditionType());
if ($isNegative) {
$conditionType = $this->mapToPositiveConditionType($conditionType);
}
$conditionValue = $this->mapConditionValue($conditionType, $filter->getValue());

// NOTE: store scope was ignored intentionally to perform search across all stores
if ($conditionType == 'is_null') {
if ($conditionType === 'is_null') {
$entityResourceModel = $attribute->getEntity();
$attributeSelect = $this->resourceConnection->getConnection()
->select()
->from(
[Collection::MAIN_TABLE_ALIAS => $entityResourceModel->getEntityTable()],
Collection::MAIN_TABLE_ALIAS . '.' . $attribute->getEntityIdField()
Collection::MAIN_TABLE_ALIAS . '.' . $entityIdField
)->joinLeft(
[$tableAlias => $attribute->getBackendTable()],
$tableAlias . '.' . $attribute->getEntityIdField() . '=' . Collection::MAIN_TABLE_ALIAS .
'.' . $attribute->getEntityIdField() . ' AND ' . $tableAlias . '.' .
$tableAlias . '.' . $entityIdField . '=' . Collection::MAIN_TABLE_ALIAS .
'.' . $entityIdField . ' AND ' . $tableAlias . '.' .
$attribute->getIdFieldName() . '=' . $attribute->getAttributeId(),
''
)->where($tableAlias . '.value is null');
)->where(
$tableAlias . '.value IS NULL OR ' . $tableAlias . '.value = ?',
''
);
} elseif ($conditionType === 'notnull') {
$attributeSelect = $this->resourceConnection->getConnection()
->select()
->from(
[$tableAlias => $attribute->getBackendTable()],
$tableAlias . '.' . $entityIdField
)->where(
$this->resourceConnection->getConnection()->prepareSqlCondition(
$tableAlias . '.' . $attribute->getIdFieldName(),
['eq' => $attribute->getAttributeId()]
)
)->where($tableAlias . '.value IS NOT NULL')
->where($tableAlias . '.value != ?', '');
} else {
$attributeSelect = $this->resourceConnection->getConnection()
->select()
->from(
[$tableAlias => $attribute->getBackendTable()],
$tableAlias . '.' . $attribute->getEntityIdField()
$tableAlias . '.' . $entityIdField
)->where(
$this->resourceConnection->getConnection()->prepareSqlCondition(
$tableAlias . '.' . $attribute->getIdFieldName(),
Expand All @@ -91,12 +112,14 @@ public function build(Filter $filter): string
);
}

$outerConditionType = $isNegative ? 'nin' : 'in';

return $this->resourceConnection
->getConnection()
->prepareSqlCondition(
Collection::MAIN_TABLE_ALIAS . '.' . $attribute->getEntityIdField(),
Collection::MAIN_TABLE_ALIAS . '.' . $entityIdField,
[
'in' => $attributeSelect
$outerConditionType => $attributeSelect
]
);
}
Expand Down Expand Up @@ -129,6 +152,34 @@ private function mapConditionType(string $conditionType): string
return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
}

/**
* Whether the filter condition type is a negative comparison.
*
* @param string $conditionType
* @return bool
*/
private function isNegativeConditionType(string $conditionType): bool
{
return in_array($conditionType, ['neq', 'nin', 'nlike'], true);
}

/**
* Map a (possibly already-mapped) negative condition type to its positive counterpart.
*
* @param string $conditionType
* @return string
*/
private function mapToPositiveConditionType(string $conditionType): string
{
$conditionsMap = [
'neq' => 'eq',
'nin' => 'in',
'nlike' => 'like',
];

return $conditionsMap[$conditionType] ?? $conditionType;
}

/**
* Wraps value with '%' if condition type is 'like' or 'not like'
*
Expand All @@ -140,7 +191,7 @@ private function mapConditionValue(string $conditionType, string $conditionValue
{
$conditionsMap = ['like', 'nlike'];

if (in_array($conditionType, $conditionsMap)) {
if (in_array($conditionType, $conditionsMap, true)) {
$conditionValue = '%' . $conditionValue . '%';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ private function reverseSqlOperatorInFilter(Filter $filter)
'nlike' => 'like',
'in' => 'nin',
'nin' => 'in',
'is_null' => 'notnull',
'notnull' => 'is_null',
];

if (!array_key_exists($filter->getConditionType(), $operatorsMap)) {
Expand Down Expand Up @@ -299,7 +301,7 @@ private function mapRuleOperatorToSQLCondition(string $ruleOperator): string
'!{}' => 'nlike', // does not contains
'()' => 'in', // is one of
'!()' => 'nin', // is not one of
'<=>' => 'is_null'
'<=>' => 'is_null',
];

if (!array_key_exists($ruleOperator, $operatorsMap)) {
Expand Down
23 changes: 17 additions & 6 deletions app/code/Magento/CatalogRule/Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
$this->_setAttributeValue($model);

$attrValue = $model->getData($attrCode);
if ($attrValue === null) {
if ($this->getOperator() === '<=>') {
$this->_restoreOldAttrValue($model, $oldAttrValue);
return true;
}
if ($this->isAttributeValueUndefined($attrValue)) {
// Missing/empty values match "is undefined" and negative operators (is not / does not contain / …).
// "Is defined" is expressed as a FALSE combine over "is undefined", not a separate operator.
$operator = $this->getOperator();
$matchesMissingValue = $operator === '<=>' || $this->isNegativeOperator($operator);
$this->_restoreOldAttrValue($model, $oldAttrValue);
return false;
return $matchesMissingValue;
}

$result = $this->validateAttribute($attrValue);
Expand Down Expand Up @@ -131,4 +131,15 @@ protected function _prepareMultiselectValue($value, \Magento\Framework\Model\Abs

return $value;
}

/**
* Whether operator is a negative comparison that should match missing attribute values.
*
* @param string|null $operator
* @return bool
*/
private function isNegativeOperator(?string $operator): bool
{
return in_array($operator, ['!=', '!{}', '!()'], true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright 2026 Adobe
* All Rights Reserved.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminFillCatalogRuleIsUndefinedConditionActionGroup">
<annotations>
<description>
Add an "is undefined" product attribute condition on Catalog Price Rule Conditions tab.
Use defaultOperatorLabel "contains" for multiselect and "is" for select/boolean attributes.
</description>
</annotations>
<arguments>
<argument name="condition" type="string"/>
<argument name="defaultOperatorLabel" type="string" defaultValue="contains"/>
</arguments>

<conditionalClick selector="{{AdminNewCatalogPriceRule.conditionsTab}}" dependentSelector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" visible="false" stepKey="openConditionsTab"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" stepKey="waitForAddConditionButton"/>
<click selector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" stepKey="addNewCondition"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.conditionSelect('1')}}" stepKey="waitForConditionSelect"/>
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.conditionSelect('1')}}" userInput="{{condition}}" stepKey="selectAttributeCondition"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.condition(defaultOperatorLabel)}}" stepKey="waitForDefaultOperator"/>
<click selector="{{AdminNewCatalogPriceRuleConditions.condition(defaultOperatorLabel)}}" stepKey="clickDefaultOperator"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" stepKey="waitForOperatorSelect"/>
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" userInput="is undefined" stepKey="selectIsUndefinedOperator"/>
<conditionalClick selector="{{AdminNewCatalogPriceRuleConditions.condition('...')}}" dependentSelector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" visible="true" stepKey="closeOperatorSelect"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright 2026 Adobe
* All Rights Reserved.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminFillCatalogRuleMultiselectConditionActionGroup">
<annotations>
<description>
Add a multiselect product attribute condition on Catalog Price Rule Conditions tab.
Default operator label is "contains"; select another operator and option value as needed.
</description>
</annotations>
<arguments>
<argument name="condition" type="string"/>
<argument name="conditionOperator" type="string" defaultValue="does not contain"/>
<argument name="conditionValue" type="string"/>
</arguments>

<conditionalClick selector="{{AdminNewCatalogPriceRule.conditionsTab}}" dependentSelector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" visible="false" stepKey="openConditionsTab"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" stepKey="waitForAddConditionButton"/>
<click selector="{{AdminNewCatalogPriceRuleConditions.newCondition}}" stepKey="addNewCondition"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.conditionSelect('1')}}" stepKey="waitForConditionSelect"/>
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.conditionSelect('1')}}" userInput="{{condition}}" stepKey="selectAttributeCondition"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.condition('contains')}}" stepKey="waitForDefaultOperator"/>
<click selector="{{AdminNewCatalogPriceRuleConditions.condition('contains')}}" stepKey="clickDefaultOperator"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" stepKey="waitForOperatorSelect"/>
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" userInput="{{conditionOperator}}" stepKey="selectConditionOperator"/>
<conditionalClick selector="{{AdminNewCatalogPriceRuleConditions.condition('...')}}" dependentSelector="{{AdminNewCatalogPriceRuleConditions.activeOperatorSelect}}" visible="true" stepKey="closeOperatorSelect"/>
<click selector="{{AdminNewCatalogPriceRuleConditions.condition('...')}}" stepKey="clickValueEllipsis"/>
<waitForElementVisible selector="{{AdminNewCatalogPriceRuleConditions.activeValueInput}}" stepKey="waitForValueInput"/>
<!-- Multiselect/select value chooser auto-applies on option select (no rule-param-apply control). -->
<selectOption selector="{{AdminNewCatalogPriceRuleConditions.activeValueInput}}" userInput="{{conditionValue}}" stepKey="selectConditionValue"/>
<waitForPageLoad stepKey="waitAfterSelectConditionValue"/>
</actionGroup>
</actionGroups>
Loading