Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b577a3
magento/magento2#28569:Multi-store: Missing store codes in relation t…
gallyamov Jun 18, 2020
1973c26
Merge branch '2.4-develop' of github.com:magento/magento2 into 28569_…
gallyamov Jun 22, 2020
5ab033d
magento/magento2#28569: Missing store codes in relation to a group an…
gallyamov Jun 22, 2020
ac5835b
magento/magento2#28569: Missing store codes in relation to a group an…
gallyamov Jun 22, 2020
5ea15d1
Merge branch '2.4-develop' of github.com:magento/magento2 into 28569_…
gallyamov Jun 24, 2020
4fe5f8f
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jun 24, 2020
48f8add
Merge branch '2.4-develop' of github.com:magento/magento2 into 28569_…
gallyamov Jun 25, 2020
d8643e2
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jun 25, 2020
7cb5e98
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jun 26, 2020
2a3f775
Merge branch '2.4-develop' into 28569_adding_stores_to_store_config
gallyamov Jun 30, 2020
d627611
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jun 30, 2020
48749bc
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jun 30, 2020
362b81a
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 1, 2020
78ea7b8
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 1, 2020
e1f8b56
Merge branch '2.4-develop' into 28569_adding_stores_to_store_config
swnsma Jul 1, 2020
4c994bf
Merge branch '2.4-develop' of github.com:magento/magento2 into 28569_…
gallyamov Jul 9, 2020
ad896c5
Merge branch '2.4-develop' into 28569_adding_stores_to_store_config
gallyamov Jul 9, 2020
454695c
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 9, 2020
00fbf7f
Merge branch '28569_adding_stores_to_store_config' of github.com:mage…
gallyamov Jul 9, 2020
3c770e2
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 9, 2020
d9edb5b
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 9, 2020
b23125e
Merge branch '2.4-develop' of github.com:magento/magento2 into 28569_…
gallyamov Jul 10, 2020
0ccadf5
magento/magento2#28569: Multi-store: Missing store codes in relation …
gallyamov Jul 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(ResourceConnection $resource)
}

/**
* Get store by website id
*
* @param int $websiteId
* @return array
*/
Expand All @@ -41,4 +43,29 @@ public function getStoreByWebsiteId($websiteId)
$data = $connection->fetchCol($storeSelect);
return $data;
}

/**
* Get website store data
*
* @param int $websiteId
* @param bool $available
* @return array
*/
public function getWebsiteStores(int $websiteId, bool $available = false): array
{
$connection = $this->resource->getConnection();
$storeTable = $this->resource->getTableName('store');
$storeSelect = $connection->select()->from($storeTable)->where(
'website_id = ?',
$websiteId
);

if ($available) {
$storeSelect = $storeSelect->where(
'is_active = 1'
);
}

return $connection->fetchAll($storeSelect);
}
}
42 changes: 24 additions & 18 deletions app/code/Magento/Store/Model/Service/StoreConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Store\Model\Service;

/**
* Allows to get store config
*/
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Api\Data\StoreConfigInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\Data\StoreConfig;
use Magento\Store\Model\Data\StoreConfigFactory;
use Magento\Store\Model\ResourceModel\Store\CollectionFactory;
use Magento\Store\Model\Store;

class StoreConfigManager implements \Magento\Store\Api\StoreConfigManagerInterface
{
/**
* @var \Magento\Store\Model\ResourceModel\Store\CollectionFactory
* @var CollectionFactory
*/
protected $storeCollectionFactory;

/**
* @var \Magento\Store\Model\Data\StoreConfigFactory
* @var StoreConfigFactory
*/
protected $storeConfigFactory;

/**
* Core store config
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var ScopeConfigInterface
*/
protected $scopeConfig;

Expand All @@ -41,25 +47,25 @@ class StoreConfigManager implements \Magento\Store\Api\StoreConfigManagerInterfa
];

/**
* @param \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Store\Model\Data\StoreConfigFactory $storeConfigFactory
* @param CollectionFactory $storeCollectionFactory
* @param ScopeConfigInterface $scopeConfig
* @param StoreConfigFactory $storeConfigFactory
*/
public function __construct(
\Magento\Store\Model\ResourceModel\Store\CollectionFactory $storeCollectionFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\Data\StoreConfigFactory $storeConfigFactory
CollectionFactory $storeCollectionFactory,
ScopeConfigInterface $scopeConfig,
StoreConfigFactory $storeConfigFactory
) {
$this->storeCollectionFactory = $storeCollectionFactory;
$this->scopeConfig = $scopeConfig;
$this->storeConfigFactory = $storeConfigFactory;
}

/**
* Get store configs
* Get store configurations
*
* @param string[] $storeCodes list of stores by store codes, will return all if storeCodes is not set
* @return \Magento\Store\Api\Data\StoreConfigInterface[]
* @return StoreConfigInterface[]
*/
public function getStoreConfigs(array $storeCodes = null)
{
Copy link
Contributor

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

Expand All @@ -76,14 +82,14 @@ public function getStoreConfigs(array $storeCodes = null)
}

/**
* Get store config
* Get store specific configs
*
* @param \Magento\Store\Model\Store $store
* @return \Magento\Store\Api\Data\StoreConfigInterface
* @param Store|StoreInterface $store
* @return StoreConfigInterface
*/
protected function getStoreConfig($store)
{
/** @var \Magento\Store\Model\Data\StoreConfig $storeConfig */
/** @var StoreConfig $storeConfig */
$storeConfig = $this->storeConfigFactory->create();

$storeConfig->setId($store->getId())
Expand Down
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
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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(),
Expand All @@ -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(),
Copy link
Contributor

@cpartica cpartica Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please respond to this question:
what is the difference between between getSecureBaseStaticUrl and getBaseStaticUrl?
shouldn't this change along with magento setting to always use secure or not?
Does getBaseStaticUrl guarantee this? (same for the other urls)

'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()));
}

/**
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/StoreGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See COPYING.txt for license details.
type Query {
storeConfig : StoreConfig @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\StoreConfigResolver") @doc(description: "The store config query") @cache(cacheable: false)
availableStores: [StoreConfig] @resolver(class: "Magento\\StoreGraphQl\\Model\\Resolver\\AvailableStoresResolver") @doc(description: "Get a list of available store views and their config information.")
}

type Website @doc(description: "Website is deprecated because it is should not be used on storefront. The type contains information about a website") {
Expand Down
Loading