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

PropertyDescription
$allCountriescraft\commerce\models\Country[] – An array of all countries.
$allCountriesAsListarray
$allCountriesListDataarray
$behaviorsyii\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

Signature

public craft\commerce\models\Country[] getAllCountries ( )

$allCountriesAsList

Type
array
Access
Read-only

View source

Signature

public array getAllCountriesAsList ( )

$allCountriesListData

Type
array
Access
Read-only

View source

Signature

public array getAllCountriesListData ( )

Public Methods

MethodDescription
__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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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.
getAllCountriesListData()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.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
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

Signature

public boolean deleteCountryById ( \craft\commerce\services\int $id )

getAllCountries()

Returns an array of all countries.

View source

Returns

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

Signature

public craft\commerce\models\Country[] getAllCountries ( )

getAllCountriesAsList()

Returns all country names, indexed by ID.

View source

Returns

array

Signature

public array getAllCountriesAsList ( )

getAllCountriesListData()

DEPRECATED

Deprecated as of 2.0

Returns all country names, indexed by ID.

View source

Returns

array

Signature

public array getAllCountriesListData ( )

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.

Signature

public craft\commerce\models\Country[] getCountriesByShippingZoneId ( \craft\commerce\services\int $shippingZoneId )

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

Signature

public craft\commerce\models\Country[] getCountriesByTaxZoneId ( \craft\commerce\services\int $taxZoneId )

getCountryById()

Returns a country by its ID.

View source

Arguments

Returns

craft\commerce\models\Country, null

Signature

public craft\commerce\models\Country, null getCountryById ( \craft\commerce\services\int $id )

getCountryByIso()

Returns a country by its ISO code.

View source

Arguments

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

Returns

craft\commerce\models\Country, null

Signature

public craft\commerce\models\Country, null getCountryByIso ( \craft\commerce\services\string $iso )

saveCountry()

Saves a country.

View source

Arguments

Returns

boolean – Whether the country was saved successfully.

Throws

Signature

public boolean saveCountry ( craft\commerce\models\Country $country, \craft\commerce\services\bool $runValidation = true )