Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
StoreRepository Class Reference
Inheritance diagram for StoreRepository:
StoreRepositoryInterface

Public Member Functions

 __construct (StoreFactory $storeFactory, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory)
 
 get ($code)
 
 getActiveStoreByCode ($code)
 
 getById ($id)
 
 getActiveStoreById ($id)
 
 getList ()
 
 clean ()
 

Protected Attributes

 $storeFactory
 
 $storeCollectionFactory
 
 $entities = []
 
 $entitiesById = []
 
 $allLoaded = false
 

Detailed Description

Information Expert in stores handling

Definition at line 16 of file StoreRepository.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( StoreFactory  $storeFactory,
\Magento\Store\Model\ResourceModel\Store\CollectionFactory  $storeCollectionFactory 
)
Parameters
StoreFactory$storeFactory
\Magento\Store\Model\ResourceModel\Store\CollectionFactory$storeCollectionFactory

Definition at line 52 of file StoreRepository.php.

55  {
56  $this->storeFactory = $storeFactory;
57  $this->storeCollectionFactory = $storeCollectionFactory;
58  }

Member Function Documentation

◆ clean()

clean ( )

{Clear cached entities

Returns
void
}

Implements StoreRepositoryInterface.

Definition at line 172 of file StoreRepository.php.

173  {
174  $this->entities = [];
175  $this->entitiesById = [];
176  $this->allLoaded = false;
177  }

◆ get()

get (   $code)

{Retrieve store by code

Parameters
string$code
Returns
\Magento\Store\Api\Data\StoreInterface
Exceptions
NoSuchEntityException
}

Implements StoreRepositoryInterface.

Definition at line 63 of file StoreRepository.php.

64  {
65  if (isset($this->entities[$code])) {
66  return $this->entities[$code];
67  }
68 
69  $storeData = $this->getAppConfig()->get('scopes', "stores/$code", []);
70  $store = $this->storeFactory->create([
71  'data' => $storeData
72  ]);
73 
74  if ($store->getId() === null) {
75  throw new NoSuchEntityException(
76  __("The store that was requested wasn't found. Verify the store and try again.")
77  );
78  }
79  $this->entities[$code] = $store;
80  $this->entitiesById[$store->getId()] = $store;
81  return $store;
82  }
__()
Definition: __.php:13
$code
Definition: info.phtml:12

◆ getActiveStoreByCode()

getActiveStoreByCode (   $code)

{Retrieve active store by code

Parameters
string$code
Returns
\Magento\Store\Api\Data\StoreInterface
Exceptions
NoSuchEntityException
StoreIsInactiveException
}

Implements StoreRepositoryInterface.

Definition at line 87 of file StoreRepository.php.

88  {
89  $store = $this->get($code);
90 
91  if (!$store->isActive()) {
92  throw new StoreIsInactiveException();
93  }
94  return $store;
95  }
$code
Definition: info.phtml:12

◆ getActiveStoreById()

getActiveStoreById (   $id)

{Retrieve active store by id

Parameters
int$id
Returns
\Magento\Store\Api\Data\StoreInterface
Exceptions
NoSuchEntityException
StoreIsInactiveException
}

Implements StoreRepositoryInterface.

Definition at line 125 of file StoreRepository.php.

126  {
127  $store = $this->getById($id);
128 
129  if (!$store->isActive()) {
130  throw new StoreIsInactiveException();
131  }
132  return $store;
133  }
$id
Definition: fieldset.phtml:14

◆ getById()

getById (   $id)

{Retrieve store by id

Parameters
int$id
Returns
\Magento\Store\Api\Data\StoreInterface
Exceptions
NoSuchEntityException
}

Implements StoreRepositoryInterface.

Definition at line 100 of file StoreRepository.php.

101  {
102  if (isset($this->entitiesById[$id])) {
103  return $this->entitiesById[$id];
104  }
105 
106  $storeData = $this->getAppConfig()->get('scopes', "stores/$id", []);
107  $store = $this->storeFactory->create([
108  'data' => $storeData
109  ]);
110 
111  if ($store->getId() === null) {
112  throw new NoSuchEntityException(
113  __("The store that was requested wasn't found. Verify the store and try again.")
114  );
115  }
116 
117  $this->entitiesById[$id] = $store;
118  $this->entities[$store->getCode()] = $store;
119  return $store;
120  }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13

◆ getList()

getList ( )

{Retrieve list of all stores

Returns
\Magento\Store\Api\Data\StoreInterface[]
}

Implements StoreRepositoryInterface.

Definition at line 138 of file StoreRepository.php.

139  {
140  if ($this->allLoaded) {
141  return $this->entities;
142  }
143  $stores = $this->getAppConfig()->get('scopes', "stores", []);
144  foreach ($stores as $data) {
145  $store = $this->storeFactory->create([
146  'data' => $data
147  ]);
148  $this->entities[$store->getCode()] = $store;
149  $this->entitiesById[$store->getId()] = $store;
150  }
151  $this->allLoaded = true;
152  return $this->entities;
153  }

Field Documentation

◆ $allLoaded

$allLoaded = false
protected

Definition at line 41 of file StoreRepository.php.

◆ $entities

$entities = []
protected

Definition at line 31 of file StoreRepository.php.

◆ $entitiesById

$entitiesById = []
protected

Definition at line 36 of file StoreRepository.php.

◆ $storeCollectionFactory

$storeCollectionFactory
protected

Definition at line 26 of file StoreRepository.php.

◆ $storeFactory

$storeFactory
protected

Definition at line 21 of file StoreRepository.php.


The documentation for this class was generated from the following file: