Skip to content

Commit 93f14e9

Browse files
committed
PB-207: Empty "Category" or "SKU" condition option causes error on save
1 parent 4b7e4c3 commit 93f14e9

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/provider/conditions-data-processor.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ define([
1313
var serializer = new ConditionsDataNormalizer();
1414

1515
return function (data, attribute) {
16-
var pairs = {};
16+
var pairs = {},
17+
conditions = '';
1718

1819
/*
1920
* The Condition Rule Tree is not a UI component and doesn't provide good data.
@@ -33,27 +34,25 @@ define([
3334
/*
3435
* Add pairs in case conditions source is not rules configurator
3536
*/
36-
if (data.condition_option !== 'condition') {
37-
var conditionOperator = data[data.condition_option + '-condition_operator']
38-
? data[data.condition_option + '-condition_operator']
39-
: "==";
40-
var conditionValue = typeof data[data.condition_option] === 'string'
41-
? data[data.condition_option].trim()
42-
: '';
43-
pairs['parameters[' + attribute + '][1--1][operator]'] = conditionOperator;
44-
pairs['parameters[' + attribute + '][1--1][type]'] = "Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product";
45-
pairs['parameters[' + attribute + '][1][aggregator]'] = "all";
46-
pairs['parameters[' + attribute + '][1][new_child]'] = "";
47-
pairs['parameters[' + attribute + '][1][type]'] = "Magento\\CatalogWidget\\Model\\Rule\\Condition\\Combine";
48-
pairs['parameters[' + attribute + '][1][value]'] = "1";
49-
pairs['parameters[' + attribute + '][1--1][attribute]'] = data.condition_option;
50-
pairs['parameters[' + attribute + '][1--1][value]'] = conditionValue;
37+
if (data['condition_option'] !== 'condition') {
38+
pairs['parameters[' + attribute + '][1--1][operator]'] = data[data['condition_option'] + '-condition_operator'] ?
39+
data[data['condition_option'] + '-condition_operator'] :
40+
'==';
41+
pairs['parameters[' + attribute + '][1--1][type]'] = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product';
42+
pairs['parameters[' + attribute + '][1][aggregator]'] = 'all';
43+
pairs['parameters[' + attribute + '][1][new_child]'] = '';
44+
pairs['parameters[' + attribute + '][1][type]'] = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Combine';
45+
pairs['parameters[' + attribute + '][1][value]'] = '1';
46+
pairs['parameters[' + attribute + '][1--1][attribute]'] = data['condition_option'];
47+
pairs['parameters[' + attribute + '][1--1][value]'] = _.isString(data[data['condition_option']]) ?
48+
data[data['condition_option']].trim() :
49+
'';
5150
}
5251

5352
if (!_.isEmpty(pairs)) {
54-
var conditions = JSON.stringify(serializer.normalize(pairs).parameters[attribute]);
53+
conditions = JSON.stringify(serializer.normalize(pairs).parameters[attribute]);
5554
data['conditions_encoded'] = conditions;
56-
objectUtils.nested(data,attribute, conditions);
55+
objectUtils.nested(data, attribute, conditions);
5756
}
5857
};
5958
});

0 commit comments

Comments
 (0)