Skip to content

Instantly share code, notes, and snippets.

@Dan0sz Dan0sz/swatch-renderer-fixed.js Secret
Created Oct 21, 2018

Embed
What would you like to do?
Fix ‘Uncaught TypeError: Cannot read property ‘updateData’ of undefined’ in Magento 2
/**
* Start update base image process based on event name
* @param {Array} images
* @param {jQuery} context
* @param {Boolean} isInProductView
* @param {String|undefined} eventName
*/
updateBaseImage: function (images, context, isInProductView, eventName) {
var gallery = context.find(this.options.mediaGallerySelector).data('gallery');
// Check if gallery is defined.
if (eventName === undefined && gallery !== undefined) {
this.processUpdateBaseImage(images, context, isInProductView, gallery);
} else {
context.find(this.options.mediaGallerySelector).on('gallery:loaded', function (loadedGallery) {
loadedGallery = context.find(this.options.mediaGallerySelector).data('gallery');
this.processUpdateBaseImage(images, context, isInProductView, loadedGallery);
}.bind(this));
}
},
/**
* Start update base image process based on event name
* @param {Array} images
* @param {jQuery} context
* @param {Boolean} isInProductView
* @param {String|undefined} eventName
*/
updateBaseImage: function (images, context, isInProductView, eventName) {
var gallery = context.find(this.options.mediaGallerySelector).data('gallery');
if (eventName === undefined) {
this.processUpdateBaseImage(images, context, isInProductView, gallery);
} else {
context.find(this.options.mediaGallerySelector).on('gallery:loaded', function (loadedGallery) {
loadedGallery = context.find(this.options.mediaGallerySelector).data('gallery');
this.processUpdateBaseImage(images, context, isInProductView, loadedGallery);
}.bind(this));
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.