Skip to content

Commit

Permalink
#28569: Multi-store: Missing store codes in relation to a group and w…
Browse files Browse the repository at this point in the history
…ebsite

- Replaced interface updates
  • Loading branch information
gallyamov committed Jul 9, 2020
1 parent 4c994bf commit 454695c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 54 deletions.
15 changes: 0 additions & 15 deletions app/code/Magento/Store/Api/Data/StoreConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ public function getCode();
*/
public function setCode($code);

/**
* Get store name
*
* @return string
*/
public function getName();

/**
* Set store code
*
* @param string $name
* @return $this
*/
public function setName($name);

/**
* Get website id of the store
*
Expand Down
22 changes: 0 additions & 22 deletions app/code/Magento/Store/Model/Data/StoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class StoreConfig extends \Magento\Framework\Api\AbstractExtensibleObject implem
{
const KEY_ID = 'id';
const KEY_CODE = 'code';
const KEY_NAME = 'name';
const KEY_WEBSITE_ID = 'website_id';
const KEY_LOCALE = 'locale';
const KEY_BASE_CURRENCY_CODE = 'base_currency_code';
Expand Down Expand Up @@ -73,27 +72,6 @@ public function setCode($code)
return $this->setData(self::KEY_CODE, $code);
}

/**
* Get store name
*
* @return string
*/
public function getName()
{
return $this->_get(self::KEY_NAME);
}

/**
* Get store name
*
* @param string $name
* @return $this
*/
public function setName($name)
{
return $this->setData(self::KEY_NAME, $name);
}

/**
* Get website id of the store
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public function getStoreByWebsiteId($websiteId)
}

/**
* Get website store codes
* Get website store data
*
* @param string $websiteId
* @param bool $available
* @return array
*/
public function getWebsiteStoreCodes(string $websiteId, bool $available = false): array
public function getWebsiteStores(string $websiteId, bool $available = false): array
{
$connection = $this->resource->getConnection();
$storeTable = $this->resource->getTableName('store');
$storeSelect = $connection->select()->from($storeTable, ['code'])->where(
$storeSelect = $connection->select()->from($storeTable)->where(
'website_id = ?',
$websiteId
);
Expand All @@ -66,6 +66,6 @@ public function getWebsiteStoreCodes(string $websiteId, bool $available = false)
);
}

return $connection->fetchCol($storeSelect);
return $connection->fetchAll($storeSelect);
}
}
3 changes: 1 addition & 2 deletions app/code/Magento/Store/Model/Service/StoreConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ protected function getStoreConfig($store)

$storeConfig->setId($store->getId())
->setCode($store->getCode())
->setWebsiteId($store->getWebsiteId())
->setName($store->getName());
->setWebsiteId($store->getWebsiteId());

foreach ($this->configPaths as $methodName => $configPath) {
$configValue = $this->scopeConfig->getValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(
public function getStoreConfigData(StoreInterface $store): array
{
$defaultStoreConfig = $this->storeConfigManager->getStoreConfigs([$store->getCode()]);
return $this->prepareStoreConfigData(current($defaultStoreConfig));
return $this->prepareStoreConfigData(current($defaultStoreConfig), $store->getName());
}

/**
Expand All @@ -77,12 +77,15 @@ public function getStoreConfigData(StoreInterface $store): array
*/
public function getAvailableStoreConfig(string $websiteId): array
{
$websiteStores = $this->storeWebsiteRelation->getWebsiteStoreCodes($websiteId, true);
$storeConfigs = $this->storeConfigManager->getStoreConfigs($websiteStores);
$websiteStores = $this->storeWebsiteRelation->getWebsiteStores($websiteId, true);
$storeCodes = array_column($websiteStores, 'code');

$storeConfigs = $this->storeConfigManager->getStoreConfigs($storeCodes);
$storesConfigData = [];

foreach ($storeConfigs as $storeConfig) {
$storesConfigData[] = $this->prepareStoreConfigData($storeConfig);
$key = array_search($storeConfig->getCode(), array_column($websiteStores, 'code'), true);
$storesConfigData[] = $this->prepareStoreConfigData($storeConfig, $websiteStores[$key]['name']);
}

return $storesConfigData;
Expand All @@ -92,9 +95,10 @@ public function getAvailableStoreConfig(string $websiteId): array
* Prepare store config data
*
* @param StoreConfigInterface $storeConfig
* @param string $storeName
* @return array
*/
private function prepareStoreConfigData(StoreConfigInterface $storeConfig): array
private function prepareStoreConfigData(StoreConfigInterface $storeConfig, string $storeName): array
{
return array_merge([
'id' => $storeConfig->getId(),
Expand All @@ -113,7 +117,7 @@ private function prepareStoreConfigData(StoreConfigInterface $storeConfig): arra
'secure_base_link_url' => $storeConfig->getSecureBaseLinkUrl(),
'secure_base_static_url' => $storeConfig->getSecureBaseStaticUrl(),
'secure_base_media_url' => $storeConfig->getSecureBaseMediaUrl(),
'store_name' => $storeConfig->getName(),
'store_name' => $storeName,
], $this->getExtendedConfigData((int)$storeConfig->getId()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace Magento\GraphQl\Store;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Api\Data\StoreConfigInterface;
use Magento\Store\Api\StoreConfigManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\ResourceModel\Store as StoreResource;
use Magento\Store\Model\Store;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand All @@ -31,13 +31,19 @@ class AvailableStoreConfigTest extends GraphQlAbstract
*/
private $storeConfigManager;

/**
* @var StoreResource
*/
private $storeResource;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->storeConfigManager = $this->objectManager->get(StoreConfigManagerInterface::class);
$this->storeResource = $this->objectManager->get(StoreResource::class);
}

/**
Expand Down Expand Up @@ -140,6 +146,8 @@ public function testNonDefaultWebsiteAvailableStoreConfigs(): void
*/
private function validateStoreConfig(StoreConfigInterface $storeConfig, array $responseConfig): void
{
$store = $this->objectManager->get(Store::class);
$this->storeResource->load($store, $storeConfig->getCode(), 'code');
$this->assertEquals($storeConfig->getId(), $responseConfig['id']);
$this->assertEquals($storeConfig->getCode(), $responseConfig['code']);
$this->assertEquals($storeConfig->getLocale(), $responseConfig['locale']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ public function testGetStoreConfig(): void
QUERY;
$response = $this->graphQlQuery($query);
$this->assertArrayHasKey('storeConfig', $response);
$this->validateStoreConfig($defaultStoreConfig, $response['storeConfig']);
$this->validateStoreConfig($defaultStoreConfig, $response['storeConfig'], $store->getName());
}

/**
* Validate Store Config Data
*
* @param StoreConfigInterface $storeConfig
* @param array $responseConfig
* @param string $storeName
*/
private function validateStoreConfig($storeConfig, $responseConfig): void
{
private function validateStoreConfig(
StoreConfigInterface $storeConfig,
array $responseConfig,
string $storeName
): void {
$this->assertEquals($storeConfig->getId(), $responseConfig['id']);
$this->assertEquals($storeConfig->getCode(), $responseConfig['code']);
$this->assertEquals($storeConfig->getLocale(), $responseConfig['locale']);
Expand Down

0 comments on commit 454695c

Please sign in to comment.