Config.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\InstantPurchase\Model;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Store\Model\ScopeInterface;
  9. use Magento\Store\Model\StoreManagerInterface;
  10. /**
  11. * Instant purchase configuration.
  12. */
  13. class Config
  14. {
  15. const ACTIVE = 'sales/instant_purchase/active';
  16. const BUTTON_TEXT = 'sales/instant_purchase/button_text';
  17. /**
  18. * @var ScopeConfigInterface
  19. */
  20. private $scopeConfig;
  21. /**
  22. * Data constructor.
  23. * @param ScopeConfigInterface $scopeConfig
  24. */
  25. public function __construct(
  26. ScopeConfigInterface $scopeConfig
  27. ) {
  28. $this->scopeConfig = $scopeConfig;
  29. }
  30. /**
  31. * Defines is feature enabled.
  32. *
  33. * @param int $storeId
  34. * @return bool
  35. */
  36. public function isModuleEnabled(int $storeId): bool
  37. {
  38. return $this->isSetFlag(self::ACTIVE, $storeId);
  39. }
  40. /**
  41. * Defines instant purchase trigger button title on product page.
  42. *
  43. * @param int $storeId
  44. * @return string
  45. */
  46. public function getButtonText(int $storeId): string
  47. {
  48. return $this->getValue(self::BUTTON_TEXT, $storeId);
  49. }
  50. /**
  51. * Fetches value from generic config.
  52. *
  53. * @param string $path
  54. * @param int $storeId
  55. * @return mixed
  56. */
  57. private function getValue(string $path, int $storeId)
  58. {
  59. return $this->scopeConfig->getValue(
  60. $path,
  61. ScopeInterface::SCOPE_STORE,
  62. $storeId
  63. );
  64. }
  65. /**
  66. * Fetches switcher value from generic config.
  67. *
  68. * @param string $path
  69. * @param int $storeId
  70. * @return bool
  71. */
  72. private function isSetFlag(string $path, int $storeId): bool
  73. {
  74. return $this->scopeConfig->isSetFlag(
  75. $path,
  76. ScopeInterface::SCOPE_STORE,
  77. $storeId
  78. );
  79. }
  80. }