-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphql-ce-120: get single store config instead multiple
- Loading branch information
vitaliyboyko
committed
Jul 19, 2018
1 parent
b5a2a98
commit e85a6e5
Showing
6 changed files
with
189 additions
and
215 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigDataProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\StoreGraphQl\Model\Resolver\Store; | ||
|
||
use Magento\Store\Api\Data\StoreConfigInterface; | ||
use Magento\Store\Api\StoreConfigManagerInterface; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\Api\StoreResolverInterface; | ||
|
||
/** | ||
* StoreConfig field data provider, used for GraphQL request processing. | ||
*/ | ||
class StoreConfigDataProvider | ||
{ | ||
/** | ||
* @var StoreConfigManagerInterface | ||
*/ | ||
private $storeConfigManager; | ||
|
||
/** | ||
* @var StoreResolverInterface | ||
*/ | ||
private $storeResolver; | ||
|
||
/** | ||
* @var StoreRepositoryInterface | ||
*/ | ||
private $storeRepository; | ||
|
||
/** | ||
* @param StoreConfigManagerInterface $storeConfigManager | ||
* @param StoreResolverInterface $storeResolver | ||
* @param StoreRepositoryInterface $storeRepository | ||
*/ | ||
public function __construct( | ||
StoreConfigManagerInterface $storeConfigManager, | ||
StoreResolverInterface $storeResolver, | ||
StoreRepositoryInterface $storeRepository | ||
) { | ||
$this->storeConfigManager = $storeConfigManager; | ||
$this->storeResolver = $storeResolver; | ||
$this->storeRepository = $storeRepository; | ||
} | ||
|
||
/** | ||
* Get store config for current store | ||
* | ||
* @return array | ||
*/ | ||
public function getStoreConfig() : array | ||
{ | ||
$storeId = $this->storeResolver->getCurrentStoreId(); | ||
$store = $this->storeRepository->getById($storeId); | ||
$storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()])); | ||
|
||
return $this->hidrateStoreConfig($storeConfig); | ||
} | ||
|
||
/** | ||
* Transform StoreConfig object to in array format | ||
* | ||
* @param StoreConfigInterface $storeConfig | ||
* @return array | ||
*/ | ||
private function hidrateStoreConfig($storeConfig): array | ||
{ | ||
/** @var StoreConfigInterface $storeConfig */ | ||
$storeConfigData = [ | ||
'id' => $storeConfig->getId(), | ||
'code' => $storeConfig->getCode(), | ||
'website_id' => $storeConfig->getWebsiteId(), | ||
'locale' => $storeConfig->getLocale(), | ||
'base_currency_code' => $storeConfig->getBaseCurrencyCode(), | ||
'default_display_currency_code' => $storeConfig->getDefaultDisplayCurrencyCode(), | ||
'timezone' => $storeConfig->getTimezone(), | ||
'weight_unit' => $storeConfig->getWeightUnit(), | ||
'base_url' => $storeConfig->getBaseUrl(), | ||
'base_link_url' => $storeConfig->getBaseLinkUrl(), | ||
'base_static_url' => $storeConfig->getSecureBaseStaticUrl(), | ||
'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() | ||
]; | ||
|
||
return $storeConfigData; | ||
} | ||
} |
80 changes: 0 additions & 80 deletions
80
app/code/Magento/StoreGraphQl/Model/Resolver/Store/StoreConfigsDataProvider.php
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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\Resolver\Value; | ||
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider; | ||
|
||
/** | ||
* StoreConfig page field resolver, used for GraphQL request processing. | ||
*/ | ||
class StoreConfigResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var StoreConfigDataProvider | ||
*/ | ||
private $storeConfigDataProvider; | ||
|
||
/** | ||
* @var ValueFactory | ||
*/ | ||
private $valueFactory; | ||
|
||
/** | ||
* @param StoreConfigDataProvider $storeConfigsDataProvider | ||
* @param ValueFactory $valueFactory | ||
*/ | ||
public function __construct( | ||
StoreConfigDataProvider $storeConfigsDataProvider, | ||
ValueFactory $valueFactory | ||
) { | ||
$this->valueFactory = $valueFactory; | ||
$this->storeConfigDataProvider = $storeConfigsDataProvider; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) : Value { | ||
|
||
$storeConfigData = $this->storeConfigDataProvider->getStoreConfig(); | ||
|
||
$result = function () use ($storeConfigData) { | ||
return !empty($storeConfigData) ? $storeConfigData : []; | ||
}; | ||
|
||
return $this->valueFactory->create($result); | ||
} | ||
} |
84 changes: 0 additions & 84 deletions
84
app/code/Magento/StoreGraphQl/Model/Resolver/StoreConfigsResolver.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.