ScopeTreeProvider.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\App\ScopeTreeProviderInterface;
  9. use Magento\Store\Model\Group;
  10. use Magento\Store\Model\Store;
  11. use Magento\Store\Model\Website;
  12. class ScopeTreeProvider implements ScopeTreeProviderInterface
  13. {
  14. /**
  15. * @var StoreManagerInterface
  16. */
  17. protected $storeManager;
  18. /**
  19. * @param StoreManagerInterface $storeManager
  20. */
  21. public function __construct(
  22. StoreManagerInterface $storeManager
  23. ) {
  24. $this->storeManager = $storeManager;
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function get()
  30. {
  31. $defaultScope = [
  32. 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
  33. 'scope_id' => null,
  34. 'scopes' => [],
  35. ];
  36. /** @var Website $website */
  37. foreach ($this->storeManager->getWebsites() as $website) {
  38. $websiteScope = [
  39. 'scope' => ScopeInterface::SCOPE_WEBSITES,
  40. 'scope_id' => $website->getId(),
  41. 'scopes' => [],
  42. ];
  43. /** @var Group $group */
  44. foreach ($website->getGroups() as $group) {
  45. $groupScope = [
  46. 'scope' => ScopeInterface::SCOPE_GROUP,
  47. 'scope_id' => $group->getId(),
  48. 'scopes' => [],
  49. ];
  50. /** @var Store $store */
  51. foreach ($group->getStores() as $store) {
  52. $storeScope = [
  53. 'scope' => ScopeInterface::SCOPE_STORES,
  54. 'scope_id' => $store->getId(),
  55. 'scopes' => [],
  56. ];
  57. $groupScope['scopes'][] = $storeScope;
  58. }
  59. $websiteScope['scopes'][] = $groupScope;
  60. }
  61. $defaultScope['scopes'][] = $websiteScope;
  62. }
  63. return $defaultScope;
  64. }
  65. }