Skip to content

Commit bf74533

Browse files
committed
MC-39744: Expose group_id through storeConfig query
- expose group id to schema - fix availableStores resolver & query
1 parent 8537892 commit bf74533

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,49 @@ public function getStoreByWebsiteId($websiteId)
5555
public function getWebsiteStores(int $websiteId, bool $available = false, int $storeGroupId = null): array
5656
{
5757
$connection = $this->resource->getConnection();
58-
$storeTable = $this->resource->getTableName('store');
59-
$storeSelect = $connection->select()->from($storeTable)->where(
60-
'website_id = ?',
61-
$websiteId
62-
);
58+
$storeTable = $this->resource->getTableName('store_website');
59+
$storeSelect = $connection->select()
60+
->from(['main_table' => $storeTable])
61+
->columns(
62+
[
63+
'website_code' => 'code',
64+
'website_name' => 'name',
65+
'website_sort_order' => 'sort_order',
66+
'default_group_id'
67+
]
68+
)
69+
->join(
70+
['group_table' => $this->resource->getTableName('store_group')],
71+
'main_table.website_id = group_table.website_id',
72+
[
73+
'store_group_code' => 'code',
74+
'store_group_name' => 'name',
75+
'default_store_id'
76+
]
77+
)
78+
->join(
79+
['store_table' => $this->resource->getTableName('store')],
80+
'group_table.group_id = store_table.group_id'
81+
);
6382

6483
if ($storeGroupId) {
6584
$storeSelect = $storeSelect->where(
66-
'group_id = ?',
85+
'store_table.group_id = ?',
6786
$storeGroupId
6887
);
6988
}
7089

7190
if ($available) {
7291
$storeSelect = $storeSelect->where(
73-
'is_active = 1'
92+
'store_table.is_active = 1'
7493
);
7594
}
7695

96+
$storeSelect = $storeSelect->where(
97+
'main_table.website_id = ?',
98+
$websiteId
99+
);
100+
77101
return $connection->fetchAll($storeSelect);
78102
}
79103
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(
6666
public function getStoreConfigData(StoreInterface $store): array
6767
{
6868
$defaultStoreConfig = $this->storeConfigManager->getStoreConfigs([$store->getCode()]);
69-
return $this->prepareStoreConfigData(current($defaultStoreConfig), $store->getName());
69+
return $this->prepareStoreConfigData(current($defaultStoreConfig), $store->getData());
7070
}
7171

7272
/**
@@ -86,7 +86,7 @@ public function getAvailableStoreConfig(int $websiteId, int $storeGroupId = null
8686

8787
foreach ($storeConfigs as $storeConfig) {
8888
$key = array_search($storeConfig->getCode(), array_column($websiteStores, 'code'), true);
89-
$storesConfigData[] = $this->prepareStoreConfigData($storeConfig, $websiteStores[$key]['name']);
89+
$storesConfigData[] = $this->prepareStoreConfigData($storeConfig, $websiteStores[$key]);
9090
}
9191

9292
return $storesConfigData;
@@ -96,15 +96,24 @@ public function getAvailableStoreConfig(int $websiteId, int $storeGroupId = null
9696
* Prepare store config data
9797
*
9898
* @param StoreConfigInterface $storeConfig
99-
* @param string $storeName
99+
* @param array $storeData
100100
* @return array
101101
*/
102-
private function prepareStoreConfigData(StoreConfigInterface $storeConfig, string $storeName): array
102+
private function prepareStoreConfigData(StoreConfigInterface $storeConfig, array $storeData): array
103103
{
104+
$x=1;
104105
return array_merge([
105106
'id' => $storeConfig->getId(),
106107
'code' => $storeConfig->getCode(),
108+
'store_code' => $storeConfig->getCode(),
109+
'store_name' => $storeData['name'] ?? null,
110+
'store_sort_order' => $storeData['sort_order'] ?? null,
111+
'store_group_code' => $storeData['store_group_code'] ?? null,
112+
'store_group_name' => $storeData['store_group_name'] ?? null,
113+
'store_group_default_store_code' => $storeData['store_group_default_store_code'] ?? null,
107114
'website_id' => $storeConfig->getWebsiteId(),
115+
'website_code' => $storeData['website_code'] ?? null,
116+
'website_name' => $storeData['website_name'] ?? null,
108117
'locale' => $storeConfig->getLocale(),
109118
'base_currency_code' => $storeConfig->getBaseCurrencyCode(),
110119
'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(),
@@ -118,7 +127,6 @@ private function prepareStoreConfigData(StoreConfigInterface $storeConfig, strin
118127
'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(),
119128
'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(),
120129
'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl(),
121-
'store_name' => $storeName,
122130
], $this->getExtendedConfigData((int)$storeConfig->getId()));
123131
}
124132

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ type Website @doc(description: "Website is deprecated because it is should not b
1717
}
1818

1919
type StoreConfig @doc(description: "The type contains information about a store config") {
20-
id : Int @doc(description: "The ID number assigned to the store")
21-
code : String @doc(description: "A code assigned to the store to identify it")
22-
website_id : Int @doc(description: "The ID number assigned to the website store belongs")
20+
id : Int @deprecated(reason: "Use `store_code` instead.") @doc(description: "The ID number assigned to the store")
21+
code : String @deprecated(reason: "Use `store_code` instead.") @doc(description: "A code assigned to the store to identify it")
22+
store_code: ID @doc(description: "The unique ID for a `StoreConfig` object representing store view and used as optional `Store` in Headers to select a current store view.")
23+
store_name : String @doc(description: "The name of the store view.")
24+
store_sort_order : Float @doc(description: "The store view sort order")
25+
store_group_code : ID @doc(description: "The unique ID/Code for a store group of which the `StoreConfig` belongs")
26+
store_group_name : String @doc(description: "The store group name for which the `StoreConfig` belongs")
27+
website_id : Int @deprecated(reason: "The field should not be used on the storefront") @doc(description: "The ID number assigned to the website store belongs")
28+
website_code : ID @doc(description: "The unique ID/Code for a website group of which the `StoreConfig` belongs")
29+
website_name : ID @doc(description: "The name of the website")
2330
locale : String @doc(description: "Store locale")
2431
base_currency_code : String @doc(description: "Base currency code")
2532
default_display_currency_code : String @doc(description: "Default display currency code")
@@ -33,6 +40,5 @@ type StoreConfig @doc(description: "The type contains information about a store
3340
secure_base_link_url : String @doc(description: "Secure base link URL for the store")
3441
secure_base_static_url : String @doc(description: "Secure base static URL for the store")
3542
secure_base_media_url : String @doc(description: "Secure base media URL for the store")
36-
store_name : String @doc(description: "Name of the store")
3743
use_store_in_url: Boolean @doc(description: "The configuration determines if the store code should be used in the URL")
3844
}

0 commit comments

Comments
 (0)