Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Website.php
Go to the documentation of this file.
1 <?php
7 
11 class Website implements ReaderInterface
12 {
16  protected $websiteRepository;
17 
21  protected $groupRepository;
22 
26  protected $storeRepository;
27 
33  public function __construct(
34  \Magento\Store\Api\StoreRepositoryInterface $storeRepository,
35  \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository,
36  \Magento\Store\Api\GroupRepositoryInterface $groupRepository
37  ) {
38  $this->websiteRepository = $websiteRepository;
39  $this->groupRepository = $groupRepository;
40  $this->storeRepository = $storeRepository;
41  }
42 
46  public function getAllowedStoreIds($scopeCode)
47  {
48  $stores = [];
49  $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
50  foreach ($this->storeRepository->getList() as $store) {
51  if ($store->getIsActive()) {
52  if (($scopeCode && $store->getWebsiteId() == $website->getId()) || (!$scopeCode)) {
53  $stores[$store->getId()] = $store->getId();
54  }
55  }
56  }
57  sort($stores);
58  return $stores;
59  }
60 
64  public function getDefaultStoreId($scopeCode)
65  {
66  $website = $scopeCode ? $this->websiteRepository->get($scopeCode) : $this->websiteRepository->getDefault();
67  return $this->groupRepository->get($website->getDefaultGroupId())->getDefaultStoreId();
68  }
69 }
__construct(\Magento\Store\Api\StoreRepositoryInterface $storeRepository, \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository, \Magento\Store\Api\GroupRepositoryInterface $groupRepository)
Definition: Website.php:33