-
Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#28569:Multi-store: Missing store codes in relation t… #28794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b577a3
1973c26
5ab033d
ac5835b
5ea15d1
4fe5f8f
48f8add
d8643e2
7cb5e98
2a3f775
d627611
48749bc
362b81a
78ea7b8
e1f8b56
4c994bf
ad896c5
454695c
00fbf7f
3c770e2
d9edb5b
b23125e
0ccadf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\StoreGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider; | ||
|
||
/** | ||
* AvailableStores page field resolver, used for GraphQL request processing. | ||
*/ | ||
class AvailableStoresResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var StoreConfigDataProvider | ||
*/ | ||
private $storeConfigDataProvider; | ||
|
||
/** | ||
* @param StoreConfigDataProvider $storeConfigsDataProvider | ||
*/ | ||
public function __construct( | ||
StoreConfigDataProvider $storeConfigsDataProvider | ||
) { | ||
$this->storeConfigDataProvider = $storeConfigsDataProvider; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
return $this->storeConfigDataProvider->getAvailableStoreConfig( | ||
(int)$context->getExtensionAttributes()->getStore()->getWebsiteId() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
namespace Magento\StoreGraphQl\Model\Resolver\Store; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Api\Data\StoreConfigInterface; | ||
use Magento\Store\Api\StoreConfigManagerInterface; | ||
use Magento\Store\Model\ResourceModel\StoreWebsiteRelation; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
|
||
|
@@ -32,19 +34,27 @@ class StoreConfigDataProvider | |
*/ | ||
private $extendedConfigData; | ||
|
||
/** | ||
* @var StoreWebsiteRelation | ||
*/ | ||
private $storeWebsiteRelation; | ||
|
||
/** | ||
* @param StoreConfigManagerInterface $storeConfigManager | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param StoreWebsiteRelation $storeWebsiteRelation | ||
* @param array $extendedConfigData | ||
*/ | ||
public function __construct( | ||
StoreConfigManagerInterface $storeConfigManager, | ||
ScopeConfigInterface $scopeConfig, | ||
StoreWebsiteRelation $storeWebsiteRelation, | ||
array $extendedConfigData = [] | ||
) { | ||
$this->storeConfigManager = $storeConfigManager; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->extendedConfigData = $extendedConfigData; | ||
$this->storeWebsiteRelation = $storeWebsiteRelation; | ||
} | ||
|
||
/** | ||
|
@@ -55,23 +65,42 @@ public function __construct( | |
*/ | ||
public function getStoreConfigData(StoreInterface $store): array | ||
{ | ||
return array_merge( | ||
$this->getBaseConfigData($store), | ||
$this->getExtendedConfigData((int)$store->getId()) | ||
); | ||
$defaultStoreConfig = $this->storeConfigManager->getStoreConfigs([$store->getCode()]); | ||
return $this->prepareStoreConfigData(current($defaultStoreConfig), $store->getName()); | ||
} | ||
|
||
/** | ||
* Get base config data | ||
* Get available website stores | ||
* | ||
* @param StoreInterface $store | ||
* @param int $websiteId | ||
* @return array | ||
*/ | ||
private function getBaseConfigData(StoreInterface $store) : array | ||
public function getAvailableStoreConfig(int $websiteId): array | ||
{ | ||
$storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()])); | ||
$websiteStores = $this->storeWebsiteRelation->getWebsiteStores($websiteId, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need a (int) typecast, and plz do that int $websiteID in methods, it's the preferred way |
||
$storeCodes = array_column($websiteStores, 'code'); | ||
|
||
$storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes); | ||
$storesConfigData = []; | ||
|
||
foreach ($storeConfigs as $storeConfig) { | ||
$key = array_search($storeConfig->getCode(), array_column($websiteStores, 'code'), true); | ||
$storesConfigData[] = $this->prepareStoreConfigData($storeConfig, $websiteStores[$key]['name']); | ||
} | ||
|
||
return [ | ||
return $storesConfigData; | ||
} | ||
|
||
/** | ||
* Prepare store config data | ||
* | ||
* @param StoreConfigInterface $storeConfig | ||
* @param string $storeName | ||
* @return array | ||
*/ | ||
private function prepareStoreConfigData(StoreConfigInterface $storeConfig, string $storeName): array | ||
{ | ||
return array_merge([ | ||
'id' => $storeConfig->getId(), | ||
'code' => $storeConfig->getCode(), | ||
'website_id' => $storeConfig->getWebsiteId(), | ||
|
@@ -82,14 +111,14 @@ private function getBaseConfigData(StoreInterface $store) : array | |
'weight_unit' => $storeConfig->getWeightUnit(), | ||
'base_url' => $storeConfig->getBaseUrl(), | ||
'base_link_url' => $storeConfig->getBaseLinkUrl(), | ||
'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), | ||
'base_static_url' => $storeConfig->getBaseStaticUrl(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please respond to this question: |
||
'base_media_url' => $storeConfig->getBaseMediaUrl(), | ||
'secure_base_url' => $storeConfig->getSecureBaseUrl(), | ||
'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(), | ||
'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(), | ||
'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl(), | ||
'store_name' => $store->getName() | ||
]; | ||
'store_name' => $storeName, | ||
], $this->getExtendedConfigData((int)$storeConfig->getId())); | ||
} | ||
|
||
/** | ||
|
@@ -98,7 +127,7 @@ private function getBaseConfigData(StoreInterface $store) : array | |
* @param int $storeId | ||
* @return array | ||
*/ | ||
private function getExtendedConfigData(int $storeId) | ||
private function getExtendedConfigData(int $storeId): array | ||
{ | ||
$extendedConfigData = []; | ||
foreach ($this->extendedConfigData as $key => $path) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can store StoreConfigs into a private local variable once fetched