* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://www.temando.com/ */ class CollectionPointConfigProvider implements ConfigProviderInterface { /** * @var ModuleConfigInterface */ private $moduleConfig; /** * @var CollectionFactory */ private $countryCollectionFactory; /** * @var StoreManagerInterface */ private $storeManager; /** * CollectionPointConfigProvider constructor. * @param ModuleConfigInterface $moduleConfig * @param CollectionFactory $countryCollectionFactory * @param StoreManagerInterface $storeManager */ public function __construct( ModuleConfigInterface $moduleConfig, CollectionFactory $countryCollectionFactory, StoreManagerInterface $storeManager ) { $this->moduleConfig = $moduleConfig; $this->countryCollectionFactory = $countryCollectionFactory; $this->storeManager = $storeManager; } /** * Obtain country data for display in checkout, shipping method step. * * @return string[] */ public function getConfig() { try { $storeId = $this->storeManager->getStore()->getId(); } catch (NoSuchEntityException $exception) { $storeId = null; } if (!$this->moduleConfig->isEnabled($storeId) || !$this->moduleConfig->isCollectionPointsEnabled($storeId)) { return ['countries' => []]; } $countryCodes = $this->moduleConfig->getCollectionPointDeliveryCountries($storeId); $countryCollection = $this->countryCollectionFactory->create(); $countryCollection->addFieldToFilter('country_id', ['in' => explode(',', $countryCodes)]); $countryCollection->loadByStore($storeId); return ['ts-cp-countries' => $countryCollection->toOptionArray(false)]; } }