Group.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model\StoreResolver;
  7. class Group implements ReaderInterface
  8. {
  9. /**
  10. * @var \Magento\Store\Api\GroupRepositoryInterface
  11. */
  12. protected $groupRepository;
  13. /**
  14. * @var \Magento\Store\Api\StoreRepositoryInterface
  15. */
  16. protected $storeRepository;
  17. /**
  18. * @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
  19. * @param \Magento\Store\Api\GroupRepositoryInterface $groupRepository
  20. */
  21. public function __construct(
  22. \Magento\Store\Api\StoreRepositoryInterface $storeRepository,
  23. \Magento\Store\Api\GroupRepositoryInterface $groupRepository
  24. ) {
  25. $this->groupRepository = $groupRepository;
  26. $this->storeRepository = $storeRepository;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getAllowedStoreIds($scopeCode)
  32. {
  33. $stores = [];
  34. foreach ($this->storeRepository->getList() as $store) {
  35. if ($store->isActive() && (int) $store->getGroupId() === $scopeCode) {
  36. $stores[] = $store->getId();
  37. }
  38. }
  39. return $stores;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getDefaultStoreId($scopeCode)
  45. {
  46. return $this->groupRepository->get($scopeCode)->getDefaultStoreId();
  47. }
  48. }