23 private $countriesFactory;
28 private $allowedCountriesReader;
38 private $storeManager;
62 $this->countriesFactory = $countriesFactory;
63 $this->allowedCountriesReader = $allowedCountriesReader;
65 $this->shareConfig = $shareConfig;
66 parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
72 public function getAllOptions($withEmpty =
true, $defaultValues =
false)
74 if (!$this->options) {
75 $allowedCountries = [];
78 if (!$this->shareConfig->isGlobalScope()) {
79 foreach ($this->storeManager->getWebsites() as
$website) {
80 $countries = $this->allowedCountriesReader
81 ->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE,
$website->getId());
82 $allowedCountries = array_merge($allowedCountries, $countries);
84 foreach ($countries as $countryCode) {
89 $allowedCountries = $this->allowedCountriesReader->getAllowedCountries();
92 $this->options = $this->createCountriesCollection()
93 ->addFieldToFilter(
'country_id', [
'in' => $allowedCountries])
96 foreach ($this->options as &
$option) {
103 return $this->options;
111 private function createCountriesCollection()
113 return $this->countriesFactory->create();
__construct(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countriesFactory, \Magento\Directory\Model\AllowedCountries $allowedCountriesReader, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\Config\Share $shareConfig)
getAllOptions($withEmpty=true, $defaultValues=false)