Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Config.php
Go to the documentation of this file.
1 <?php
12 namespace Magento\Tax\Model;
13 
15 
19 class Config
20 {
21  // tax notifications
22  const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT = 'tax/notification/ignore_discount';
23 
24  const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
25 
26  const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
27 
28  const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
29 
30  // tax classes
31  const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
32 
33  // tax calculation
34  const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
35 
36  const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
37 
38  const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
39 
40  const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
41 
42  const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
43 
44  const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
45 
46  const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
47 
48  const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED = 'tax/calculation/cross_border_trade_enabled';
49 
50  // tax defaults
51  const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
52 
53  const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
54 
55  const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
56 
60  const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
61 
62  const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
63 
67  const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
68 
69  const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
70 
71  const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
72 
74  const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
75 
76  const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
77 
78  const XML_PATH_DISPLAY_CART_FULL_SUMMARY = 'tax/cart_display/full_summary';
79 
80  const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
81 
85  const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
86 
87  const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
88 
89  const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
90 
92  const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
93 
94  const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
95 
96  const XML_PATH_DISPLAY_SALES_FULL_SUMMARY = 'tax/sales_display/full_summary';
97 
98  const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
99 
101 
103 
105 
106  const DISPLAY_TYPE_BOTH = 3;
107 
112 
117 
121  protected $_priceIncludesTax = null;
122 
128  protected $_needUseShippingExcludeTax = false;
129 
133  protected $_shippingPriceIncludeTax = null;
134 
140  protected $_scopeConfig;
141 
145  public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
146  {
147  $this->_scopeConfig = $scopeConfig;
148  }
149 
156  public function priceIncludesTax($store = null)
157  {
158  if (null !== $this->_priceIncludesTax) {
160  }
161  return (bool)$this->_scopeConfig->getValue(
162  self::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
164  $store
165  );
166  }
167 
174  public function setPriceIncludesTax($value)
175  {
176  if (null === $value) {
177  $this->_priceIncludesTax = null;
178  } else {
179  $this->_priceIncludesTax = (bool)$value;
180  }
181  return $this;
182  }
183 
190  public function applyTaxAfterDiscount($store = null)
191  {
192  return (bool)$this->_scopeConfig->getValue(
193  self::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT,
195  $store
196  );
197  }
198 
208  public function getPriceDisplayType($store = null)
209  {
210  return (int)$this->_scopeConfig->getValue(
211  self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE,
213  $store
214  );
215  }
216 
223  public function discountTax($store = null)
224  {
225  return (int)$this->_scopeConfig->getValue(
226  self::CONFIG_XML_PATH_DISCOUNT_TAX,
228  $store
229  ) == 1;
230  }
231 
239  public function getCalculationSequence($store = null)
240  {
241  if ($this->applyTaxAfterDiscount($store)) {
242  if ($this->discountTax($store)) {
244  } else {
246  }
247  } else {
248  if ($this->discountTax($store)) {
250  } else {
252  }
253  }
254  return $seq;
255  }
256 
263  public function setNeedUseShippingExcludeTax($flag)
264  {
265  $this->_needUseShippingExcludeTax = $flag;
266  return $this;
267  }
268 
276  {
278  }
279 
286  public function getAlgorithm($store = null)
287  {
288  return $this->_scopeConfig->getValue(
289  self::XML_PATH_ALGORITHM,
291  $store
292  );
293  }
294 
301  public function getShippingTaxClass($store = null)
302  {
303  return (int)$this->_scopeConfig->getValue(
304  self::CONFIG_XML_PATH_SHIPPING_TAX_CLASS,
306  $store
307  );
308  }
309 
316  public function getShippingPriceDisplayType($store = null)
317  {
318  return (int)$this->_scopeConfig->getValue(
319  self::CONFIG_XML_PATH_DISPLAY_SHIPPING,
321  $store
322  );
323  }
324 
331  public function shippingPriceIncludesTax($store = null)
332  {
333  if ($this->_shippingPriceIncludeTax === null) {
334  $this->_shippingPriceIncludeTax = (bool)$this->_scopeConfig->getValue(
335  self::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX,
337  $store
338  );
339  }
341  }
342 
349  public function setShippingPriceIncludeTax($flag)
350  {
351  $this->_shippingPriceIncludeTax = $flag;
352  return $this;
353  }
354 
359  public function displayCartPricesInclTax($store = null)
360  {
361  return $this->_scopeConfig->getValue(
362  self::XML_PATH_DISPLAY_CART_PRICE,
364  $store
366  }
367 
372  public function displayCartPricesExclTax($store = null)
373  {
374  return $this->_scopeConfig->getValue(
375  self::XML_PATH_DISPLAY_CART_PRICE,
377  $store
379  }
380 
385  public function displayCartPricesBoth($store = null)
386  {
387  return $this->_scopeConfig->getValue(
388  self::XML_PATH_DISPLAY_CART_PRICE,
390  $store
392  }
393 
398  public function displayCartSubtotalInclTax($store = null)
399  {
400  return $this->_scopeConfig->getValue(
401  self::XML_PATH_DISPLAY_CART_SUBTOTAL,
403  $store
405  }
406 
411  public function displayCartSubtotalExclTax($store = null)
412  {
413  return $this->_scopeConfig->getValue(
414  self::XML_PATH_DISPLAY_CART_SUBTOTAL,
416  $store
418  }
419 
424  public function displayCartSubtotalBoth($store = null)
425  {
426  return $this->_scopeConfig->getValue(
427  self::XML_PATH_DISPLAY_CART_SUBTOTAL,
429  $store
431  }
432 
437  public function displayCartShippingInclTax($store = null)
438  {
439  return $this->_scopeConfig->getValue(
440  self::XML_PATH_DISPLAY_CART_SHIPPING,
442  $store
444  }
445 
450  public function displayCartShippingExclTax($store = null)
451  {
452  return $this->_scopeConfig->getValue(
453  self::XML_PATH_DISPLAY_CART_SHIPPING,
455  $store
457  }
458 
463  public function displayCartShippingBoth($store = null)
464  {
465  return $this->_scopeConfig->getValue(
466  self::XML_PATH_DISPLAY_CART_SHIPPING,
468  $store
470  }
471 
477  public function displayCartDiscountInclTax($store = null)
478  {
479  return $this->_scopeConfig->getValue(
480  self::XML_PATH_DISPLAY_CART_DISCOUNT,
482  $store
484  }
485 
491  public function displayCartDiscountExclTax($store = null)
492  {
493  return $this->_scopeConfig->getValue(
494  self::XML_PATH_DISPLAY_CART_DISCOUNT,
496  $store
498  }
499 
505  public function displayCartDiscountBoth($store = null)
506  {
507  return $this->_scopeConfig->getValue(
508  self::XML_PATH_DISPLAY_CART_DISCOUNT,
510  $store
512  }
513 
518  public function displayCartTaxWithGrandTotal($store = null)
519  {
520  return (bool)$this->_scopeConfig->getValue(
521  self::XML_PATH_DISPLAY_CART_GRANDTOTAL,
523  $store
524  );
525  }
526 
531  public function displayCartFullSummary($store = null)
532  {
533  return (bool)$this->_scopeConfig->getValue(
534  self::XML_PATH_DISPLAY_CART_FULL_SUMMARY,
536  $store
537  );
538  }
539 
544  public function displayCartZeroTax($store = null)
545  {
546  return (bool)$this->_scopeConfig->getValue(
547  self::XML_PATH_DISPLAY_CART_ZERO_TAX,
549  $store
550  );
551  }
552 
557  public function displaySalesPricesInclTax($store = null)
558  {
559  return $this->_scopeConfig->getValue(
560  self::XML_PATH_DISPLAY_SALES_PRICE,
562  $store
564  }
565 
570  public function displaySalesPricesExclTax($store = null)
571  {
572  return $this->_scopeConfig->getValue(
573  self::XML_PATH_DISPLAY_SALES_PRICE,
575  $store
577  }
578 
583  public function displaySalesPricesBoth($store = null)
584  {
585  return $this->_scopeConfig->getValue(
586  self::XML_PATH_DISPLAY_SALES_PRICE,
588  $store
590  }
591 
596  public function displaySalesSubtotalInclTax($store = null)
597  {
598  return $this->_scopeConfig->getValue(
599  self::XML_PATH_DISPLAY_SALES_SUBTOTAL,
601  $store
603  }
604 
609  public function displaySalesSubtotalExclTax($store = null)
610  {
611  return $this->_scopeConfig->getValue(
612  self::XML_PATH_DISPLAY_SALES_SUBTOTAL,
614  $store
616  }
617 
622  public function displaySalesSubtotalBoth($store = null)
623  {
624  return $this->_scopeConfig->getValue(
625  self::XML_PATH_DISPLAY_SALES_SUBTOTAL,
627  $store
629  }
630 
635  public function displaySalesShippingInclTax($store = null)
636  {
637  return $this->_scopeConfig->getValue(
638  self::XML_PATH_DISPLAY_SALES_SHIPPING,
640  $store
642  }
643 
648  public function displaySalesShippingExclTax($store = null)
649  {
650  return $this->_scopeConfig->getValue(
651  self::XML_PATH_DISPLAY_SALES_SHIPPING,
653  $store
655  }
656 
661  public function displaySalesShippingBoth($store = null)
662  {
663  return $this->_scopeConfig->getValue(
664  self::XML_PATH_DISPLAY_SALES_SHIPPING,
666  $store
668  }
669 
675  public function displaySalesDiscountInclTax($store = null)
676  {
677  return $this->_scopeConfig->getValue(
678  self::XML_PATH_DISPLAY_SALES_DISCOUNT,
680  $store
682  }
683 
689  public function displaySalesDiscountExclTax($store = null)
690  {
691  return $this->_scopeConfig->getValue(
692  self::XML_PATH_DISPLAY_SALES_DISCOUNT,
694  $store
696  }
697 
703  public function displaySalesDiscountBoth($store = null)
704  {
705  return $this->_scopeConfig->getValue(
706  self::XML_PATH_DISPLAY_SALES_DISCOUNT,
708  $store
710  }
711 
716  public function displaySalesTaxWithGrandTotal($store = null)
717  {
718  return (bool)$this->_scopeConfig->getValue(
719  self::XML_PATH_DISPLAY_SALES_GRANDTOTAL,
721  $store
722  );
723  }
724 
729  public function displaySalesFullSummary($store = null)
730  {
731  return (bool)$this->_scopeConfig->getValue(
732  self::XML_PATH_DISPLAY_SALES_FULL_SUMMARY,
734  $store
735  );
736  }
737 
742  public function displaySalesZeroTax($store = null)
743  {
744  return (bool)$this->_scopeConfig->getValue(
745  self::XML_PATH_DISPLAY_SALES_ZERO_TAX,
747  $store
748  );
749  }
750 
757  public function crossBorderTradeEnabled($store = null)
758  {
759  return (bool)$this->_scopeConfig->getValue(
760  self::CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED,
762  $store
763  );
764  }
765 
777  {
778  return (bool)$this->_scopeConfig->getValue(
779  self::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
781  $store
782  );
783  }
784 
791  public function isWrongDisplaySettingsIgnored($store = null)
792  {
793  return (bool)$this->_scopeConfig->getValue(
794  self::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY,
796  $store
797  );
798  }
799 
806  public function isWrongDiscountSettingsIgnored($store = null)
807  {
808  return (bool)$this->_scopeConfig->getValue(
809  self::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT,
811  $store
812  );
813  }
814 
821  public function getInfoUrl($store = null)
822  {
823  return (string)$this->_scopeConfig->getValue(
824  self::XML_PATH_TAX_NOTIFICATION_INFO_URL,
826  $store
827  );
828  }
829 
838  public function needPriceConversion($store = null)
839  {
840  $res = 0;
841  $priceIncludesTax = $this->priceIncludesTax($store) || $this->getNeedUseShippingExcludeTax();
842  if ($priceIncludesTax) {
843  switch ($this->getPriceDisplayType($store)) {
848  $res = false;
849  break;
850  default:
851  break;
852  }
853  } else {
854  switch ($this->getPriceDisplayType($store)) {
859  $res = false;
860  break;
861  default:
862  break;
863  }
864  }
865 
866  if ($res === false) {
867  $res = $this->displayCartPricesBoth();
868  }
869  return $res;
870  }
871 }
const XML_PATH_DISPLAY_CART_ZERO_TAX
Definition: Config.php:80
const XML_PATH_DISPLAY_CART_FULL_SUMMARY
Definition: Config.php:78
const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT
Definition: Config.php:42
displaySalesDiscountExclTax($store=null)
Definition: Config.php:689
displaySalesSubtotalInclTax($store=null)
Definition: Config.php:596
displaySalesSubtotalExclTax($store=null)
Definition: Config.php:609
displayCartSubtotalBoth($store=null)
Definition: Config.php:424
getShippingTaxClass($store=null)
Definition: Config.php:301
displayCartPricesBoth($store=null)
Definition: Config.php:385
displaySalesPricesInclTax($store=null)
Definition: Config.php:557
const CONFIG_XML_PATH_APPLY_ON
Definition: Config.php:40
shippingPriceIncludesTax($store=null)
Definition: Config.php:331
const CONFIG_XML_PATH_DEFAULT_POSTCODE
Definition: Config.php:55
const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY
Definition: Config.php:24
const XML_PATH_DISPLAY_SALES_GRANDTOTAL
Definition: Config.php:94
displaySalesPricesExclTax($store=null)
Definition: Config.php:570
displayCartShippingBoth($store=null)
Definition: Config.php:463
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
Definition: Config.php:145
const XML_PATH_DISPLAY_CART_DISCOUNT
Definition: Config.php:74
const CONFIG_XML_PATH_DEFAULT_REGION
Definition: Config.php:53
const CONFIG_XML_PATH_DISCOUNT_TAX
Definition: Config.php:44
const XML_PATH_DISPLAY_SALES_DISCOUNT
Definition: Config.php:92
const CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED
Definition: Config.php:48
const XML_PATH_DISPLAY_SALES_ZERO_TAX
Definition: Config.php:98
displayCartShippingExclTax($store=null)
Definition: Config.php:450
displayCartTaxWithGrandTotal($store=null)
Definition: Config.php:518
const XML_PATH_DISPLAY_SALES_FULL_SUMMARY
Definition: Config.php:96
priceIncludesTax($store=null)
Definition: Config.php:156
const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX
Definition: Config.php:36
const DISPLAY_TYPE_EXCLUDING_TAX
Definition: Config.php:102
getShippingPriceDisplayType($store=null)
Definition: Config.php:316
const XML_PATH_DISPLAY_CART_SHIPPING
Definition: Config.php:71
getCalculationSequence($store=null)
Definition: Config.php:239
const DISPLAY_TYPE_INCLUDING_TAX
Definition: Config.php:104
const XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT
Definition: Config.php:22
const CONFIG_XML_PATH_DEFAULT_COUNTRY
Definition: Config.php:51
displaySalesSubtotalBoth($store=null)
Definition: Config.php:622
displaySalesFullSummary($store=null)
Definition: Config.php:729
displayCartDiscountInclTax($store=null)
Definition: Config.php:477
const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT
Definition: Config.php:26
displayCartSubtotalInclTax($store=null)
Definition: Config.php:398
crossBorderTradeEnabled($store=null)
Definition: Config.php:757
$value
Definition: gender.phtml:16
getPriceDisplayType($store=null)
Definition: Config.php:208
getAlgorithm($store=null)
Definition: Config.php:286
setPriceIncludesTax($value)
Definition: Config.php:174
displaySalesShippingExclTax($store=null)
Definition: Config.php:648
const XML_PATH_DISPLAY_SALES_PRICE
Definition: Config.php:85
displaySalesPricesBoth($store=null)
Definition: Config.php:583
displaySalesDiscountInclTax($store=null)
Definition: Config.php:675
setNeedUseShippingExcludeTax($flag)
Definition: Config.php:263
const CONFIG_XML_PATH_SHIPPING_TAX_CLASS
Definition: Config.php:31
const XML_PATH_DISPLAY_CART_PRICE
Definition: Config.php:67
isWrongDiscountSettingsIgnored($store=null)
Definition: Config.php:806
const XML_PATH_DISPLAY_SALES_SUBTOTAL
Definition: Config.php:87
displaySalesShippingInclTax($store=null)
Definition: Config.php:635
displayCartFullSummary($store=null)
Definition: Config.php:531
const CALCULATION_STRING_SEPARATOR
Definition: Config.php:100
displaySalesDiscountBoth($store=null)
Definition: Config.php:703
const XML_PATH_DISPLAY_CART_SUBTOTAL
Definition: Config.php:69
displaySalesShippingBoth($store=null)
Definition: Config.php:661
displayCartDiscountExclTax($store=null)
Definition: Config.php:491
const CONFIG_XML_PATH_PRICE_INCLUDES_TAX
Definition: Config.php:34
const XML_PATH_TAX_NOTIFICATION_INFO_URL
Definition: Config.php:28
needPriceConversion($store=null)
Definition: Config.php:838
const CONFIG_XML_PATH_DISPLAY_SHIPPING
Definition: Config.php:62
displaySalesZeroTax($store=null)
Definition: Config.php:742
getInfoUrl($store=null)
Definition: Config.php:821
const XML_PATH_DISPLAY_SALES_SHIPPING
Definition: Config.php:89
setShippingPriceIncludeTax($flag)
Definition: Config.php:349
const CONFIG_XML_PATH_BASED_ON
Definition: Config.php:38
displayCartSubtotalExclTax($store=null)
Definition: Config.php:411
const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE
Definition: Config.php:60
displaySalesTaxWithGrandTotal($store=null)
Definition: Config.php:716
isWrongDisplaySettingsIgnored($store=null)
Definition: Config.php:791
displayCartDiscountBoth($store=null)
Definition: Config.php:505
displayCartPricesExclTax($store=null)
Definition: Config.php:372
displayCartZeroTax($store=null)
Definition: Config.php:544
applyTaxAfterDiscount($store=null)
Definition: Config.php:190
displayCartPricesInclTax($store=null)
Definition: Config.php:359
isWrongApplyDiscountSettingIgnored($store=null)
Definition: Config.php:776
const XML_PATH_DISPLAY_CART_GRANDTOTAL
Definition: Config.php:76
discountTax($store=null)
Definition: Config.php:223
displayCartShippingInclTax($store=null)
Definition: Config.php:437