class CurrentStore in Commerce Core 8.2
Same name in this branch
- 8.2 modules/store/src/CurrentStore.php \Drupal\commerce_store\CurrentStore
- 8.2 modules/store/src/Plugin/views/argument_default/CurrentStore.php \Drupal\commerce_store\Plugin\views\argument_default\CurrentStore
Holds a reference to the current store, resolved on demand.
The ChainStoreResolver runs the registered store resolvers one by one until one of them returns the store. The DefaultStoreResolver runs last, and will select the default store. Custom resolvers can choose based on the url, the user's country, etc.
Note that this functionality is optional, since not every site will be limited to having only one active store at the time.
Hierarchy
- class \Drupal\commerce_store\CurrentStore implements CurrentStoreInterface
Expanded class hierarchy of CurrentStore
See also
\Drupal\commerce_store\Resolver\ChainStoreResolver
\Drupal\commerce_store\Resolver\DefaultStoreResolver
1 string reference to 'CurrentStore'
- commerce_store.services.yml in modules/
store/ commerce_store.services.yml - modules/store/commerce_store.services.yml
1 service uses CurrentStore
File
- modules/
store/ src/ CurrentStore.php, line 22
Namespace
Drupal\commerce_storeView source
class CurrentStore implements CurrentStoreInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The chain resolver.
*
* @var \Drupal\commerce_store\Resolver\ChainStoreResolverInterface
*/
protected $chainResolver;
/**
* Static cache of resolved stores. One per request.
*
* @var \SplObjectStorage
*/
protected $stores;
/**
* Constructs a new CurrentStore object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\commerce_store\Resolver\ChainStoreResolverInterface $chain_resolver
* The chain resolver.
*/
public function __construct(RequestStack $request_stack, ChainStoreResolverInterface $chain_resolver) {
$this->requestStack = $request_stack;
$this->chainResolver = $chain_resolver;
$this->stores = new \SplObjectStorage();
}
/**
* {@inheritdoc}
*/
public function getStore() {
$request = $this->requestStack
->getCurrentRequest();
if (!$this->stores
->contains($request)) {
$this->stores[$request] = $this->chainResolver
->resolve();
}
return $this->stores[$request];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentStore:: |
protected | property | The chain resolver. | |
CurrentStore:: |
protected | property | The request stack. | |
CurrentStore:: |
protected | property | Static cache of resolved stores. One per request. | |
CurrentStore:: |
public | function |
Gets the active store for the current request. Overrides CurrentStoreInterface:: |
|
CurrentStore:: |
public | function | Constructs a new CurrentStore object. |