11 use Magento\Store\Model\ResourceModel\Website\CollectionFactory;
71 if (isset($this->entities[
$code])) {
72 return $this->entities[
$code];
75 $websiteData = $this->getAppConfig()->get(
'scopes',
"websites/$code", []);
77 'data' => $websiteData
93 if (isset($this->entitiesById[
$id])) {
94 return $this->entitiesById[
$id];
97 $websiteData = $this->getAppConfig()->get(
'scopes',
"websites/$id", []);
99 'data' => $websiteData
115 if (!$this->allLoaded) {
116 $websites = $this->getAppConfig()->get(
'scopes',
'websites', []);
124 $this->allLoaded =
true;
134 if (!$this->
default) {
135 foreach ($this->entities as
$entity) {
141 if (!$this->allLoaded) {
142 $this->initDefaultWebsite();
144 if (!$this->
default) {
145 throw new \DomainException(
__(
"The default website isn't defined. Set the website and try again."));
157 $this->entities = [];
158 $this->entitiesById = [];
159 $this->
default =
null;
160 $this->allLoaded =
false;
169 private function getAppConfig()
171 if (!$this->appConfig) {
174 return $this->appConfig;
181 private function initDefaultWebsite()
183 $websites = (array) $this->getAppConfig()->get(
'scopes',
'websites', []);
185 if (isset(
$data[
'is_default']) &&
$data[
'is_default'] == 1) {
186 if ($this->
default) {
187 throw new \DomainException(
189 'The default website is invalid. ' 190 .
'Make sure no more than one default is defined and try again.'
$websiteCollectionFactory
__construct(WebsiteFactory $factory, CollectionFactory $websiteCollectionFactory)