Skip to content

Instantly share code, notes, and snippets.

@Dan0sz
Created October 21, 2018 12:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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