62 private $allowedCountriesReader;
72 private $storeManager;
95 \Psr\Log\LoggerInterface
$logger,
97 \
Magento\Framework\Event\ManagerInterface $eventManager,
98 \
Magento\Framework\Locale\ListsInterface $localeLists,
101 \
Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
102 \
Magento\Framework\Locale\ResolverInterface $localeResolver,
110 $this->_scopeConfig = $scopeConfig;
111 $this->_localeLists = $localeLists;
112 $this->_localeResolver = $localeResolver;
113 $this->_countryFactory = $countryFactory;
114 $this->_arrayUtils = $arrayUtils;
136 private function addForegroundCountriesToOptionArray($emptyLabel,
$options)
138 if ($emptyLabel !==
false &&
count($this->_foregroundCountries) !== 0 &&
141 $options[] = [
'value' =>
'',
'label' => $emptyLabel];
163 private function getAllowedCountriesReader()
165 if (!$this->allowedCountriesReader) {
169 return $this->allowedCountriesReader;
180 $allowedCountries = $this->getAllowedCountriesReader()
181 ->getAllowedCountries(ScopeInterface::SCOPE_STORE,
$store);
183 if (!empty($allowedCountries)) {
198 foreach ($this->_items as $country) {
199 if ($country->getCountryId() == $countryId) {
218 if (!empty($countryCode)) {
219 if (is_array($countryCode)) {
220 if (is_array($iso)) {
222 foreach ($iso as $iso_curr) {
223 $whereOr[] .= $this->
_getConditionSql(
"{$iso_curr}_code", [
'in' => $countryCode]);
225 $this->_select->where(
'(' . implode(
') OR (', $whereOr) .
')');
230 if (is_array($iso)) {
232 foreach ($iso as $iso_curr) {
235 $this->_select->where(
'(' . implode(
') OR (', $whereOr) .
')');
252 if (!empty($countryId)) {
253 if (is_array($countryId)) {
273 $name = (string)$this->_localeLists->getCountryTranslation(
$data[
'value']);
278 $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale());
279 foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
280 $name = array_search($foregroundCountry, $sort);
282 $sort = [
$name => $foregroundCountry] + $sort;
284 $isRegionVisible = (bool)$this->helperData->isShowNonRequiredState();
288 $options = $this->addForegroundCountriesToOptionArray($emptyLabel,
$options);
290 if ($this->helperData->isRegionRequired(
$value)) {
291 $option[
'is_region_required'] =
true;
293 $option[
'is_region_visible'] = $isRegionVisible;
295 if ($this->helperData->isZipCodeOptional(
$value)) {
296 $option[
'is_zipcode_optional'] =
true;
301 array_unshift(
$options, [
'value' =>
'',
'label' => $emptyLabel]);
304 $this->addDefaultCountryToOptions(
$options);
315 private function addDefaultCountryToOptions(array &
$options)
317 $defaultCountry = [];
318 foreach ($this->storeManager->getWebsites() as
$website) {
319 $defaultCountryConfig = $this->_scopeConfig->getValue(
320 \
Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY,
321 ScopeInterface::SCOPE_WEBSITES,
324 $defaultCountry[$defaultCountryConfig][] =
$website->getId();
328 if (isset($defaultCountry[
$option[
'value']])) {
342 if (empty($foregroundCountries)) {
345 $this->_foregroundCountries = (array)$foregroundCountries;
355 public function getCountriesWithRequiredStates()
358 foreach ($this->
getItems() as $country) {
360 if ($country->getRegionCollection()->getSize() > 0
363 $countries[$country->getId()] = $country;
addCountryCodeFilter($countryCode, $iso=['iso3', 'iso2'])
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Directory\Model\ResourceModel\CountryFactory $countryFactory, \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\Helper\AbstractHelper $helperData, array $countriesWithNotRequiredStates=[], \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null, \Magento\Store\Model\StoreManagerInterface $storeManager=null)
_toOptionArray($valueField=null, $labelField='name', $additional=[])
setForegroundCountries($foregroundCountries)
toOptionArray($emptyLabel=' ')
addFieldToFilter($attribute, $condition=null)
_getConditionSql($fieldName, $condition)
_init($model, $resourceModel)
addCountryIdFilter($countryId)
$countriesWithNotRequiredStates
if(!isset($_GET['name'])) $name