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

PropertyDescription
$allStatescraft\commerce\models\State[] – An array of all states.
$allStatesAsListarray – 2D array of states indexed by their ids grouped by country ids.
$behaviorsyii\base\Behavior – List of behaviors attached to this component

$allStates

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

An array of all states.

View source

Signature

public craft\commerce\models\State[] getAllStates ( )

$allStatesAsList

Type
array
Access
Read-only

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

View source

Signature

public array getAllStatesAsList ( )

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.
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.
getAllStates()Returns an array of all states.
getAllStatesAsList()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.
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.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
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

Signature

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

getAllStates()

Returns an array of all states.

View source

Returns

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

Signature

public craft\commerce\models\State[] getAllStates ( )

getAllStatesAsList()

Returns all states grouped by countries.

View source

Returns

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

Signature

public array getAllStatesAsList ( )

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

Signature

public craft\commerce\models\State, null getStateByAbbreviation ( \craft\commerce\services\int $countryId, \craft\commerce\services\string $abbreviation )

getStateById()

Returns a state by its ID.

View source

Arguments

Returns

craft\commerce\models\State, null

Signature

public craft\commerce\models\State, null getStateById ( \craft\commerce\services\int $id )

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.

Signature

public craft\commerce\models\State[] getStatesByShippingZoneId ( $shippingZoneId )

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.

Signature

public craft\commerce\models\State[] getStatesByTaxZoneId ( \craft\commerce\services\int $taxZoneId )

saveState()

Saves a state.

View source

Arguments

Returns

boolean – Whether the state was saved successfully.

Throws

Signature

public boolean saveState ( craft\commerce\models\State $model, \craft\commerce\services\bool $runValidation = true )