Stores ​
- Type
- Class
- Namespace
- craft\commerce\services
- Inherits
- craft\commerce\services\Stores » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 5.0.0
Stores service.
Public Properties ​
Property | Description |
---|---|
allSiteStores | \Illuminate\Support\Collection<\craft\commerce\models\SiteStore> |
allStores | \Illuminate\Support\Collection |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
currentStore | craft\commerce\models\Store – The current store |
primaryStore | craft\commerce\models\Store |
siteIdsAvailableForAssignmentToNewStores | array |
allSiteStores
​
- Type
\Illuminate\Support\Collection<\craft\commerce\models\SiteStore>
- Default value
null
- Access
- Read-only
allStores
​
- Type
\Illuminate\Support\Collection
- Default value
null
currentStore
​
- Type
- craft\commerce\models\Store
- Default value
null
- Access
- Read-only
The current store
primaryStore
​
- Type
- craft\commerce\models\Store
- Default value
null
siteIdsAvailableForAssignmentToNewStores
​
- Type
- array
- Default value
null
- Access
- Read-only
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. |
afterDeleteCraftSiteHandler() | |
afterSaveCraftSiteHandler() | |
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. |
deleteStore() | |
deleteStoreById() | |
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. |
getAllSiteStores() | |
getAllSitesForStore() | |
getAllStores() | |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getCurrentStore() | Returns the current store. |
getPrimaryStore() | Returns the primary store. |
getSiteIdsAvailableForAssignmentToNewStores() | Returns sites that are assigned to more than one store assigned, so that other new stores can use them. |
getStoreByHandle() | |
getStoreById() | |
getStoreBySiteId() | |
getStoreByUid() | |
getStoresByUserId() | Returns a collections of stores that are available to a user. |
handleChangedSiteStore() | Handle site store mapping change. |
handleChangedStore() | Handle store status change. |
handleDeletedSiteStore() | Handle a deleted Store. |
handleDeletedStore() | Handle a deleted Store. |
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. |
refreshStores() | Refresh the status of all stores based on the DB data. |
reorderStores() | |
saveSiteStore() | |
saveStore() | Saves a store. |
trigger() | Triggers an event. |
afterDeleteCraftSiteHandler()
​
Arguments ​
$event
(craft\events\SiteEvent)
Returns ​
void
Throws ​
- craft\errors\BusyResourceException
- yii\base\ErrorException
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
- craft\errors\StaleResourceException
- yii\base\Exception
afterSaveCraftSiteHandler()
​
Arguments ​
$event
(craft\events\SiteEvent)
Returns ​
void
Throws ​
- craft\errors\BusyResourceException
- yii\base\ErrorException
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
- craft\errors\StaleResourceException
- yii\base\Exception
deleteStore()
​
Arguments ​
$store
(craft\commerce\models\Store)
Returns ​
Throws ​
deleteStoreById()
​
Arguments ​
$storeId
(integer)
Returns ​
Throws ​
getAllSiteStores()
​
Returns ​
\Illuminate\Support\Collection<\craft\commerce\models\SiteStore>
getAllSitesForStore()
​
Arguments ​
$store
(craft\commerce\models\Store)
Returns ​
\Illuminate\Support\Collection<\craft\models\Site>
getAllStores()
​
Returns ​
\Illuminate\Support\Collection<\craft\commerce\models\Store>
getCurrentStore()
​
Returns the current store.
Returns ​
craft\commerce\models\Store – The current store
Throws ​
getPrimaryStore()
​
Returns the primary store.
Returns ​
craft\commerce\models\Store, null
getSiteIdsAvailableForAssignmentToNewStores()
​
Returns sites that are assigned to more than one store assigned, so that other new stores can use them.
Returns ​
getStoreByHandle()
​
Arguments ​
$handle
(string)
Returns ​
craft\commerce\models\Store, null
getStoreById()
​
Arguments ​
$id
(integer)
Returns ​
craft\commerce\models\Store, null
getStoreBySiteId()
​
Arguments ​
$siteId
(integer)
Returns ​
craft\commerce\models\Store, null
getStoreByUid()
​
Arguments ​
$uid
(string)
Returns ​
craft\commerce\models\Store, null
getStoresByUserId()
​
Returns a collections of stores that are available to a user.
Arguments ​
$userId
(integer)
Returns ​
\Illuminate\Support\Collection<\craft\commerce\models\Store>
Throws ​
handleChangedSiteStore()
​
Handle site store mapping change.
Arguments ​
$event
(craft\events\ConfigEvent)
Returns ​
void
Throws ​
handleChangedStore()
​
Handle store status change.
Arguments ​
$event
(craft\events\ConfigEvent)
Returns ​
void
Throws ​
handleDeletedSiteStore()
​
Handle a deleted Store.
Arguments ​
$event
(craft\events\ConfigEvent)
Throws ​
handleDeletedStore()
​
Handle a deleted Store.
Arguments ​
$event
(craft\events\ConfigEvent)
Throws ​
refreshStores()
​
Refresh the status of all stores based on the DB data.
Returns ​
void
reorderStores()
​
Arguments ​
$ids
(array)
Returns ​
Throws ​
- craft\errors\BusyResourceException
- yii\base\ErrorException
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
- craft\errors\StaleResourceException
- yii\base\Exception
saveSiteStore()
​
Arguments ​
$siteStore
(craft\commerce\models\SiteStore)$runValidation
(boolean)
Returns ​
Throws ​
- craft\errors\BusyResourceException
- yii\base\ErrorException
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
- craft\errors\StaleResourceException
- yii\base\Exception
saveStore()
​
Saves a store.
Arguments ​
$store
(craft\commerce\models\Store) – The store to be saved$runValidation
(boolean) – Whether the store should be validated
Returns ​
Throws ​
- craft\errors\BusyResourceException
- craft\errors\StaleResourceException
- yii\base\ErrorException
- yii\base\Exception
- yii\base\InvalidConfigException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
Constants ​
Constant | Description |
---|---|
CONFIG_SITESTORES_KEY | The project config path to site stores data |
CONFIG_STORES_KEY | The project config path to stores data |
Events ​
EVENT_AFTER_DELETE_STORE ​
The event that is triggered after a store is deleted
use craft\commerce\events\DeleteStoreEvent;
use craft\commerce\models\Store;
use craft\commerce\services\Stores;
use yii\base\Event;
Event::on(
Stores::class,
Stores::EVENT_AFTER_DELETE_STORE,
function(DeleteStoreEvent $event) {
// @var Store $store
$store = $event->store;
// ...
}
);
EVENT_AFTER_SAVE_STORE ​
The event that is triggered after a store is saved.
use craft\commerce\events\StoreEvent;
use craft\commerce\models\Store;
use craft\commerce\services\Stores;
use yii\base\Event;
Event::on(
Stores::class,
Stores::EVENT_AFTER_SAVE_STORE,
function(StoreEvent $event) {
// @var Store $store
$store = $event->store;
// @var bool $isNew
$isNew = $event->isNew;
// ...
}
);
EVENT_BEFORE_APPLY_STORE_DELETE ​
The event that is triggered before a store delete is applied to the database.
use craft\commerce\events\DeleteStoreEvent;
use craft\commerce\models\Store;
use craft\commerce\services\Stores;
use yii\base\Event;
Event::on(
Stores::class,
Stores::EVENT_BEFORE_APPLY_STORE_DELETE,
function(DeleteStoreEvent $event) {
// @var Store $store
$store = $event->store;
// ...
}
);
EVENT_BEFORE_DELETE_STORE ​
The event that is triggered before a store is deleted.
You may set craft\events\CancelableEvent::$isValid to false
to prevent the store from getting deleted.
use craft\commerce\events\DeleteStoreEvent;
use craft\commerce\models\Store;
use craft\commerce\services\Stores;
use yii\base\Event;
Event::on(
Stores::class,
Stores::EVENT_BEFORE_DELETE_STORE,
function(DeleteStoreEvent $event) {
// @var Store $store
$store = $event->store;
// ...
}
);
EVENT_BEFORE_SAVE_STORE ​
The event that is triggered before a store is saved.
use craft\commerce\events\StoreEvent;
use craft\commerce\models\Store;
use craft\commerce\services\Stores;
use yii\base\Event;
Event::on(
Stores::class,
Stores::EVENT_BEFORE_SAVE_STORE,
function(StoreEvent $event) {
// @var Store $store
$store = $event->store;
// @var bool $isNew
$isNew = $event->isNew;
// ...
}
);