Skip to content

Store ​

Type
Class
Namespace
craft\commerce\models
Inherits
craft\commerce\models\Store » craft\commerce\base\Model » craft\base\Model » yii\base\Model » yii\base\Component » yii\base\BaseObject
Implements
ArrayAccess, IteratorAggregate, craft\base\ModelInterface, yii\base\Arrayable, yii\base\Configurable, yii\base\StaticInstanceInterface
Uses traits
craft\base\ClonefixTrait, yii\base\ArrayableTrait, yii\base\StaticInstanceTrait
Since
4.0

Store model.

View source

Public Properties ​

PropertyDescription
activeValidatorsyii\validators\Validator – The validators applicable to the current scenario.
administrativeAreasListByCountryCodearray
allowCheckoutWithoutPaymentboolean, string
allowEmptyCartOnCheckoutboolean, string
allowPartialPaymentOnCheckoutboolean, string
attributesarray – Attribute values (name => value).
autoSetCartShippingMethodOptionboolean, string
autoSetNewCartAddressesboolean, string
autoSetPaymentSourceboolean, string
behaviorsyii\base\Behavior – List of behaviors attached to this component.
configarray
countriesstring[] – $countries
countriesListarray
currency\Money\Currency, null
errorsarray – Errors for all attributes or the specified attribute.
firstErrorsarray – The first errors.
freeOrderPaymentStrategystring
freeOrderPaymentStrategyOptions
handlestring, null – Handle
idinteger, null – ID
inventoryLocations\Illuminate\Support\Collection
inventoryLocationsOptionsarray
iteratorArrayIterator – An iterator for traversing the items in the list.
marketAddressConditioncraft\commerce\elements\conditions\addresses\ZoneAddressCondition
minimumTotalPriceStrategystring
minimumTotalPriceStrategyOptions
namestring
orderReferenceFormatstring
primaryboolean – Primary store?
requireBillingAddressAtCheckoutboolean, string
requireShippingAddressAtCheckoutboolean, string
requireShippingMethodSelectionAtCheckoutboolean, string
scenariostring – The scenario that this model is in.
settingscraft\commerce\models\StoreSettings, null
siteNames\Illuminate\Support\Collection<string>
sites\Illuminate\Support\Collection
sortOrderinteger – Sort order
storeSettingsUrlstring
uidstring, null – Store UID
useBillingAddressForTaxboolean, string
validateOrganizationTaxIdAsVatIdboolean, string – Whether to enable validation requiring the organizationTaxId to be a valid VAT ID.
validatorsArrayObject, yii\validators\Validator – All the validators declared in the model.

administrativeAreasListByCountryCode ​

Type
array
Default value
null
Access
Read-only

View source

allowCheckoutWithoutPayment ​

Type
boolean, string
Default value
null

View source

allowEmptyCartOnCheckout ​

Type
boolean, string
Default value
null

View source

allowPartialPaymentOnCheckout ​

Type
boolean, string
Default value
null

View source

autoSetCartShippingMethodOption ​

Type
boolean, string
Default value
null

View source

autoSetNewCartAddresses ​

Type
boolean, string
Default value
null

View source

autoSetPaymentSource ​

Type
boolean, string
Default value
null

View source

config ​

Type
array
Default value
null

View source

countries ​

Type
string[]
Default value
null

$countries

View source

countriesList ​

Type
array
Default value
null
Access
Read-only

View source

currency ​

Type
\Money\Currency, null
Default value
null

View source

freeOrderPaymentStrategy ​

Type
string
Default value
null

View source

freeOrderPaymentStrategyOptions ​

Default value
null
Access
Read-only

View source

handle ​

Type
string, null
Default value
null

Handle

View source

id ​

Type
integer, null
Default value
null

ID

View source

inventoryLocations ​

Type
\Illuminate\Support\Collection
Default value
null
Access
Read-only

View source

inventoryLocationsOptions ​

Type
array
Default value
null
Access
Read-only

View source

marketAddressCondition ​

