ValidationMessage.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\Quote\Validator\MinimumOrderAmount;
  7. class ValidationMessage
  8. {
  9. /**
  10. * @var \Magento\Store\Model\StoreManagerInterface
  11. */
  12. private $storeManager;
  13. /**
  14. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  15. */
  16. private $scopeConfig;
  17. /**
  18. * @var \Magento\Framework\Locale\CurrencyInterface
  19. * @deprecated 101.0.3 since 101.0.0
  20. */
  21. private $currency;
  22. /**
  23. * @var \Magento\Framework\Pricing\Helper\Data
  24. */
  25. private $priceHelper;
  26. /**
  27. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  28. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  29. * @param \Magento\Framework\Locale\CurrencyInterface $currency
  30. * @param \Magento\Framework\Pricing\Helper\Data $priceHelper
  31. */
  32. public function __construct(
  33. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  34. \Magento\Store\Model\StoreManagerInterface $storeManager,
  35. \Magento\Framework\Locale\CurrencyInterface $currency,
  36. \Magento\Framework\Pricing\Helper\Data $priceHelper = null
  37. ) {
  38. $this->scopeConfig = $scopeConfig;
  39. $this->storeManager = $storeManager;
  40. $this->currency = $currency;
  41. $this->priceHelper = $priceHelper ?: \Magento\Framework\App\ObjectManager::getInstance()
  42. ->get(\Magento\Framework\Pricing\Helper\Data::class);
  43. }
  44. /**
  45. * Get validation message.
  46. *
  47. * @return \Magento\Framework\Phrase
  48. * @throws \Zend_Currency_Exception
  49. */
  50. public function getMessage()
  51. {
  52. $message = $this->scopeConfig->getValue(
  53. 'sales/minimum_order/description',
  54. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  55. );
  56. if (!$message) {
  57. $minimumAmount = $this->priceHelper->currency($this->scopeConfig->getValue(
  58. 'sales/minimum_order/amount',
  59. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  60. ), true, false);
  61. $message = __('Minimum order amount is %1', $minimumAmount);
  62. } else {
  63. //Added in order to address the issue: https://github.com/magento/magento2/issues/8287
  64. $message = __($message);
  65. }
  66. return $message;
  67. }
  68. }