Skip to content

Instantly share code, notes, and snippets.

@Dan0sz
Created October 21, 2018 12:14
Show Gist options
  • Save Dan0sz/3f84e42607d1fb46680889f804008a3f to your computer and use it in GitHub Desktop.
Save Dan0sz/3f84e42607d1fb46680889f804008a3f to your computer and use it in GitHub Desktop.
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