Type
craft\commerce\elements\conditions\addresses\ZoneAddressCondition
Default value
null
Access
Read-only

View source

minimumTotalPriceStrategy ​

Type
string
Default value
null

View source

minimumTotalPriceStrategyOptions ​

Default value
null
Access
Read-only

View source

name ​

Type
string
Default value
null

View source

orderReferenceFormat ​

Type
string
Default value
null

View source

primary ​

Type
boolean
Default value
false

Primary store?

View source

requireBillingAddressAtCheckout ​

Type
boolean, string
Default value
null

View source

requireShippingAddressAtCheckout ​

Type
boolean, string
Default value
null

View source

requireShippingMethodSelectionAtCheckout ​

Type
boolean, string
Default value
null

View source

settings ​

Type
craft\commerce\models\StoreSettings, null
Default value
null

View source

siteNames ​

Type
\Illuminate\Support\Collection<string>
Default value
null
Access
Read-only

View source

sites ​

Type
\Illuminate\Support\Collection
Default value
null
Access
Read-only

View source

sortOrder ​

Type
integer
Default value
99

Sort order

View source

storeSettingsUrl ​

Type
string
Default value
null
Access
Read-only

View source

uid ​

Type
string, null
Default value
null

Store UID

View source

useBillingAddressForTax ​

Type
boolean, string
Default value
null

View source

validateOrganizationTaxIdAsVatId ​

Type
boolean, string
Default value
null

Whether to enable validation requiring the organizationTaxId to be a valid VAT ID.

When set to false, no validation is applied to organizationTaxId.

When set to true, organizationTaxId must contain a valid VAT ID.

TIP

This setting strictly toggles input validation and has no impact on tax configuration or behavior elsewhere in the system.

