One thing to take into account when building a Magento based website is performance. The performance is lacking without a cache. You can either do this with the Magento Cache or use something like Varnish. Recently in building a clients site I was having an issue that if you turned on the cache you would end up with a PHP error.
Fatal error: Call to a member function getIdentities() on null in /usr/local/www/magento/vendor/magento/module-catalog/Block/Category/View.php on line 177
This was certainly weird as in the past when building WordPress sites a malfunctioning cache would just leave broken elements on the web-page that the visitors see. I certainly didn’t expect to get a PHP error when doing something like turning a cache on.
After doing a few google searches and a few tests of my own it appeared to be theme related. That is if I switch over to the Blank or Luma built in themes everything worked as planned. Since the error itself didn’t give any hints as to where is was, I had to go to plan B. That is start disabling parts of my theme until I worked out what was breaking it. Since the theme at this time is not too complicated it didn’t take that long to pinpoint it down to the “default.xml” file in the layout section of the them. Disabling the block calls one at a time pointed to the footer causing the error.
One thing that developers tend to do and I’m not exception when trying to get things to work is often forget to removing things that didn’t work but haven’t broken the system.
<block class="Magento\Catalog\Block\Category\View" name="footer.custom" template="Magento_Theme::html/footer.phtml"/>
<block class="Magento\Cms\Block\Block" name="test" before="footer.newsletter">
<arguments>
<argument name="block_id" xsi:type="string">block_footer_custom</argument>
</arguments>
</block>
</referenceContainer>
In this case while the line of code didn’t break the site when the page cache was turned off it certainly did when it was turned on. The weird thing in this case is that it only broke the home page. All the categories worked fine.
Copyright © 2020 | Ben Hutton