Countries

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\Countries » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
2.0

Country service.

View source

# Public Properties

Property Description
allCountries craft\commerce\models\Country[] – An array of all countries.
allCountriesAsList array
allEnabledCountries array
allEnabledCountriesAsList array
behaviors yii\base\Behavior – List of behaviors attached to this component

# allCountries

Type
craft\commerce\models\Country[]
Access
Read-only

An array of all countries.

View source

# allCountriesAsList

Type
array
Access
Read-only

View source

# allEnabledCountries

Type
array
Access
Read-only
Since
3.0

View source

# allEnabledCountriesAsList

Type
array
Access
Read-only
Since
3.0

View source

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__clone() This method is called after the object is created by cloning an existing one.
__construct() Constructor.
__get() Returns the value of a component property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets the value of a component property.
__unset() Sets a component property to be null.
attachBehavior() Attaches a behavior to this component.
attachBehaviors() Attaches a list of behaviors to the component.
behaviors() Returns a list of behaviors that this component should behave as.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() Returns a value indicating whether a property can be set.
className() Returns the fully qualified name of this class.
deleteCountryById() Deletes a country by its ID.
detachBehavior() Detaches a behavior from the component.
detachBehaviors() Detaches all behaviors from the component.
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component.
getAllCountries() Returns an array of all countries.
getAllCountriesAsList() Returns all country names, indexed by ID.
getAllEnabledCountries() Returns an array of all enabled countries
getAllEnabledCountriesAsList() Returns all country names, indexed by ID.
getBehavior() Returns the named behavior object.
getBehaviors() Returns all behaviors attached to this component.
getCountriesByShippingZoneId() Returns all countries in a shipping zone, per the shipping zone's ID.
getCountriesByTaxZoneId() Returns all countries in a tax zone, per the tax zone's ID.
getCountryById() Returns a country by its ID.
getCountryByIso() Returns a country by its ISO code.
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event.
hasMethod() Returns a value indicating whether a method is defined.
hasProperty() Returns a value indicating whether a property is defined for this component.
init() Initializes the object.
off() Detaches an existing event handler from this component.
on() Attaches an event handler to an event.
reorderCountries()
saveCountry() Saves a country.
trigger() Triggers an event.

# deleteCountryById()

Deletes a country by its ID.

View source

Arguments

Returns

boolean – Whether the country was deleted successfully

# getAllCountries()

Returns an array of all countries.

View source

Returns

craft\commerce\models\Country[] – An array of all countries.

# getAllCountriesAsList()

Returns all country names, indexed by ID.

View source

Returns

array

# getAllEnabledCountries()

Since
3.0

Returns an array of all enabled countries

View source

Returns

array

# getAllEnabledCountriesAsList()

Since
3.0

Returns all country names, indexed by ID.

View source

Returns

array

# getCountriesByShippingZoneId()

Returns all countries in a shipping zone, per the shipping zone's ID.

View source

Arguments

  • $shippingZoneId (integer) – The shipping zone's ID

Returns

craft\commerce\models\Country[] – An array of countries in the matched shipping zone.

# getCountriesByTaxZoneId()

Returns all countries in a tax zone, per the tax zone's ID.

View source

Arguments

  • $taxZoneId (integer) – The tax zone's ID

Returns

craft\commerce\models\Country[] – An array of countries in the matched tax zone

# getCountryById()

Returns a country by its ID.

View source

Arguments

Returns

craft\commerce\models\Country, null

# getCountryByIso()

Returns a country by its ISO code.

View source

Arguments

  • $iso (string) – The country's ISO code

Returns

craft\commerce\models\Country, null

# reorderCountries()

Since
2.2

View source

Arguments

Returns

boolean

Throws

# saveCountry()

Saves a country.

View source

Arguments

Returns

boolean – Whether the country was saved successfully.

Throws