View source

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()
__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.
activeAttributes()Returns the attribute names that are subject to validation in the current scenario.
addError()Adds a new error to the specified attribute.
addErrors()Adds a list of errors.
addModelErrors()Adds errors from another model, with a given attribute name prefix.
afterValidate()This method is invoked after validation ends.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attributeHints()Returns the attribute hints.
attributeLabels()Returns the attribute labels.
attributes()Returns the list of attribute names.
beforeValidate()This method is invoked before validation starts.
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.
clearErrors()Removes errors for all attributes or a single attribute.
createValidators()Creates validator objects based on the validation rules specified in rules().
datetimeAttributes()Returns the names of any attributes that should hold DateTime values.
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.
extraFields()Returns the list of fields that can be expanded further and returned by toArray().
fields()Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.
formName()Returns the form name that this model class should use.
generateAttributeLabel()Generates a user friendly attribute label based on the give attribute name.
getActiveValidators()Returns the validators applicable to the current scenario.
getAdministrativeAreasListByCountryCode()
getAllowCheckoutWithoutPayment()Whether carts are can be marked as completed without a payment.
getAllowEmptyCartOnCheckout()Whether carts are allowed to be empty on checkout.
getAllowPartialPaymentOnCheckout()Whether partial payment can be made from the front end when the gateway allows them.
getAttributeHint()Returns the text hint for the specified attribute.
getAttributeLabel()Returns the text label for the specified attribute.
getAttributes()Returns attribute values.
getAutoSetCartShippingMethodOption()Whether the first available shipping method option should be set automatically on carts.
getAutoSetNewCartAddresses()Whether the user’s primary shipping and billing addresses should be set automatically on new carts.
getAutoSetPaymentSource()Whether the user’s primary payment source should be set automatically on new carts.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getConfig()Returns the project config data for this store.
getCountries()
getCountriesList()
getCurrency()
getErrorSummary()Returns the errors for all attributes as a one-dimensional array.
getErrors()Returns the errors for all attributes or a single attribute.
getFirstError()Returns the first error of the specified attribute.
getFirstErrors()Returns the first error of every attribute in the model.
getFreeOrderPaymentStrategy()How Commerce should handle free orders.
getFreeOrderPaymentStrategyOptions()Returns a key-value array of freeOrderPaymentStrategy options and labels.
getInventoryLocations()Returns the inventory locations related to this store.
getInventoryLocationsOptions()
getIterator()Returns an iterator for traversing the attributes in the model.
getMarketAddressCondition()
getMinimumTotalPriceStrategy()How Commerce should handle minimum total price for an order.
getMinimumTotalPriceStrategyOptions()Returns a key-value array of minimumTotalPriceStrategy options and labels.
getName()Returns the store’s name.
getOrderReferenceFormat()Human-friendly reference number format for orders. Result must be unique.
getRequireBillingAddressAtCheckout()Whether a billing address is required before making payment on an order.
getRequireShippingAddressAtCheckout()
getRequireShippingMethodSelectionAtCheckout()Whether shipping method selection is required before making payment on an order.
getScenario()Returns the scenario that this model is used in.
getSettings()
getSiteNames()Returns the names of the sites related to this store
getSites()Returns the sites that are related to this store.
getStoreSettingsUrl()Gets the CP url to these stores settings
getUseBillingAddressForTax()Whether taxes should be calculated based on the billing address instead of the shipping address.
getValidateOrganizationTaxIdAsVatId()
getValidators()Returns all the validators declared in rules().
hasErrors()Returns a value indicating whether there is any validation error.
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.
instance()Returns static class instance, which can be used to obtain meta information.
isAttributeActive()Returns a value indicating whether the attribute is active in the current scenario.
isAttributeRequired()Returns a value indicating whether the attribute is required.
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.
load()Populates the model with input data.
loadMultiple()Populates a set of models with the data from end user.
off()Detaches an existing event handler from this component.
offsetExists()Returns whether there is an element at the specified offset.
offsetGet()Returns the element at the specified offset.
offsetSet()Sets the element at the specified offset.
offsetUnset()Sets the element value at the specified offset to null.
on()Attaches an event handler to an event.
onUnsafeAttribute()This method is invoked when an unsafe attribute is being massively assigned.
rules()Returns the validation rules for attributes.
safeAttributes()Returns the attribute names that are safe to be massively assigned in the current scenario.
scenarios()Returns a list of scenarios and the corresponding active attributes.
setAllowCheckoutWithoutPayment()
setAllowEmptyCartOnCheckout()
setAllowPartialPaymentOnCheckout()
setAttributes()Sets the attribute values in a massive way.
setAutoSetCartShippingMethodOption()
setAutoSetNewCartAddresses()
setAutoSetPaymentSource()
setCountries()
setCurrency()
setFreeOrderPaymentStrategy()
setMinimumTotalPriceStrategy()
setName()Sets the store’s name.
setOrderReferenceFormat()
setRequireBillingAddressAtCheckout()
setRequireShippingAddressAtCheckout()
setRequireShippingMethodSelectionAtCheckout()
setScenario()Sets the scenario for the model.
setUseBillingAddressForTax()
setValidateOrganizationTaxIdAsVatId()
toArray()Converts the model into an array.
trigger()Triggers an event.
validate()Performs the data validation.
validateMultiple()Validates multiple models.

attributeLabels() ​

Returns the attribute labels.

Attribute labels are mainly used for display purpose. For example, given an attribute firstName, we can declare a label First Name which is more user-friendly and can be displayed to end users.

By default an attribute label is generated using generateAttributeLabel(). This method allows you to explicitly specify attribute labels.

Note, in order to inherit labels defined in the parent class, a child class needs to merge the parent labels with child labels using functions such as array_merge().

View source

Returns ​

array – Attribute labels (name => label)

attributes() ​

Returns the list of attribute names.

By default, this method returns all public non-static properties of the class. You may override this method to change the default behavior.

View source

Returns ​

string[] – List of attribute names.

getAdministrativeAreasListByCountryCode() ​

DEPRECATED

Deprecated in 5.0.0. Use [[Store::getSettings()->getAdministrativeAreasListByCountryCode()]] instead.

View source

