Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DiscountErrors.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  private $storeManager;
19 
23  private $urlBuilder;
24 
28  private $taxConfig;
29 
35  private $storesWithInvalidSettings;
36 
44  public function __construct(
45  \Magento\Store\Model\StoreManagerInterface $storeManager,
46  \Magento\Framework\UrlInterface $urlBuilder,
47  \Magento\Tax\Model\Config $taxConfig
48  ) {
49  $this->storeManager = $storeManager;
50  $this->urlBuilder = $urlBuilder;
51  $this->taxConfig = $taxConfig;
52  }
53 
58  public function getIdentity()
59  {
60  return 'TAX_NOTIFICATION_DISCOUNT_ERRORS';
61  }
62 
66  public function isDisplayed()
67  {
68  if (!$this->taxConfig->isWrongDiscountSettingsIgnored() && $this->getStoresWithWrongSettings()) {
69  return true;
70  }
71  return false;
72  }
73 
77  public function getText()
78  {
79  $messageDetails = '';
80 
81  if (!empty($this->getStoresWithWrongSettings()) && !$this->taxConfig->isWrongDiscountSettingsIgnored()) {
82  $messageDetails .= '<strong>';
83  $messageDetails .= __('With customer tax applied “Before Discount”,'
84  . ' the final discount calculation may not match customers’ expectations. ');
85  $messageDetails .= '</strong><p>';
86  $messageDetails .= __('Store(s) affected: ');
87  $messageDetails .= implode(', ', $this->getStoresWithWrongSettings());
88  $messageDetails .= '</p><p>';
89  $messageDetails .= __(
90  'Click on the link to <a href="%1">ignore this notification</a>',
91  $this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'discount'])
92  );
93  $messageDetails .= "</p>";
94  }
95 
96  return $messageDetails;
97  }
98 
103  public function getSeverity()
104  {
106  }
107 
118  private function checkSettings($store = null)
119  {
120  return $this->taxConfig->applyTaxAfterDiscount($store);
121  }
122 
129  private function getStoresWithWrongSettings()
130  {
131  if (null !== $this->storesWithInvalidSettings) {
132  return $this->storesWithInvalidSettings;
133  }
134  $this->storesWithInvalidSettings = [];
135  $storeCollection = $this->storeManager->getStores(true);
136  foreach ($storeCollection as $store) {
137  if (!$this->checkSettings($store)) {
138  $website = $store->getWebsite();
139  $this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')';
140  }
141  }
142  return $this->storesWithInvalidSettings;
143  }
144 }
$storeManager
__()
Definition: __.php:13
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Tax\Model\Config $taxConfig)