customerSession = $customerSession; $this->httpContext = $httpContext; $this->taxCalculation = $calculation; $this->taxHelper = $taxHelper; $this->moduleManager = $moduleManager; $this->cacheConfig = $cacheConfig; } /** * @param \Magento\Framework\App\ActionInterface $subject * @param \Magento\Framework\App\RequestInterface $request * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch( \Magento\Framework\App\ActionInterface $subject, \Magento\Framework\App\RequestInterface $request ) { if (!$this->customerSession->isLoggedIn() || !$this->moduleManager->isEnabled('Magento_PageCache') || !$this->cacheConfig->isEnabled() || !$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) { return; } $defaultBillingAddress = $this->customerSession->getDefaultTaxBillingAddress(); $defaultShippingAddress = $this->customerSession->getDefaultTaxShippingAddress(); $customerTaxClassId = $this->customerSession->getCustomerTaxClassId(); if (!empty($defaultBillingAddress) || !empty($defaultShippingAddress)) { $taxRates = $this->taxCalculation->getTaxRates( $defaultBillingAddress, $defaultShippingAddress, $customerTaxClassId ); $this->httpContext->setValue( 'tax_rates', $taxRates, 0 ); } } }