MerchantCountry.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\System\Config\Source;
  7. /**
  8. * Source model for merchant countries supported by PayPal
  9. */
  10. class MerchantCountry implements \Magento\Framework\Option\ArrayInterface
  11. {
  12. /**
  13. * @var \Magento\Paypal\Model\ConfigFactory
  14. */
  15. protected $_configFactory;
  16. /**
  17. * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
  18. */
  19. protected $_countryCollectionFactory;
  20. /**
  21. * @param \Magento\Paypal\Model\ConfigFactory $configFactory
  22. * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory
  23. */
  24. public function __construct(
  25. \Magento\Paypal\Model\ConfigFactory $configFactory,
  26. \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory
  27. ) {
  28. $this->_configFactory = $configFactory;
  29. $this->_countryCollectionFactory = $countryCollectionFactory;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function toOptionArray($isMultiselect = false)
  35. {
  36. $supported = $this->_configFactory->create()->getSupportedMerchantCountryCodes();
  37. $options = $this->_countryCollectionFactory->create()->addCountryCodeFilter(
  38. $supported,
  39. 'iso2'
  40. )->loadData()->toOptionArray(
  41. $isMultiselect ? false : __('--Please Select--')
  42. );
  43. return $options;
  44. }
  45. }