Skip to content

Commit 1d9317d

Browse files
MC-32547: Error when adding product as button link in Pagebuilder
1 parent a202112 commit 1d9317d

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/ui-select.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ define([
11601160

11611161
if (this.isSearchKeyCached(searchKey)) {
11621162
cachedSearchResult = this.getCachedSearchResults(searchKey);
1163+
this.cacheOptions.plain = cachedSearchResult.options;
11631164
this.options(cachedSearchResult.options);
11641165
this.afterLoadOptions(searchKey, cachedSearchResult.lastPage, cachedSearchResult.total);
11651166

@@ -1274,6 +1275,7 @@ define([
12741275
});
12751276

12761277
this.total = response.total;
1278+
this.cacheOptions.plain = existingOptions;
12771279
this.options(existingOptions);
12781280
},
12791281

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/ui-select.test.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,24 @@ define([
624624
expect(obj.options).toHaveBeenCalledWith([]);
625625
expect(obj.processRequest).toHaveBeenCalledWith(searchKey, 1);
626626
});
627+
it('Should update cacheOptions if response was cached', function () {
628+
var searchKey = 'cake',
629+
searchResult = 'piece a cake';
630+
631+
obj.deviation = 30;
632+
obj.cachedSearchResults = {
633+
cake: {
634+
options: [searchResult],
635+
lastPage: 1,
636+
total: 1
637+
}
638+
};
639+
640+
spyOn(obj, 'options');
641+
obj.loadOptions(searchKey);
642+
expect(obj.options).toHaveBeenCalledWith([searchResult]);
643+
expect(obj.cacheOptions.plain).toContain(searchResult);
644+
});
627645
});
628646
describe('"isSearchKeyCached" method', function () {
629647
it('Should return false if searchKey has already been cached and total covers > 1 page', function () {
@@ -672,7 +690,7 @@ define([
672690
});
673691
});
674692
describe('"processRequest" method', function () {
675-
it('Should store options successfully fetched from ajax request', function () {
693+
it('Should store options and update cache successfully after fetched from ajax request', function () {
676694
var ajaxRequest,
677695
successfulAjaxResponse = {
678696
options: {
@@ -686,14 +704,43 @@ define([
686704
}
687705
};
688706

707+
// place a number of options to cache prior fetch
708+
obj.cacheOptions.plain = [{
709+
'2053': {
710+
value: '2057',
711+
label: 'testProductName5a8ddfd933b5c',
712+
'is_active': 1,
713+
path: 'testSku5a8ddfd933b5c',
714+
optgroup: false
715+
},
716+
'2054': {
717+
value: '2058',
718+
label: 'testProductName5a8ddfd933b5c',
719+
'is_active': 1,
720+
path: 'testSku5a8ddfd933b5c',
721+
optgroup: false
722+
}
723+
}];
724+
689725
$.ajax = jasmine.createSpy().and.callFake(function (request) {
690726
ajaxRequest = request.success.bind(obj);
691727
});
692728

693729
expect(obj.processRequest()).toBeUndefined();
694730

695731
ajaxRequest(successfulAjaxResponse);
696-
expect(JSON.stringify(obj.options())).toEqual(JSON.stringify([successfulAjaxResponse.options['2053']]));
732+
733+
expect(
734+
JSON.stringify(obj.options())
735+
).toEqual(
736+
JSON.stringify([successfulAjaxResponse.options['2053']])
737+
);
738+
739+
expect(
740+
JSON.stringify(obj.cacheOptions.plain)
741+
).toEqual(
742+
JSON.stringify([successfulAjaxResponse.options['2053']])
743+
);
697744
});
698745
});
699746
});

0 commit comments

Comments
 (0)