22 private $storeManager;
39 private $storesWithInvalidSettings;
48 \
Magento\Framework\UrlInterface $urlBuilder,
52 $this->urlBuilder = $urlBuilder;
53 $this->taxConfig = $taxConfig;
62 return 'TAX_NOTIFICATION_APPLY_DISCOUNT';
70 if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) {
84 $messageDetails .=
'<strong>';
85 $messageDetails .=
__(
'To apply the discount on prices including tax and apply the tax after discount,' 86 .
' set Catalog Prices to “Including Tax”. ');
87 $messageDetails .=
'</strong><p>';
88 $messageDetails .=
__(
'Store(s) affected: ');
89 $messageDetails .= implode(
', ', $this->getStoresWithWrongSettings());
90 $messageDetails .=
'</p><p>';
91 $messageDetails .=
__(
92 'Click on the link to <a href="%1">ignore this notification</a>',
93 $this->urlBuilder->getUrl(
'tax/tax/ignoreTaxNotification', [
'section' =>
'apply_discount'])
95 $messageDetails .=
"</p>";
98 return $messageDetails;
115 private function getStoresWithWrongSettings()
117 if (
null !== $this->storesWithInvalidSettings) {
118 return $this->storesWithInvalidSettings;
120 $this->storesWithInvalidSettings = [];
121 $storeCollection = $this->storeManager->getStores(
true);
122 foreach ($storeCollection as
$store) {
123 if (!$this->checkSettings(
$store)) {
125 $this->storesWithInvalidSettings[] =
$website->getName() .
' (' .
$store->getName() .
')';
128 return $this->storesWithInvalidSettings;
137 private function checkSettings(
$store =
null)
139 return $this->taxConfig->priceIncludesTax(
$store)
140 || !$this->taxConfig->applyTaxAfterDiscount(
$store)
141 || !$this->taxConfig->discountTax(
$store);
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, Config $taxConfig)