storeManager = $storeManager; $this->urlBuilder = $urlBuilder; $this->taxConfig = $taxConfig; } /** * {@inheritdoc} * @codeCoverageIgnore */ public function getIdentity() { return 'TAX_NOTIFICATION_APPLY_DISCOUNT'; } /** * {@inheritdoc} */ public function isDisplayed() { if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) { return true; } return false; } /** * {@inheritdoc} */ public function getText() { $messageDetails = ''; if ($this->isDisplayed()) { $messageDetails .= ''; $messageDetails .= __('To apply the discount on prices including tax and apply the tax after discount,' . ' set Catalog Prices to “Including Tax”. '); $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' => 'apply_discount']) ); $messageDetails .= "
"; } return $messageDetails; } /** * {@inheritdoc} * @codeCoverageIgnore */ public function getSeverity() { return self::SEVERITY_CRITICAL; } /** * Return list of store names which have invalid settings. * * @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; } /** * Check if settings are valid. * * @param null|int|bool|string|\Magento\Store\Model\Store $store $store * @return bool false if settings are incorrect */ private function checkSettings($store = null) { return $this->taxConfig->priceIncludesTax($store) || !$this->taxConfig->applyTaxAfterDiscount($store) || !$this->taxConfig->discountTax($store); } }