Skip to content

Commit 6209cfb

Browse files
committed
PWA-805: Expose localization system / store config from GraphQL
1 parent 42311fa commit 6209cfb

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

app/code/Magento/Store/Model/ResourceModel/StoreWebsiteRelation.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public function getStoreByWebsiteId($websiteId)
4848
* Get website store data
4949
*
5050
* @param int $websiteId
51+
* @param int $storeGroupId
5152
* @param bool $available
5253
* @return array
5354
*/
54-
public function getWebsiteStores(int $websiteId, bool $available = false): array
55+
public function getWebsiteStores(int $websiteId, int $storeGroupId = null, bool $available = false): array
5556
{
5657
$connection = $this->resource->getConnection();
5758
$storeTable = $this->resource->getTableName('store');
@@ -60,6 +61,13 @@ public function getWebsiteStores(int $websiteId, bool $available = false): array
6061
$websiteId
6162
);
6263

64+
if ($storeGroupId) {
65+
$storeSelect = $storeSelect->where(
66+
'group_id = ?',
67+
$storeGroupId
68+
);
69+
}
70+
6371
if ($available) {
6472
$storeSelect = $storeSelect->where(
6573
'is_active = 1'

app/code/Magento/StoreGraphQl/Model/Resolver/AvailableStoresResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public function resolve(
4141
array $value = null,
4242
array $args = null
4343
) {
44+
$storeGroupId = !empty($args['use_current_group']) ?
45+
(int)$context->getExtensionAttributes()->getStore()->getStoreGroupId() :
46+
null;
4447
return $this->storeConfigDataProvider->getAvailableStoreConfig(
45-
(int)$context->getExtensionAttributes()->getStore()->getWebsiteId()
48+
(int)$context->getExtensionAttributes()->getStore()->getWebsiteId(),
49+
$storeGroupId
4650
);
4751
}
4852
}

app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ public function getStoreConfigData(StoreInterface $store): array
7373
* Get available website stores
7474
*
7575
* @param int $websiteId
76+
* @param int|null $storeGroupId
7677
* @return array
7778
*/
78-
public function getAvailableStoreConfig(int $websiteId): array
79+
public function getAvailableStoreConfig(int $websiteId, int $storeGroupId = null): array
7980
{
80-
$websiteStores = $this->storeWebsiteRelation->getWebsiteStores($websiteId, true);
81+
$websiteStores = $this->storeWebsiteRelation->getWebsiteStores($websiteId, $storeGroupId, true);
8182
$storeCodes = array_column($websiteStores, 'code');
8283

8384
$storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes);

app/code/Magento/StoreGraphQl/etc/graphql/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@
2323
</argument>
2424
</arguments>
2525
</type>
26+
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
27+
<arguments>
28+
<argument name="extendedConfigData" xsi:type="array">
29+
<item name="use_store_in_url" xsi:type="string">web/url/use_store</item>
30+
</argument>
31+
</arguments>
32+
</type>
2633
</config>

app/code/Magento/StoreGraphQl/etc/schema.graphqls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# See COPYING.txt for license details.
33
type Query {
44
storeConfig : StoreConfig @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigResolver") @doc(description: "The store config query") @cache(cacheable: false)
5-
availableStores: [StoreConfig] @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\AvailableStoresResolver") @doc(description: "Get a list of available store views and their config information.")
5+
availableStores(
6+
use_current_group : Boolean @doc(description: "Get only store views from the current store group")
7+
): [StoreConfig] @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\AvailableStoresResolver") @doc(description: "Get a list of available store views and their config information.")
68
}
79

810
type Website @doc(description: "Website is deprecated because it is should not be used on storefront. The type contains information about a website") {
@@ -32,4 +34,5 @@ type StoreConfig @doc(description: "The type contains information about a store
3234
secure_base_static_url : String @doc(description: "Secure base static URL for the store")
3335
secure_base_media_url : String @doc(description: "Secure base media URL for the store")
3436
store_name : String @doc(description: "Name of the store")
37+
use_store_in_url: Boolean @doc(description: "Indicates whether store code is used in url")
3538
}

0 commit comments

Comments
 (0)