Skip to content

Commit 9b90342

Browse files
committed
Support store list retrieval in phtml template
1 parent 73a253c commit 9b90342

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/View/Result/Page.php

+27
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Magento\Store\Model\ScopeInterface;
2828
use Magento\Store\Model\StoreManagerInterface;
2929
use ScandiPWA\Locale\View\Result\Page as LocalePage;
30+
use Magento\Framework\Serialize\Serializer\Json;
31+
3032

3133
/**
3234
* Class Page
@@ -44,6 +46,11 @@ class Page extends LocalePage
4446
*/
4547
protected $storeManager;
4648

49+
/**
50+
* @var Json
51+
*/
52+
protected $json;
53+
4754
/**
4855
* Page constructor.
4956
* @param StoreManagerInterface $storeManager
@@ -56,6 +63,7 @@ class Page extends LocalePage
5663
* @param GeneratorPool $generatorPool
5764
* @param RendererFactory $pageConfigRendererFactory
5865
* @param Reader $pageLayoutReader
66+
* @param Json $json
5967
* @param string $template
6068
* @param bool $isIsolated
6169
* @param EntitySpecificHandlesList|null $entitySpecificHandlesList
@@ -72,13 +80,15 @@ public function __construct(
7280
GeneratorPool $generatorPool,
7381
RendererFactory $pageConfigRendererFactory,
7482
Reader $pageLayoutReader,
83+
Json $json,
7584
string $template,
7685
$isIsolated = false,
7786
EntitySpecificHandlesList $entitySpecificHandlesList = null,
7887
$action = null
7988
) {
8089
$this->scopeConfig = $context->getScopeConfig();
8190
$this->storeManager = $storeManager;
91+
$this->json = $json;
8292

8393
parent::__construct(
8494
$localeResolver,
@@ -112,4 +122,21 @@ public function getThemeConfiguration(
112122
$this->storeManager->getStore()->getId()
113123
);
114124
}
125+
126+
/**
127+
* Get store list json
128+
*
129+
* @return bool|false|string
130+
*/
131+
public function getStoreListJson()
132+
{
133+
$result = [];
134+
$storeList = $this->storeManager->getStores();
135+
136+
foreach ($storeList as $store) {
137+
$result[] = $store->getCode();
138+
}
139+
140+
return $this->json->serialize($result);
141+
}
115142
}

0 commit comments

Comments
 (0)