I've been trying to setup a dynamic tax display in Magento 2.x but without any luck. What I did is to create a plugin for \Magento\Framework\App\Http\Context::getVaryString that adds selected tax display to context and it does it well but when page gets reloaded the previous content is showing, in effect it doesn't refresh the cache although context value is different.

 * Set unique identifier for context
 * @param \Magento\Framework\App\Http\Context $subject
public function beforeGetVaryString(\Magento\Framework\App\Http\Context $subject)
    $subject->setValue(\Tax\Switcher\Helper\Data::CONTEXT_TAX, $this->getCurrentTaxDisplay(), $this->getDefaultTaxDisplay());

Any ideas what could be causing this? Do I have to refreh the cache manually, seems like a bad idea?

Appreciate your help!

  • did you try to clear cache by execute this command : magento php/bin cache:clean ? – mrfizh Oct 17 '18 at 8:46
  • Well, if we have to flush cache at all, it has to be programmatically every time user switches tax display hence why I mentioned that I don't think this is the solution. I wonder if cache can't be invalidated/refresh just by the identifier value. – Angel Oct 17 '18 at 10:35

Your Answer

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

Browse other questions tagged or ask your own question.