Returns ​

array

Throws ​

getAllowCheckoutWithoutPayment() ​

Whether carts are can be marked as completed without a payment.

View source

Arguments ​

Returns ​

boolean, string

getAllowEmptyCartOnCheckout() ​

Whether carts are allowed to be empty on checkout.

View source

Arguments ​

Returns ​

boolean, string

getAllowPartialPaymentOnCheckout() ​

Whether partial payment can be made from the front end when the gateway allows them.

The false default does not allow partial payments on the front end.

View source

Arguments ​

Returns ​

boolean, string

getAutoSetCartShippingMethodOption() ​

Whether the first available shipping method option should be set automatically on carts.

View source

Arguments ​

Returns ​

boolean, string

getAutoSetNewCartAddresses() ​

Whether the user’s primary shipping and billing addresses should be set automatically on new carts.

View source

Arguments ​

Returns ​

boolean, string

getAutoSetPaymentSource() ​

Whether the user’s primary payment source should be set automatically on new carts.

View source

Arguments ​

Returns ​

boolean, string

getConfig() ​

Returns the project config data for this store.

View source

getCountries() ​

DEPRECATED

Deprecated in 5.0.0. Use [[Store::getSettings()->getCountries()]] instead.

View source

Returns ​

string[] – $countries

getCountriesList() ​

DEPRECATED

Deprecated in 5.0.0. Use [[Store::getSettings()->getCountriesList()]] instead.

View source

Returns ​

array

Throws ​

getCurrency() ​

View source

Returns ​

\Money\Currency, null

getFreeOrderPaymentStrategy() ​

How Commerce should handle free orders.

The default 'complete' setting automatically completes zero-balance orders without forwarding them to the payment gateway.

The 'process' setting forwards zero-balance orders to the payment gateway for processing. This can be useful if the customer’s balance needs to be updated or otherwise adjusted by the payment gateway.

View source

Arguments ​

Returns ​

string

getFreeOrderPaymentStrategyOptions() ​

Returns a key-value array of freeOrderPaymentStrategy options and labels.

View source

getInventoryLocations() ​

Returns the inventory locations related to this store.

View source

Returns ​

\Illuminate\Support\Collection

Throws ​

getInventoryLocationsOptions() ​

View source

Returns ​

array

Throws ​

getMarketAddressCondition() ​

DEPRECATED

Deprecated in 5.0.0. Use [[Store::getSettings()->getMarketAddressCondition()]] instead.

View source

Returns ​

craft\commerce\elements\conditions\addresses\ZoneAddressCondition

getMinimumTotalPriceStrategy() ​

How Commerce should handle minimum total price for an order.

Options:

  • 'default' rounds the sum of the item subtotal and adjustments.
  • 'zero' returns 0 if the result from 'default' would’ve been negative; minimum order total is 0.
  • 'shipping' returns the total shipping cost if the 'default' result would’ve been negative; minimum order total equals shipping amount.

View source

Arguments ​

Returns ​

string

getMinimumTotalPriceStrategyOptions() ​

Returns a key-value array of minimumTotalPriceStrategy options and labels.

View source

getName() ​

Returns the store’s name.

View source

Arguments ​

  • $parse (boolean) – Whether to parse the name for an environment variable

Returns ​

string

getOrderReferenceFormat() ​

Human-friendly reference number format for orders. Result must be unique.

See Order Numbers.

View source

Arguments ​

Returns ​

string

getRequireBillingAddressAtCheckout() ​

Whether a billing address is required before making payment on an order.

View source

Arguments ​

Returns ​

boolean, string

getRequireShippingAddressAtCheckout() ​

View source

Arguments ​

Returns ​

boolean, string

getRequireShippingMethodSelectionAtCheckout() ​

Whether shipping method selection is required before making payment on an order.

View source

Arguments ​

Returns ​

boolean, string

getSettings() ​

View source

Returns ​

craft\commerce\models\StoreSettings

getSiteNames() ​

Returns the names of the sites related to this store

