3

I need to create 2 widgets on the homepage (CMS Home Page -> Main Content Area).

To do that, I created 2 modules (one for each widget) and extended them from Catalog Product List to use my own template (and also to select the products from the admin in a more fancy way).

The problem is that the frontend is displaying the same widget twice (the first one, the other one doesn't appear at all).

Apparently, there is a known issue related to this, but if someone found a solution to this bug and share it, it would be greatly appreciated.

Msquare
9,4627 gold badges30 silver badges71 bronze badges
asked Nov 9, 2016 at 16:16
2
  • What version of magento 2 are you using? Commented Nov 9, 2016 at 16:24
  • @AndréFerraz 2.1.1 Commented Nov 9, 2016 at 17:56

1 Answer 1

1

I found a solution and forgot to post it here, better late than never. The issue is that the widget_id isn't stored within the cache key, so I added the getCacheKeyInfo method to the Block of my Module and set the id for the widget (note self::WIDGET_ID).

/*
 * Set widget id to prevent M2 bug
 * https://github.com/magento/magento2/issues/4389
 */
public function getCacheKeyInfo()
{
 return [
 'CATALOG_PRODUCTS_LIST_WIDGET',
 $this->_storeManager->getStore()->getId(),
 $this->_design->getDesignTheme()->getId(),
 $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP), intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
 $this->getProductsPerPage(),
 self::WIDGET_ID,
 serialize($this->getRequest()->getParams())
 ];
}
answered Apr 15, 2018 at 11:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.