4

I have a custom checkout page for samples, Where I want to get list of European countries list in magento 2.

  • Please state more about what you are trying to achieve and what have you tried so far? – Dexter Jan 10 '17 at 7:41
  • Please, accept @GielBerkers answer if it was helpful. – Siarhey Uchukhlebau Apr 27 '17 at 20:02
6

There is an option called 'European Union Countries' (general/countries/eu_countries). You can use this configuration setting to get the list of all these countries. By default, all EU-countries are selected.

Example from within a helper:

$countries = $this
    ->scopeConfig
    ->getValue(
        'general/country/eu_countries'
    );
var_dump($countries);

Outputs:

string(83) "AT,BE,BG,CY,CZ,DK,EE,FI,FR,DE,GR,HR,HU,IE,IT,LV,LT,LU,MT,NL,PL,PT,RO,SK,SI,ES,SE,GB"
  • it is not working – Vinod Kumar Jan 10 '17 at 7:27
  • Please update your question and share with us the code you've tried – Giel Berkers Jan 10 '17 at 7:31
  • My bad, it needed to be country, not countries. – Giel Berkers Jan 10 '17 at 7:34
0

Like above

$countries = $this
->scopeConfig
->getValue(
    'general/country/eu_countries'
);
var_dump($countries);

but remember to create scopeConfig in your constructor:

public function __construct(
    ...
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    ...
) {
    ...
    $this->scopeConfig = $scopeConfig;
    ...
}

then information about EU countries from Stores->Configuration->General->General->Country Options->European Union Countries will be load into $countries variable, so if You don't set this field in admin, no information will be loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.