1

We are using Magefans Blog Module.

When we are activating the Full Page Cache, it triggers a HTTP 500 on the CMS home page, where we are using a implementation of it.

Modules Block Code that triggers the error:

/**
 * Get Block Identities
 * @return Array
 */
public function getIdentities()
{
    return [\Magento\Cms\Model\Page::CACHE_TAG . '_relatedproducts_'.$this->getPost()->getId()  ];
}

Error:

Fatal error: Uncaught Error: Call to a member function getId() on null in /home/customer00014/public_html/206/app/code/Magefan/Blog/Block/Post/View/RelatedProducts.php:135

Stack trace: #0 /home/customer00014/public_html/206/var/generation/Magefan/Blog/Block/Post/View/RelatedProducts/Interceptor.php(63): Magefan\Blog\Block\Post\View\RelatedProducts->getIdentities() 
#1 /home/customer00014/public_html/206/vendor/magento/module-page-cache/Model/Layout/LayoutPlugin.php(71): Magefan\Blog\Block\Post\View\RelatedProducts\Interceptor->getIdentities() 
#2 /home/customer00014/public_html/206/vendor/magento/framework/Interception/Interceptor.php(150): Magento\PageCache\Model\Layout\LayoutPlugin->afterGetOutput(Object(Magento\Framework\View\Layout\Interceptor), ' <script>\n ...'') 
#3 /home/customer00014/public_html/206/var/generation/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array) #4 /home/customer00014/public_html/206/vendor/magento/framework/View/Result/Page.php(241): Mage in /home/customer00014/public_html/206/app/code/Magefan/Blog/Block/Post/View/RelatedProducts.php on line 135

In the specific .php-file theres a ->getPost()->getID() call which triggers the error.

The question now is:

  • why does the module calls a member function on null, and what does that mean?

  • how can I fix this error? What would be the correct way to "get identitiers"?

  • for what do I need Identities? Is it cache relevant?

0

I fixed my issue by changing the files. I don't like this approach, but customers don't care for good code (or/and are not willing to pay for such :().

I basically just added a random number instead of getting the unique ID.

/**
     * Get Block Identities
     * @return Array
     */
    public function getIdentities()
    {   
        $random = rand(0,99999);
        return [\Magento\Cms\Model\Page::CACHE_TAG . '_relatedproducts_' . $this->getPost() . $random  ];
    }

Now Full Page Cache works. - however, now the blog pages throw errors.

1
  • 1
    Identities is used for the cache identifier, so by using a random number, you have essentially disabled the cache. (Other than when someone happens to get the same previously used random number). Since you mention this is a third party module, Id suggest raising this as a bug with them. – John Cuthbert Aug 23 '16 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.