Skip to content

Commit 19b0dc9

Browse files
authored
Merge pull request #342 from magento-obsessive-owls/PB-301
[Owls] PB-301 Products lose their conditions after upgrade
2 parents dbe3e2c + babef83 commit 19b0dc9

File tree

6 files changed

+65
-15
lines changed

6 files changed

+65
-15
lines changed

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

Lines changed: 5 additions & 2 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/js/content-type/products/mass-converter/widget-directive.js

Lines changed: 5 additions & 2 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/carousel-widget-directive.ts

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

3030
data.carousel_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,12 +51,15 @@ export default class WidgetDirective extends BaseWidgetDirective {
5151
id_path: "",
5252
show_pager: 0,
5353
products_count: data.carousel_products_count,
54-
sort_order: data.sort_order,
5554
condition_option: data.condition_option,
5655
condition_option_value: "",
5756
type_name: "Catalog Products Carousel",
5857
conditions_encoded: this.encodeWysiwygCharacters(data.conditions_encoded || ""),
59-
};
58+
} as { [key: string]: any; };
59+
60+
if (data.sort_order) {
61+
attributes.sort_order = data.sort_order
62+
}
6063

6164
if (typeof data[data.condition_option] === "string") {
6265
attributes.condition_option_value = this.encodeWysiwygCharacters(data[data.condition_option]);

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

Lines changed: 7 additions & 4 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,12 +51,15 @@ 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",
58-
conditions_encoded: this.encodeWysiwygCharacters(data.conditions_encoded || ""),
59-
};
57+
conditions_encoded: this.encodeWysiwygCharacters(data.conditions_encoded || "")
58+
} as { [key: string]: any; };
59+
60+
if (data.sort_order) {
61+
attributes.sort_order = data.sort_order
62+
}
6063

6164
if (typeof data[data.condition_option] === "string") {
6265
attributes.condition_option_value = this.encodeWysiwygCharacters(data[data.condition_option]);

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

Lines changed: 21 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
carousel_products_count: 123,
72-
conditions_encoded: '[]'
72+
conditions_encoded: '[]',
73+
condition_option: 'condition',
74+
sort_order: 'position'
7375
},
7476
config = {
7577
html_variable: 'myhtml'
@@ -86,6 +88,9 @@ define([
8688
expect(result.myhtml).toContain(' id_path=""');
8789
expect(result.myhtml).toContain(' show_pager="0"');
8890
expect(result.myhtml).toContain(' type_name="Catalog Products Carousel"');
91+
expect(result.myhtml).toContain(' condition_option="condition');
92+
expect(result.myhtml).toContain(' sort_order="position');
93+
expect(result.myhtml).toContain(' condition_option_value=""');
8994
});
9095
it('Should encode conditions_encoded', function () {
9196
var data = {
@@ -107,12 +112,25 @@ define([
107112
expect(result.myhtml).toContain(' show_pager="0"');
108113
expect(result.myhtml).toContain(' type_name="Catalog Products Carousel"');
109114
});
115+
it('Should not add empty sort_order attribute', function () {
116+
var data = {
117+
carousel_products_count: 123,
118+
conditions_encoded: '[]'
119+
},
120+
config = {
121+
html_variable: 'myhtml'
122+
},
123+
result = model.toDom(data, config);
124+
125+
expect(result.myhtml).not.toContain('sort_order');
126+
});
110127
});
111128
describe('fromDom', function () {
112129
it('Should parse regular properties without conditions_encoded', function () {
113130
var expected = {
114131
carousel_products_count: '123',
115-
conditions_encoded: ''
132+
conditions_encoded: '',
133+
condition_option: 'condition'
116134
},
117135
config = {
118136
html_variable: 'myhtml'
@@ -124,6 +142,7 @@ define([
124142

125143
expect(result.carousel_products_count).toBe(expected.carousel_products_count);
126144
expect(result.conditions_encoded).toBe(expected.conditions_encoded);
145+
expect(result.condition_option).toBe(expected.condition_option);
127146
// assert the automatically added properties do not get returned.
128147
expect(result.type).toBe(undefined);
129148
expect(result.id_path).toBe(undefined);

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

Lines changed: 21 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,25 @@ 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+
123+
expect(result.myhtml).not.toContain('sort_order');
124+
});
108125
});
109126
describe('fromDom', function () {
110127
it('Should parse regular properties without conditions_encoded', function () {
111128
var expected = {
112129
products_count: '123',
113-
conditions_encoded: ''
130+
conditions_encoded: '',
131+
condition_option: 'condition'
114132
},
115133
config = {
116134
html_variable: 'myhtml'
@@ -122,6 +140,7 @@ define([
122140

123141
expect(result.products_count).toBe(expected.products_count);
124142
expect(result.conditions_encoded).toBe(expected.conditions_encoded);
143+
expect(result.condition_option).toBe(expected.condition_option);
125144
// assert the automatically added properties do not get returned.
126145
expect(result.type).toBe(undefined);
127146
expect(result.id_path).toBe(undefined);

0 commit comments

Comments
 (0)