Skip to content

Commit bfdec57

Browse files
committed
MC-39744: Expose group_id through storeConfig query
- fix single/current store config query
1 parent bf74533 commit bfdec57

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ public function getStoreByWebsiteId($websiteId)
5050
* @param int $websiteId
5151
* @param bool $available
5252
* @param int|null $storeGroupId
53+
* @param int|null $storeId
5354
* @return array
5455
*/
55-
public function getWebsiteStores(int $websiteId, bool $available = false, int $storeGroupId = null): array
56-
{
56+
public function getWebsiteStores(
57+
int $websiteId,
58+
bool $available = false,
59+
int $storeGroupId = null,
60+
int $storeId = null
61+
): array {
5762
$connection = $this->resource->getConnection();
5863
$storeTable = $this->resource->getTableName('store_website');
5964
$storeSelect = $connection->select()
@@ -87,6 +92,13 @@ public function getWebsiteStores(int $websiteId, bool $available = false, int $s
8792
);
8893
}
8994

95+
if ($storeId) {
96+
$storeSelect = $storeSelect->where(
97+
'store_table.store_id = ?',
98+
$storeId
99+
);
100+
}
101+
90102
if ($available) {
91103
$storeSelect = $storeSelect->where(
92104
'store_table.is_active = 1'

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,19 @@ public function __construct(
6565
*/
6666
public function getStoreConfigData(StoreInterface $store): array
6767
{
68-
$defaultStoreConfig = $this->storeConfigManager->getStoreConfigs([$store->getCode()]);
69-
return $this->prepareStoreConfigData(current($defaultStoreConfig), $store->getData());
68+
$defaultWebsiteStore = $this->storeWebsiteRelation->getWebsiteStores(
69+
(int) $store->getWebsiteId(),
70+
true,
71+
(int) $store->getStoreGroupId(),
72+
(int) $store->getStoreId()
73+
);
74+
if (empty($defaultWebsiteStore)) {
75+
return [];
76+
}
77+
78+
$storeConfigs = $this->storeConfigManager->getStoreConfigs([$store->getCode()]);
79+
80+
return $this->prepareStoreConfigData(current($storeConfigs), current($defaultWebsiteStore));
7081
}
7182

7283
/**
@@ -101,15 +112,16 @@ public function getAvailableStoreConfig(int $websiteId, int $storeGroupId = null
101112
*/
102113
private function prepareStoreConfigData(StoreConfigInterface $storeConfig, array $storeData): array
103114
{
104-
$x=1;
105115
return array_merge([
106116
'id' => $storeConfig->getId(),
107117
'code' => $storeConfig->getCode(),
108118
'store_code' => $storeConfig->getCode(),
109119
'store_name' => $storeData['name'] ?? null,
110120
'store_sort_order' => $storeData['sort_order'] ?? null,
121+
'is_default_store' => $storeData['default_store_id'] == $storeConfig->getId() ?? null,
111122
'store_group_code' => $storeData['store_group_code'] ?? null,
112123
'store_group_name' => $storeData['store_group_name'] ?? null,
124+
'is_default_store_group' => $storeData['default_group_id'] == $storeData['group_id'] ?? null,
113125
'store_group_default_store_code' => $storeData['store_group_default_store_code'] ?? null,
114126
'website_id' => $storeConfig->getWebsiteId(),
115127
'website_code' => $storeData['website_code'] ?? null,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ type StoreConfig @doc(description: "The type contains information about a store
2222
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.")
2323
store_name : String @doc(description: "The name of the store view.")
2424
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")
25+
is_default_store : Boolean @doc(description: "The default store for the store group")
26+
store_group_code : ID @doc(description: "The unique ID/Code for a store group the `StoreConfig` belongs to")
27+
store_group_name : String @doc(description: "The store group name the `StoreConfig` belongs to")
28+
is_default_store_group : Boolean @doc(description: "The default store group for which the `StoreConfig` belongs")
2729
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")
2830
website_code : ID @doc(description: "The unique ID/Code for a website group of which the `StoreConfig` belongs")
2931
website_name : ID @doc(description: "The name of the website")

0 commit comments

Comments
 (0)