Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ApplyDiscountOnPrices.php
Go to the documentation of this file.
1 <?php
7 
9 
18 {
22  private $storeManager;
23 
27  private $urlBuilder;
28 
32  private $taxConfig;
33 
39  private $storesWithInvalidSettings;
40 
46  public function __construct(
47  \Magento\Store\Model\StoreManagerInterface $storeManager,
48  \Magento\Framework\UrlInterface $urlBuilder,
49  Config $taxConfig
50  ) {
51  $this->storeManager = $storeManager;
52  $this->urlBuilder = $urlBuilder;
53  $this->taxConfig = $taxConfig;
54  }
55 
60  public function getIdentity()
61  {
62  return 'TAX_NOTIFICATION_APPLY_DISCOUNT';
63  }
64 
68  public function isDisplayed()
69  {
70  if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) {
71  return true;
72  }
73  return false;
74  }
75 
79  public function getText()
80  {
81  $messageDetails = '';
82 
83  if ($this->isDisplayed()) {
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'])
94  );
95  $messageDetails .= "</p>";
96  }
97 
98  return $messageDetails;
99  }
100 
105  public function getSeverity()
106  {
108  }
109 
115  private function getStoresWithWrongSettings()
116  {
117  if (null !== $this->storesWithInvalidSettings) {
118  return $this->storesWithInvalidSettings;
119  }
120  $this->storesWithInvalidSettings = [];
121  $storeCollection = $this->storeManager->getStores(true);
122  foreach ($storeCollection as $store) {
123  if (!$this->checkSettings($store)) {
124  $website = $store->getWebsite();
125  $this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')';
126  }
127  }
128  return $this->storesWithInvalidSettings;
129  }
130 
137  private function checkSettings($store = null)
138  {
139  return $this->taxConfig->priceIncludesTax($store)
140  || !$this->taxConfig->applyTaxAfterDiscount($store)
141  || !$this->taxConfig->discountTax($store);
142  }
143 }
$storeManager
__()
Definition: __.php:13
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, Config $taxConfig)