Magento2: AddFotoramaVideoEvents is not a function on configurable product with no image on associated simple products

Created on 15 Mar 2017  Â·  6Comments  Â·  Source: magento/magento2

Preconditions

  1. Magento 2.1.4 and Magento 2.1.3

Steps to reproduce

  1. Fresh install of Magento 2.1.3 or 2.1.4
  2. Create a configurable product that has two or more configurable options
  3. Do not add an image to the simple products associated with the configurable product just created but feel free to add one to the configurable product.
  4. Browse to the configurable product just created and select any combination of the options in the dropdown.
  5. Notice there is now an error in the debugging console that says configurable.js:294 Uncaught TypeError: $(...).AddFotoramaVideoEvents is not a function

Expected result

  1. There should not be a Javascript error.

Actual result

  1. A Javascript error is produced

I have narrowed it down to this line $(this.options.mediaGallerySelector).AddFotoramaVideoEvents(); if you comment this out the error will obviously go away. I am just confused why it is trying to create a FotoramaVideoEvents widget when it is just an image.

Catalog Format is valid needs update bug report

All 6 comments

@Yamaha32088 Hi, unfortunally, I can't reproduce the issue as you described it. May you please confirm if this problem is relevant on latest release version of Magento 2?

According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.

I can confirm that issue for Magento 2.1.7.

Preconditions

  1. Magento CE 2.1.7
  2. Multiple Configurable product created

Steps to reproduce

  1. Go to any configurable product.
  2. Configure the product.
  3. Every time a configuration of the product (e.g. color, or size) is changed the javascript error is thrown.

EDIT: This problem does only appear when deactiving Magento_ProductVideo

This problem is caused when module-product-video is disabled because module-swatches has a dependency to module-product-video in swatch-renderer.js.

Even if the Magento ProductVideo module is enabled but the gallery.phtml block that it adds is moved or removed, you will get this error.

Kind of a silly dependency, I feel like this call to AddFotoramaVideoEvents() should be added to the swatch-renderer.js file via a mixin.

Anyway, my fix was to override the swatch-renderer.js file (copy it to Magento_Swatches/web/js/ in my theme) and just add a wrapper to test if the method exists:

if (isInitial) {
    if ($.isFunction($(this.options.mediaGallerySelector).AddFotoramaVideoEvents)) {
        $(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
    }
}

When overriding the catalog_product_view.xml, it seems that the changes in ProductVideo are no longer applied – so the line has to be added manually:

It works for me

<container name="product.info.media" htmlTag="div" htmlClass="product media" after="product.info.main"> <block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" as="media_image" template="product/view/gallery.phtml"/> <block class="Magento\ProductVideo\Block\Product\View\Gallery" name="product.info.media.video" after="product.info.media.image" template="product/view/gallery.phtml"/> </container>

Was this page helpful?
0 / 5 - 0 ratings