Developer forum

Forum » Development » Get countries from ShippingMethod

Get countries from ShippingMethod

Marie Louise Veigert
Reply

Hi,

We would like to get the list of countries, which are selected in the ShippingMethod.

We need it for a dropdown in checkout.

DW version: 9.3.8

I have looked at the templatetags and in the API, but havn't found something usefull.
Does anyone know how to get the selected countries? Or know if it's possible.

BR Marie Louise


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Marie,

you can try to use that code(methodId - needs to be your shipping method id):

API for 9.4:
Dim selectedCountries As New Ecommerce.International.CountryCollection()

            For Each country As Ecommerce.International.Country In Ecommerce.Services.Countries.GetCountries()
                If Ecommerce.International.CountryRelation.GetCoutryRelations(country.Code2, country.RegionCode, methodId, Ecommerce.Orders.Fee.MethodTypeShippment).Any() Then
                    selectedCountries.Add(country)
                End If
            Next

API for 9.3:
Dim selectedCountries As New Ecommerce.International.CountryTextCollection()

            For Each dwCountryText As Ecommerce.International.CountryText In Ecommerce.International.CountryText.GetCoutryTexts
                If dwCountryText.CountryRelations(methodId, Ecommerce.Orders.Fee.MethodTypeShippment).Any() Then
                    selectedCountries.Add(dwCountryText)
                End If
            Next

Regards, Dmitrij

 

You must be logged in to post in the forum