4

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

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

2 Answers 2

7

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"
3
  • it is not working Commented Jan 10, 2017 at 7:27
  • Please update your question and share with us the code you've tried Commented Jan 10, 2017 at 7:31
  • My bad, it needed to be country, not countries. Commented Jan 10, 2017 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 and acknowledge you have read our privacy policy.

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