Products that cover the topic Magento 2 Tax/VAT Switcher

Hole punching Hyvä ViewModel category cache

 

We've been stumbled upon a cache issue we recently discovered in Hyva themes. All of a sudden our Tax Switcher for Magento 2 stopped working on few setups, it seems it didn't change price display in category pages and product listings.

After a lot of debugging, we found that this is related to how Hyvä product list ViewModel generates item cache. By examinging the ViewModel located here:

{ } ViewModel vendor\hyva-themes\magento2-theme-module\src\ViewModel\ProductListItem.php

It seems that the getItemCacheKeyInfo() method does not include any values that could be dynamic per customer. It is build by using multiple criterias but it does not include the selected tax display settings.

{ } php public  function  getItemCacheKeyInfo (         Product  $product,         AbstractBlock  $block,         string  $viewMode,         string  $templateType )   :  array   {         return           [                 $product->getId(),                 $viewMode,                 $templateType,                 $block->getTemplate(),                 $product->getStoreId(),                 $this->getCurrencyCode(),                 (int)  $block->getData('hideDetails'),                 (int)  $block->getData('hide_rating_summary'),                 $this->isCategoryInProductUrl()  ?  $this->currentCategory->get()->getId()  :  '0',                 (int)  $this->customerSession->getCustomerGroupId(),                 (string)  $block->getData('image_display_area'),                 json_encode($product->getData('image_custom_attributes')  ??  []),         ]; }

This caused category pages to get cached and to not change price display depending on selected tax display by the customer. This issue could affect ANY third party module that is trying to generate dynamic cache key depending on additional criteria.

A fix for this may include direct modification of this method or an after plugin.

Extensions for Magento

Anowave is an extension developer for Magento 1.x and Magento 2.x platforms. We provide a wide range of premium extensions for our in-house and public clients. The extensions we offer extend the capabilities of Magento and provide bespoke functionality. They also fill some gaps in the functionality provided by the base platform and help customers choose Magento as their preferred eCommerce platform.

The extensions we offer are part of our full-range Magento service, which also includes a Premium Helpdesk where customers can speak with actual software engineers and have their issues resolved without hassle. Premium-labeled modules also include free installation, configuration, testing, etc.