View source

Returns ​

\Illuminate\Support\Collection<string>

Throws ​

getSites() ​

Returns the sites that are related to this store.

View source

Returns ​

\Illuminate\Support\Collection

Throws ​

getStoreSettingsUrl() ​

Gets the CP url to these stores settings

View source

Arguments ​

Returns ​

string

getUseBillingAddressForTax() ​

Whether taxes should be calculated based on the billing address instead of the shipping address.

View source

Arguments ​

Returns ​

boolean, string

getValidateOrganizationTaxIdAsVatId() ​

View source

Arguments ​

Returns ​

boolean, string – Whether to enable validation requiring the organizationTaxId to be a valid VAT ID.

When set to false, no validation is applied to organizationTaxId.

When set to true, organizationTaxId must contain a valid VAT ID.

TIP

This setting strictly toggles input validation and has no impact on tax configuration or behavior elsewhere in the system.

setAllowCheckoutWithoutPayment() ​

View source

Arguments ​

Returns ​

void

setAllowEmptyCartOnCheckout() ​

View source

Arguments ​

Returns ​

void

setAllowPartialPaymentOnCheckout() ​

View source

Arguments ​

Returns ​

void

setAutoSetCartShippingMethodOption() ​

View source

Arguments ​

Returns ​

void

setAutoSetNewCartAddresses() ​

View source

Arguments ​

Returns ​

void

setAutoSetPaymentSource() ​

View source

Arguments ​

Returns ​

void

setCountries() ​

DEPRECATED

Deprecated in 5.0.0. Use [[Store::getSettings()->setCountries()]] instead.

View source

Arguments ​

  • $countries (mixed)

Returns ​

void

Throws ​

setCurrency() ​

View source

Arguments ​

  • $currency (string, \Money\Currency)

Returns ​

void

setFreeOrderPaymentStrategy() ​

View source

Arguments ​

  • $freeOrderPaymentStrategy (string)

Returns ​

void

setMinimumTotalPriceStrategy() ​

View source

Arguments ​

  • $minimumTotalPriceStrategy (string)

Returns ​

void

setName() ​

Sets the store’s name.

View source

Arguments ​

setOrderReferenceFormat() ​

View source

Arguments ​

Returns ​

void

setRequireBillingAddressAtCheckout() ​

View source

Arguments ​

Returns ​

void

setRequireShippingAddressAtCheckout() ​

View source

Arguments ​

Returns ​

void

setRequireShippingMethodSelectionAtCheckout() ​

View source

Arguments ​

Returns ​

void

setUseBillingAddressForTax() ​

View source

Arguments ​

Returns ​

void

setValidateOrganizationTaxIdAsVatId() ​

View source

Arguments ​

Returns ​

void

Protected Methods ​

MethodDescription
defineBehaviors()Returns the behaviors to attach to this class.
defineRules()Returns the validation rules for attributes.
extractFieldsFor()Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id".
extractRootFields()Extracts the root field names from nested fields.
resolveFields()Determines which fields can be returned by toArray().

defineBehaviors() ​

Returns the behaviors to attach to this class.

See behaviors() for details about what should be returned.

Models should override this method instead of behaviors() so EVENT_DEFINE_BEHAVIORS handlers can modify the class-defined behaviors.

View source

Returns ​

array

defineRules() ​

Returns the validation rules for attributes.

See rules() for details about what should be returned.

Models should override this method instead of rules() so EVENT_DEFINE_RULES handlers can modify the class-defined rules.

View source

Returns ​

array

Constants ​

ConstantDescription
FREE_ORDER_PAYMENT_STRATEGY_COMPLETE
FREE_ORDER_PAYMENT_STRATEGY_PROCESS
MINIMUM_TOTAL_PRICE_STRATEGY_DEFAULT
MINIMUM_TOTAL_PRICE_STRATEGY_SHIPPING
MINIMUM_TOTAL_PRICE_STRATEGY_ZERO
SCENARIO_DEFAULTThe name of the default scenario.