States

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

State service.

View source

# Public Properties

Property Description
allEnabledStates craft\commerce\models\State[] – An array of all enabled states.
allEnabledStatesAsList array
allEnabledStatesAsListGroupedByCountryId array – 2D array of states indexed by their ids grouped by country ids.
allStates craft\commerce\models\State[] – An array of all states.
allStatesAsList array
allStatesAsListGroupedByCountryId array – 2D array of states indexed by their ids grouped by country ids.
behaviors yii\base\Behavior – List of behaviors attached to this component

# allEnabledStates

Type
craft\commerce\models\State[]
Access
Read-only
Since
3.0

An array of all enabled states.

View source

# allEnabledStatesAsList

Type
array
Access
Read-only
Since
3.0

View source

# allEnabledStatesAsListGroupedByCountryId

Type
array
Access
Read-only
Since
3.0

2D array of states indexed by their ids grouped by country ids.

View source

# allStates

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

An array of all states.

View source

# allStatesAsList

Type
array
Access
Read-only

View source

# allStatesAsListGroupedByCountryId

Type
array
Access
Read-only
Since
3.0

2D array of states indexed by their ids grouped by country ids.

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.
deleteStateById() Deletes a state 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.
getAllEnabledStates() Returns an array of all enabled states.
getAllEnabledStatesAsList() Returns all enabled states as array indexed by ID
getAllEnabledStatesAsListGroupedByCountryId() Returns all enabled states grouped by countries.
getAllStates() Returns an array of all states.
getAllStatesAsList() Returns all states indexed by ID
getAllStatesAsListGroupedByCountryId() Returns all states grouped by countries.
getBehavior() Returns the named behavior object.
getBehaviors() Returns all behaviors attached to this component.
getStateByAbbreviation() Returns a state by its abbreviation.
getStateById() Returns a state by its ID.
getStatesByCountryId()
getStatesByShippingZoneId() Returns all states in a shipping zone.
getStatesByTaxZoneId() Returns all states in a tax zone.
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.
reorderStates()
saveState() Saves a state.
trigger() Triggers an event.

# deleteStateById()

Deletes a state by its ID.

View source

Arguments

Returns

boolean – Whether the state was deleted successfully

# getAllEnabledStates()

Since
3.0

Returns an array of all enabled states.

View source

Returns

craft\commerce\models\State[] – An array of all enabled states.

# getAllEnabledStatesAsList()

Since
3.0

Returns all enabled states as array indexed by ID

View source

Returns

array

# getAllEnabledStatesAsListGroupedByCountryId()

Since
3.0

Returns all enabled states grouped by countries.

View source

Returns

array – 2D array of states indexed by their ids grouped by country ids.

# getAllStates()

Returns an array of all states.

View source

Returns

craft\commerce\models\State[] – An array of all states.

# getAllStatesAsList()

Returns all states indexed by ID

View source

Returns

array

# getAllStatesAsListGroupedByCountryId()

Since
3.0

Returns all states grouped by countries.

View source

Returns

array – 2D array of states indexed by their ids grouped by country ids.

# getStateByAbbreviation()

Returns a state by its abbreviation.

View source

Arguments

  • $countryId (integer) – The state's country ID
  • $abbreviation (string) – The state's abbreviation

Returns

craft\commerce\models\State, null

# getStateById()

Returns a state by its ID.

View source

Arguments

Returns

craft\commerce\models\State, null

# getStatesByCountryId()

View source

Arguments

Returns

array

# getStatesByShippingZoneId()

Returns all states in a shipping zone.

View source

Arguments

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

Returns

craft\commerce\models\State[] – Array of states in the matched shipping zone.

# getStatesByTaxZoneId()

Returns all states in a tax zone.

View source

Arguments

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

Returns

craft\commerce\models\State[] – Array of states in the matched tax zone.

# reorderStates()

Since
3.1

View source

Arguments

Returns

boolean

Throws

# saveState()

Saves a state.

View source

Arguments

Returns

boolean – Whether the state was saved successfully.

Throws