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.
Public Properties ​
administrativeAreasListByCountryCode
​
- Type
- array
- Default value
null
- Access
- Read-only
allowCheckoutWithoutPayment
​
allowEmptyCartOnCheckout
​
allowPartialPaymentOnCheckout
​
autoSetCartShippingMethodOption
​
autoSetNewCartAddresses
​
autoSetPaymentSource
​
config
​
- Type
- array
- Default value
null
countries
​
- Type
- string[]
- Default value
null
$countries
countriesList
​
- Type
- array
- Default value
null
- Access
- Read-only
currency
​
- Type
\Money\Currency
, null- Default value
null
freeOrderPaymentStrategy
​
- Type
- string
- Default value
null
freeOrderPaymentStrategyOptions
​
- Default value
null
- Access
- Read-only
handle
​
Handle
id
​
ID
inventoryLocations
​
- Type
\Illuminate\Support\Collection
- Default value
null
- Access
- Read-only
inventoryLocationsOptions
​
- Type
- array
- Default value
null
- Access
- Read-only
marketAddressCondition
​
- Type
- craft\commerce\elements\conditions\addresses\ZoneAddressCondition
- Default value
null
- Access
- Read-only
minimumTotalPriceStrategy
​
- Type
- string
- Default value
null
minimumTotalPriceStrategyOptions
​
- Default value
null
- Access
- Read-only
name
​
- Type
- string
- Default value
null
orderReferenceFormat
​
- Type
- string
- Default value
null
primary
​
- Type
- boolean
- Default value
false
Primary store?
requireBillingAddressAtCheckout
​
requireShippingAddressAtCheckout
​
requireShippingMethodSelectionAtCheckout
​
settings
​
- Type
- craft\commerce\models\StoreSettings, null
- Default value
null
siteNames
​
- Type
\Illuminate\Support\Collection<string>
- Default value
null
- Access
- Read-only
sites
​
- Type
\Illuminate\Support\Collection
- Default value
null
- Access
- Read-only
sortOrder
​
- Type
- integer
- Default value
99
Sort order
storeSettingsUrl
​
- Type
- string
- Default value
null
- Access
- Read-only
uid
​
Store UID
useBillingAddressForTax
​
validateOrganizationTaxIdAsVatId
​
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.
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() | |
__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()
.
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.
Returns ​
string[] – List of attribute names.
getAdministrativeAreasListByCountryCode()
​
DEPRECATED
Deprecated in 5.0.0. Use [[Store::getSettings()->getAdministrativeAreasListByCountryCode()]] instead.
Returns ​
Throws ​
getAllowCheckoutWithoutPayment()
​
Whether carts are can be marked as completed without a payment.
Arguments ​
$parse
(boolean)
Returns ​
getAllowEmptyCartOnCheckout()
​
Whether carts are allowed to be empty on checkout.
Arguments ​
$parse
(boolean)
Returns ​
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.
Arguments ​
$parse
(boolean)
Returns ​
getAutoSetCartShippingMethodOption()
​
Whether the first available shipping method option should be set automatically on carts.
Arguments ​
$parse
(boolean)
Returns ​
getAutoSetNewCartAddresses()
​
Whether the user’s primary shipping and billing addresses should be set automatically on new carts.
Arguments ​
$parse
(boolean)
Returns ​
getAutoSetPaymentSource()
​
Whether the user’s primary payment source should be set automatically on new carts.
Arguments ​
$parse
(boolean)
Returns ​
getConfig()
​
Returns the project config data for this store.
getCountries()
​
DEPRECATED
Deprecated in 5.0.0. Use [[Store::getSettings()->getCountries()]] instead.
Returns ​
string[] – $countries
getCountriesList()
​
DEPRECATED
Deprecated in 5.0.0. Use [[Store::getSettings()->getCountriesList()]] instead.
Returns ​
Throws ​
getCurrency()
​
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.
Arguments ​
$parse
(boolean)
Returns ​
getFreeOrderPaymentStrategyOptions()
​
Returns a key-value array of freeOrderPaymentStrategy
options and labels.
getInventoryLocations()
​
Returns the inventory locations related to this store.
Returns ​
\Illuminate\Support\Collection
Throws ​
getInventoryLocationsOptions()
​
Returns ​
Throws ​
getMarketAddressCondition()
​
DEPRECATED
Deprecated in 5.0.0. Use [[Store::getSettings()->getMarketAddressCondition()]] instead.
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'
returns0
if the result from'default'
would’ve been negative; minimum order total is0
.'shipping'
returns the total shipping cost if the'default'
result would’ve been negative; minimum order total equals shipping amount.
Arguments ​
$parse
(boolean)
Returns ​
getMinimumTotalPriceStrategyOptions()
​
Returns a key-value array of minimumTotalPriceStrategy
options and labels.
getName()
​
Returns the store’s name.
Arguments ​
$parse
(boolean) – Whether to parse the name for an environment variable
Returns ​
getOrderReferenceFormat()
​
Human-friendly reference number format for orders. Result must be unique.
See Order Numbers.
Arguments ​
$parse
(boolean)
Returns ​
getRequireBillingAddressAtCheckout()
​
Whether a billing address is required before making payment on an order.
Arguments ​
$parse
(boolean)
Returns ​
getRequireShippingAddressAtCheckout()
​
Arguments ​
$parse
(boolean)
Returns ​
getRequireShippingMethodSelectionAtCheckout()
​
Whether shipping method selection is required before making payment on an order.
Arguments ​
$parse
(boolean)
Returns ​
getSettings()
​
Returns ​
craft\commerce\models\StoreSettings
getSiteNames()
​
Returns the names of the sites related to this store
Returns ​
\Illuminate\Support\Collection<string>
Throws ​
getSites()
​
Returns the sites that are related to this store.
Returns ​
\Illuminate\Support\Collection
Throws ​
getStoreSettingsUrl()
​
Gets the CP url to these stores settings
Arguments ​
Returns ​
getUseBillingAddressForTax()
​
Whether taxes should be calculated based on the billing address instead of the shipping address.
Arguments ​
$parse
(boolean)
Returns ​
getValidateOrganizationTaxIdAsVatId()
​
Arguments ​
$parse
(boolean)
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()
​
Arguments ​
Returns ​
void
setAllowEmptyCartOnCheckout()
​
Arguments ​
Returns ​
void
setAllowPartialPaymentOnCheckout()
​
Arguments ​
Returns ​
void
setAutoSetCartShippingMethodOption()
​
Arguments ​
Returns ​
void
setAutoSetNewCartAddresses()
​
Arguments ​
Returns ​
void
setAutoSetPaymentSource()
​
Arguments ​
Returns ​
void
setCountries()
​
DEPRECATED
Deprecated in 5.0.0. Use [[Store::getSettings()->setCountries()]] instead.
Arguments ​
$countries
(mixed
)
Returns ​
void
Throws ​
setCurrency()
​
Arguments ​
$currency
(string,\Money\Currency
)
Returns ​
void
setFreeOrderPaymentStrategy()
​
Arguments ​
$freeOrderPaymentStrategy
(string)
Returns ​
void
setMinimumTotalPriceStrategy()
​
Arguments ​
$minimumTotalPriceStrategy
(string)
Returns ​
void
setName()
​
Sets the store’s name.
Arguments ​
$name
(string)
setOrderReferenceFormat()
​
Arguments ​
Returns ​
void
setRequireBillingAddressAtCheckout()
​
Arguments ​
Returns ​
void
setRequireShippingAddressAtCheckout()
​
Arguments ​
Returns ​
void
setRequireShippingMethodSelectionAtCheckout()
​
Arguments ​
Returns ​
void
setUseBillingAddressForTax()
​
Arguments ​
Returns ​
void
setValidateOrganizationTaxIdAsVatId()
​
Arguments ​
Returns ​
void
Protected Methods ​
Method | Description |
---|---|
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.
Returns ​
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.
Returns ​
Constants ​
Constant | Description |
---|---|
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_DEFAULT | The name of the default scenario. |