AgreementsProvider.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CheckoutAgreements\Model;
  7. use Magento\Store\Model\ScopeInterface;
  8. use Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory as AgreementCollectionFactory;
  9. /**
  10. * Provide Agreements stored in db
  11. */
  12. class AgreementsProvider implements AgreementsProviderInterface
  13. {
  14. /**
  15. * Path to config node
  16. */
  17. const PATH_ENABLED = 'checkout/options/enable_agreements';
  18. /**
  19. * @var AgreementCollectionFactory
  20. */
  21. protected $agreementCollectionFactory;
  22. /**
  23. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  24. */
  25. protected $scopeConfig;
  26. /**
  27. * @var \Magento\Store\Model\StoreManagerInterface
  28. */
  29. protected $storeManager;
  30. /**
  31. * @param AgreementCollectionFactory $agreementCollectionFactory
  32. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  33. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  34. * @codeCoverageIgnore
  35. */
  36. public function __construct(
  37. AgreementCollectionFactory $agreementCollectionFactory,
  38. \Magento\Store\Model\StoreManagerInterface $storeManager,
  39. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  40. ) {
  41. $this->agreementCollectionFactory = $agreementCollectionFactory;
  42. $this->storeManager = $storeManager;
  43. $this->scopeConfig = $scopeConfig;
  44. }
  45. /**
  46. * Get list of required Agreement Ids
  47. *
  48. * @return int[]
  49. */
  50. public function getRequiredAgreementIds()
  51. {
  52. $agreementIds = [];
  53. if ($this->scopeConfig->isSetFlag(self::PATH_ENABLED, ScopeInterface::SCOPE_STORE)) {
  54. $agreementCollection = $this->agreementCollectionFactory->create();
  55. $agreementCollection->addStoreFilter($this->storeManager->getStore()->getId());
  56. $agreementCollection->addFieldToFilter('is_active', 1);
  57. $agreementCollection->addFieldToFilter('mode', AgreementModeOptions::MODE_MANUAL);
  58. $agreementIds = $agreementCollection->getAllIds();
  59. }
  60. return $agreementIds;
  61. }
  62. }