Skip to content

Commit 42cecc4

Browse files
committed
PB-301: Products lose their conditions after upgrade
1 parent b781986 commit 42cecc4

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/products/mass-converter/widget-directive.js

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/products/mass-converter/widget-directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class WidgetDirective extends BaseWidgetDirective {
2929

3030
data.products_count = attributes.products_count;
3131
data.sort_order = attributes.sort_order;
32-
data.condition_option = attributes.condition_option;
32+
data.condition_option = attributes.condition_option || "condition";
3333
data[data.condition_option] = this.decodeWysiwygCharacters(attributes.condition_option_value || "");
3434
data.conditions_encoded = this.decodeWysiwygCharacters(attributes.conditions_encoded || "");
3535
data[data.condition_option + "_source"] = data.conditions_encoded;
@@ -51,11 +51,11 @@ export default class WidgetDirective extends BaseWidgetDirective {
5151
id_path: "",
5252
show_pager: 0,
5353
products_count: data.products_count,
54-
sort_order: data.sort_order,
5554
condition_option: data.condition_option,
5655
condition_option_value: "",
5756
type_name: "Catalog Products List",
5857
conditions_encoded: this.encodeWysiwygCharacters(data.conditions_encoded || ""),
58+
...data.sort_order && { sort_order: data.sort_order}
5959
};
6060

6161
if (typeof data[data.condition_option] === "string") {

dev/tests/js/jasmine/tests/app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/products/mass-converter/widget-directive.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ define([
6969
it('Should transform regular properties', function () {
7070
var data = {
7171
products_count: 123,
72-
conditions_encoded: '[]'
72+
conditions_encoded: '[]',
73+
condition_option: 'condition',
74+
sort_order: 'position'
7375
},
7476
config = {
7577
html_variable: 'myhtml'
@@ -85,6 +87,9 @@ define([
8587
expect(result.myhtml).toContain(' id_path=""');
8688
expect(result.myhtml).toContain(' show_pager="0"');
8789
expect(result.myhtml).toContain(' type_name="Catalog Products List"');
90+
expect(result.myhtml).toContain(' condition_option="condition');
91+
expect(result.myhtml).toContain(' sort_order="position');
92+
expect(result.myhtml).toContain(' condition_option_value=""');
8893
});
8994
it('Should encode conditions_encoded', function () {
9095
var data = {
@@ -105,12 +110,24 @@ define([
105110
expect(result.myhtml).toContain(' show_pager="0"');
106111
expect(result.myhtml).toContain(' type_name="Catalog Products List"');
107112
});
113+
it('Should not add empty sort_order attribute', function () {
114+
var data = {
115+
products_count: 123,
116+
conditions_encoded: '[]'
117+
},
118+
config = {
119+
html_variable: 'myhtml'
120+
},
121+
result = model.toDom(data, config);
122+
expect(result.myhtml).not.toContain('sort_order');
123+
});
108124
});
109125
describe('fromDom', function () {
110126
it('Should parse regular properties without conditions_encoded', function () {
111127
var expected = {
112128
products_count: '123',
113-
conditions_encoded: ''
129+
conditions_encoded: '',
130+
condition_option: 'condition'
114131
},
115132
config = {
116133
html_variable: 'myhtml'
@@ -122,6 +139,7 @@ define([
122139

123140
expect(result.products_count).toBe(expected.products_count);
124141
expect(result.conditions_encoded).toBe(expected.conditions_encoded);
142+
expect(result.condition_option).toBe(expected.condition_option);
125143
// assert the automatically added properties do not get returned.
126144
expect(result.type).toBe(undefined);
127145
expect(result.id_path).toBe(undefined);

0 commit comments

Comments
 (0)