Skip to content

Commit e3c9976

Browse files
authored
Merge pull request #457 from favicode/bugfix/js-validation-on-pdp
Bugfix/js validation on pdp
2 parents 7e78881 + 730ccb0 commit e3c9976

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

Diff for: view/frontend/web/js/gallery/gallery-mixin.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ define([
77
return function (gallery) {
88

99
return wrapper.wrap(gallery, function (initialize, config, element) {
10+
if (_.isUndefined(config) || _.isEmpty(config))
11+
return initialize(config, element);
1012

11-
if (_.isUndefined(config.data))
13+
if (_.isUndefined(config.data) || _.isEmpty(config.data))
1214
return initialize(config, element);
1315

1416
let wdpr = window.devicePixelRatio;

Diff for: view/frontend/web/js/swatch-renderer-mixin.js

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
define([
2-
'mage/utils/wrapper',
2+
'jquery',
33
'underscore'
4-
], function (wrapper, _) {
4+
], function ($, _) {
55
'use strict';
66

77
return function (swatchRenderer) {
88

9-
return wrapper.wrap(swatchRenderer, function (create, config, element) {
9+
$.widget('mage.SwatchRenderer', swatchRenderer, {
10+
11+
_init: function () {
12+
if (_.isUndefined(this.options) || _.isEmpty(this.options))
13+
return this._super();
1014

11-
if (_.isUndefined(config.jsonConfig))
12-
return create(config, element);
15+
if (_.isUndefined(this.options.jsonConfig) || _.isEmpty(this.options.jsonConfig))
16+
return this._super();
1317

14-
if (_.isUndefined(config.jsonConfig.images))
15-
return create(config, element);
18+
if (_.isUndefined(this.options.jsonConfig.images) || _.isEmpty(this.options.jsonConfig.images))
19+
return this._super();
1620

17-
let wdpr = window.devicePixelRatio;
21+
let wdpr = window.devicePixelRatio;
1822

19-
_.each(config.jsonConfig.images, function (images) {
20-
_.each(images, function (imageObject) {
21-
if (_.isUndefined(imageObject.fastly_srcset))
22-
return;
23+
_.each(this.options.jsonConfig.images, function (images) {
24+
_.each(images, function (imageObject) {
25+
if (_.isUndefined(imageObject.fastly_srcset))
26+
return;
2327

24-
if (!_.has(imageObject.fastly_srcset, wdpr))
25-
return;
28+
if (!_.has(imageObject.fastly_srcset, wdpr))
29+
return;
2630

27-
imageObject.img = imageObject.fastly_srcset[wdpr];
31+
imageObject.img = imageObject.fastly_srcset[wdpr];
32+
});
2833
});
29-
});
3034

31-
create(config, element);
35+
return this._super();
36+
}
3237
});
38+
39+
return $.mage.SwatchRenderer;
3340
};
34-
});
41+
});

0 commit comments

Comments
 (0)