Magento2: When viewing product only the image shows

Created on 27 Jun 2019  路  17Comments  路  Source: magento/magento2

Upgraded to 2.3.2 and now when viewing a product only the product image shows and the following PHP error is generated.

[27-Jun-2019 01:14:57 UTC] PHP Fatal error: Uncaught Error: Call to a member function getOptionsJson() on null in /chroot/home/a06150d0/magento_root/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml:48
Stack trace:

0 /chroot/home/a06150d0/magento_root/vendor/magento/framework/View/TemplateEngine/Php.php(59): include()

1 /chroot/home/a06150d0/magento_root/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Gallery\Interceptor), '/chroot/home/a0...', Array)

2 /chroot/home/a06150d0/magento_root/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array)

3 /chroot/home/a06150d0/magento_root/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Catalog\Block\Product\View\Gallery\Interceptor), '/chroot/home/a0...', Array)

4 /c in /chroot/home/a06150d0/magento_root/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml on line 48

Format is not valid

Most helpful comment

If you've instantiated the Magento\Catalog\Block\Product\View\Gallery block in your custom theme in some xml file, make sure you add that new gallery_options argument.
See here for how it was changed in 2.3.2: https://github.com/magento/magento2/pull/18440/files#diff-85a7317671ca24ca85af5cb5808b676e (app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml file)

Not sure if this is helpful here, but I just saw that change by accident and I think it is related.

All 17 comments

Hi @SamB-GB. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@SamB-GB do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

I have the same issue:

Basically the code for some reason in the product/view/gallery.phtml expects $block->getGalleryOptions() to always be an object - in this instance it returns null and the result call of getOptionsJson() is causing an exception which kills the script from continuing hence why just the image appears (thou all the header is included if you view source) is returned.

<script type="text/x-magento-init"> { "[data-gallery-role=gallery-placeholder]": { "mage/gallery/gallery": { "mixins":["magnifier/magnify"], "magnifierOpts": <?= /* @escapeNotVerified */ $block->getMagnifier() ?>, "data": <?= /* @escapeNotVerified */ $block->getGalleryImagesJson() ?>, "options": <?= /* @noEscape */ $block->getGalleryOptions()->getOptionsJson() ?>, "fullscreen": <?= /* @noEscape */ $block->getGalleryOptions()->getFSOptionsJson() ?>, "breakpoints": <?= /* @escapeNotVerified */ $block->getBreakpoints() ?> } } } </script>

I'm running Magento 2.3.2 on PHP 7.1.30 on Cpanel CENTOS 6.10 v78.0.23.

I don't have a vanilla install to try it on but if I remove that call and leave the options blank - the page loads correctly.

My product only has a single image - adding more images does not cause the issue to go away so it is not dependent upon how many images you have on the product.

A temporary workaround is to override module-catalog/view/frontend/templates/product/view/gallery.phtml file on your theme from Magento 2.3.1. Works for me.

Thing is it was working fine in 2.3.1 with no changes required this end.

Same issue here...
Uncaught Error: Call to a member function getOptionsJson() on null in /app/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml:48
Stack trace:

0 /app/vendor/magento/framework/View/TemplateEngine/Php.php(59): include()

1 /app/vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Catalog\Block\Product\View\Gallery\Interceptor), '/app/vendor/mag...', Array)

2 /app/vendor/magento/framework/View/Element/Template.php(301): Magento\Framework\View\Element\Template->fetchView('/app/vendor/mag...')

3 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1094): Magento\Framework\View\Element\Template->_toHtml()

4 /app/vendor/magento/framework/View/Element/AbstractBlock.php(1098): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element{closure}()

5 /app/vendor/magento/framework/View/Element/AbstractBlock.php(671): Magento\Framework\View\Element\AbstractBlock->_loadCache()

6 /app/vendor/mage in /app/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml on line 48

On Magento Enterprise Cloud Edition.

Getting the same error. Help Needed ASAP.

To solve this you can override Magento\Catalog\Block\Product\View\Gallery and add a new function getGalleryOptions(). This function should return an instance of Magento\Catalog\Block\Product\View\GalleryOptions, the instance should be injected to the overridden class file.

If you've instantiated the Magento\Catalog\Block\Product\View\Gallery block in your custom theme in some xml file, make sure you add that new gallery_options argument.
See here for how it was changed in 2.3.2: https://github.com/magento/magento2/pull/18440/files#diff-85a7317671ca24ca85af5cb5808b676e (app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml file)

Not sure if this is helpful here, but I just saw that change by accident and I think it is related.

Yes, this is a change I made in one of my PR's. The key is to make sure that the argument gallery_options is injected as an argument to the Gallery Block class in the layout xml. Its not the way I originally wanted to implement it, I wanted to add the getOptionsJson() functions directly to the Magento\Catalog\Block\Product\View\Gallery class, but was blocked from doing so due to backwards compatability rules.

What I don't understand is why some of you have the new Magento\Catalog\Block\Product\View\Gallery class with the $block->getGalleryOptions()->getOptionsJson() call, but don't have the associated change in catalog_product_view.xml. Is it because you are inheriting from, or instantiating Magento\Catalog\Block\Product\View\Gallery in your own class/theme, and haven't injected gallery_options at your layout xml/class level.

With hindsight, it would have been prudent to add a comment block to the top of Magento\Catalog\Block\Product\View\Gallery stating that you must inject gallery_options as argument, otherwise, how would you know? Perhaps this bug could morph into a documentation update for the Gallery class.

I didn't get how should I override the file module-catalog/view/frontend/templates/product/view/gallery.phtml. Could some of you guys help me?

@alexjuniodev Don't do that.

You need to locate in whichever of your third party modules is instantiating an instance of the "Magento\Catalog\Block\Product\View\Gallery" class in its layout xml files and ensure it is injecting the argument "gallery_options" to the block as per the below code.

https://github.com/gwharton/magento2/blob/e29fa3d9b150d81da1caa3484d90ecc3d2156770/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml#L124-L128

Or contact your theme/module providers and get them to update their theme/module to the latest magento version.

The above referenced PR's could also be used as a workaround/alternative solution, but it is unclear at the moment if the above PR's will be accepted into Magento or not. However they would give you a working system without delving into your module/themes code.

Had the same problem today after update from 2.3.1 to 2.3.2, https://github.com/magento/magento2/issues/23432#issuecomment-511916538 solved my issue. Thanks!

I had the same thing in Magento 2.2.9, just find where you are using Magento\Catalog\Block\Product\View\Gallery in your custom theme and update it like this:

                <block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="product/view/gallery.phtml">
                    <arguments>
                        <argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument>
                    </arguments>
                </block>

So add gallery_options as an argument. Thanks @gwharton!

That worked! Many thanks!

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @SamB-GB
I am closing this issue because it is not relevant.
Thanks for your report!

This is quite disgraceful. While we might expect breaking changes like this in the first major release (i.e. 2.3.0), this sort of thing should not be introduced in minor releases. I've followed the other discussions and think you guys need to get some real-world experience and put backward compatibility at the forefront of your decision processes.

It's not theme developers or extension developers that are affected by this kind of ill-thought action, but store owners. And yes, theme and extension developers and store support are having a nightmare trying to keep up with ill-considered actions the core team keeps on taking.

Please will you stop and think about who uses Magento - do not introduce hidden, breaking changes like this in minor releases.

Was this page helpful?
0 / 5 - 0 ratings