storeManager = $storeManager; $this->urlBuilder = $urlBuilder; $this->taxConfig = $taxConfig; } /** * {@inheritdoc} * @codeCoverageIgnore */ public function getIdentity() { return 'TAX_NOTIFICATION_ROUNDING_ERRORS'; } /** * {@inheritdoc} */ public function isDisplayed() { if (!$this->taxConfig->isWrongDisplaySettingsIgnored() && $this->getStoresWithWrongSettings()) { return true; } return false; } /** * {@inheritdoc} */ public function getText() { $messageDetails = ''; if (!empty($this->getStoresWithWrongSettings()) && !$this->taxConfig->isWrongDisplaySettingsIgnored()) { $messageDetails .= ''; $messageDetails .= __('Your current tax configuration may result in rounding errors. '); $messageDetails .= '
'; $messageDetails .= __('Store(s) affected: '); $messageDetails .= implode(', ', $this->getStoresWithWrongSettings()); $messageDetails .= '
'; $messageDetails .= __( 'Click on the link to ignore this notification', $this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'price_display']) ); $messageDetails .= "
"; } return $messageDetails; } /** * {@inheritdoc} * @codeCoverageIgnore */ public function getSeverity() { return self::SEVERITY_CRITICAL; } /** * Check if tax calculation type and price display settings are compatible * * Invalid settings if * Tax Calculation Method Based On 'Total' or 'Row' * and at least one Price Display Settings has 'Including and Excluding Tax' value * * @param null|int|bool|string|\Magento\Store\Model\Store $store $store * @return bool */ private function checkSettings($store = null) { if ($this->taxConfig->getAlgorithm($store) == \Magento\Tax\Model\Calculation::CALC_UNIT_BASE) { return true; } return $this->taxConfig->getPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH && $this->taxConfig->getShippingPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH && !$this->taxConfig->displayCartPricesBoth($store) && !$this->taxConfig->displayCartSubtotalBoth($store) && !$this->taxConfig->displayCartShippingBoth($store) && !$this->taxConfig->displaySalesPricesBoth($store) && !$this->taxConfig->displaySalesSubtotalBoth($store) && !$this->taxConfig->displaySalesShippingBoth($store); } /** * Return list of store names which have not compatible tax calculation type and price display settings. * Return true if settings are wrong for default store. * * @return array */ private function getStoresWithWrongSettings() { if (null !== $this->storesWithInvalidSettings) { return $this->storesWithInvalidSettings; } $this->storesWithInvalidSettings = []; $storeCollection = $this->storeManager->getStores(true); foreach ($storeCollection as $store) { if (!$this->checkSettings($store)) { $website = $store->getWebsite(); $this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')'; } } return $this->storesWithInvalidSettings; } }