Config.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Model;
  7. use Magento\Store\Model\ScopeInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Store\Model\StoreManagerInterface;
  10. use Magento\Framework\Escaper;
  11. /**
  12. * Class Config
  13. */
  14. class Config
  15. {
  16. /**#@+
  17. * Minimum advertise price constants
  18. */
  19. const XML_PATH_MSRP_ENABLED = 'sales/msrp/enabled';
  20. const XML_PATH_MSRP_DISPLAY_ACTUAL_PRICE_TYPE = 'sales/msrp/display_price_type';
  21. const XML_PATH_MSRP_EXPLANATION_MESSAGE = 'sales/msrp/explanation_message';
  22. const XML_PATH_MSRP_EXPLANATION_MESSAGE_WHATS_THIS = 'sales/msrp/explanation_message_whats_this';
  23. /**#@-*/
  24. /**#@-*/
  25. protected $scopeConfig;
  26. /**
  27. * @var StoreManagerInterface
  28. */
  29. protected $storeManager;
  30. /**
  31. * @var Escaper
  32. */
  33. protected $escaper;
  34. /**
  35. * @var int
  36. */
  37. protected $storeId;
  38. /**
  39. * Config constructor.
  40. *
  41. * @param ScopeConfigInterface $scopeConfig
  42. * @param StoreManagerInterface $storeManager
  43. * @param Escaper $escaper
  44. */
  45. public function __construct(
  46. ScopeConfigInterface $scopeConfig,
  47. StoreManagerInterface $storeManager,
  48. Escaper $escaper
  49. ) {
  50. $this->scopeConfig = $scopeConfig;
  51. $this->storeManager = $storeManager;
  52. $this->escaper = $escaper;
  53. }
  54. /**
  55. * Set a specified store ID value
  56. *
  57. * @param int $store
  58. * @return $this
  59. */
  60. public function setStoreId($store)
  61. {
  62. $this->storeId = $store;
  63. return $this;
  64. }
  65. /**
  66. * Check if Minimum Advertised Price is enabled
  67. *
  68. * @return bool
  69. * @api
  70. */
  71. public function isEnabled()
  72. {
  73. return $this->scopeConfig->isSetFlag(
  74. self::XML_PATH_MSRP_ENABLED,
  75. ScopeInterface::SCOPE_STORE,
  76. $this->storeId
  77. );
  78. }
  79. /**
  80. * Return Msrp display actual type
  81. *
  82. * @return null|string
  83. */
  84. public function getDisplayActualPriceType()
  85. {
  86. return $this->scopeConfig->getValue(
  87. self::XML_PATH_MSRP_DISPLAY_ACTUAL_PRICE_TYPE,
  88. ScopeInterface::SCOPE_STORE,
  89. $this->storeId
  90. );
  91. }
  92. /**
  93. * Return Msrp explanation message
  94. *
  95. * @return string
  96. */
  97. public function getExplanationMessage()
  98. {
  99. return $this->escaper->escapeHtml(
  100. $this->scopeConfig->getValue(
  101. self::XML_PATH_MSRP_EXPLANATION_MESSAGE,
  102. ScopeInterface::SCOPE_STORE,
  103. $this->storeId
  104. ),
  105. ['b', 'br', 'strong', 'i', 'u', 'p', 'span']
  106. );
  107. }
  108. /**
  109. * Return Msrp explanation message for "Whats This" window
  110. *
  111. * @return string
  112. */
  113. public function getExplanationMessageWhatsThis()
  114. {
  115. return $this->escaper->escapeHtml(
  116. $this->scopeConfig->getValue(
  117. self::XML_PATH_MSRP_EXPLANATION_MESSAGE_WHATS_THIS,
  118. ScopeInterface::SCOPE_STORE,
  119. $this->storeId
  120. ),
  121. ['b', 'br', 'strong', 'i', 'u', 'p', 'span']
  122. );
  123. }
  124. }