Skip to content

Bugfix/js validation on pdp #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion view/frontend/web/js/gallery/gallery-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ define([
return function (gallery) {

return wrapper.wrap(gallery, function (initialize, config, element) {
if (_.isUndefined(config) || _.isEmpty(config))
return initialize(config, element);

if (_.isUndefined(config.data))
if (_.isUndefined(config.data) || _.isEmpty(config.data))
return initialize(config, element);

let wdpr = window.devicePixelRatio;
Expand Down
43 changes: 25 additions & 18 deletions view/frontend/web/js/swatch-renderer-mixin.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
define([
'mage/utils/wrapper',
'jquery',
'underscore'
], function (wrapper, _) {
], function ($, _) {
'use strict';

return function (swatchRenderer) {

return wrapper.wrap(swatchRenderer, function (create, config, element) {
$.widget('mage.SwatchRenderer', swatchRenderer, {

_init: function () {
if (_.isUndefined(this.options) || _.isEmpty(this.options))
return this._super();

if (_.isUndefined(config.jsonConfig))
return create(config, element);
if (_.isUndefined(this.options.jsonConfig) || _.isEmpty(this.options.jsonConfig))
return this._super();

if (_.isUndefined(config.jsonConfig.images))
return create(config, element);
if (_.isUndefined(this.options.jsonConfig.images) || _.isEmpty(this.options.jsonConfig.images))
return this._super();

let wdpr = window.devicePixelRatio;
let wdpr = window.devicePixelRatio;

_.each(config.jsonConfig.images, function (images) {
_.each(images, function (imageObject) {
if (_.isUndefined(imageObject.fastly_srcset))
return;
_.each(this.options.jsonConfig.images, function (images) {
_.each(images, function (imageObject) {
if (_.isUndefined(imageObject.fastly_srcset))
return;

if (!_.has(imageObject.fastly_srcset, wdpr))
return;
if (!_.has(imageObject.fastly_srcset, wdpr))
return;

imageObject.img = imageObject.fastly_srcset[wdpr];
imageObject.img = imageObject.fastly_srcset[wdpr];
});
});
});

create(config, element);
return this._super();
}
});

return $.mage.SwatchRenderer;
};
});
});