Skip to content

Commit

Permalink
TE-10179 Replace direct usage of Store.php with corresponding Facades…
Browse files Browse the repository at this point in the history
… and Get rid of APPLICATION_STORE global constant usage. (#8929)

TE-10179 Dynamic Store | Backend Modules
  • Loading branch information
dmytro-dymarchuk committed Jan 4, 2022
1 parent e638624 commit be3ed49
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 15 deletions.
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -10,15 +10,17 @@
"spryker/glossary": "^3.0.0",
"spryker/gui": "^3.33.0",
"spryker/kernel": "^3.30.0",
"spryker/key-builder": "^1.0.0",
"spryker/key-builder": "^1.1.0",
"spryker/locale": "^3.0.0",
"spryker/product": "^5.0.0 || ^6.0.0",
"spryker/product-page-search-extension": "^1.1.0",
"spryker/propel-orm": "^1.0.0",
"spryker/search": "^6.0.0 || ^7.0.0 || ^8.0.0",
"spryker/storage": "^3.0.0",
"spryker/store": "^1.4.0",
"spryker/symfony": "^3.0.0",
"spryker/touch": "^3.0.0 || ^4.0.0",
"spryker/transfer": "^3.25.0",
"spryker/util-data-reader": "^1.0.0"
},
"require-dev": {
Expand Down
5 changes: 5 additions & 0 deletions dependency.json
@@ -0,0 +1,5 @@
{
"include": {
"spryker/transfer": "Provides transfer objects decimal property type functionality."
}
}
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Client\ProductSearch\Dependency\Client;

class ProductSearchToLocaleClientBridge implements ProductSearchToLocaleClientInterface
{
/**
* @var \Spryker\Client\Locale\LocaleClientInterface
*/
protected $localeClient;

/**
* @param \Spryker\Client\Locale\LocaleClientInterface $localeClient
*/
public function __construct($localeClient)
{
$this->localeClient = $localeClient;
}

/**
* @return string
*/
public function getCurrentLocale(): string
{
return $this->localeClient->getCurrentLocale();
}
}
@@ -0,0 +1,16 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Client\ProductSearch\Dependency\Client;

interface ProductSearchToLocaleClientInterface
{
/**
* @return string
*/
public function getCurrentLocale();
}
@@ -0,0 +1,34 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Client\ProductSearch\Dependency\Client;

use Generated\Shared\Transfer\StoreTransfer;

class ProductSearchToStoreClientBridge implements ProductSearchToStoreClientInterface
{
/**
* @var \Spryker\Client\Store\StoreClientInterface
*/
protected $storeClient;

/**
* @param \Spryker\Client\Store\StoreClientInterface $storeClient
*/
public function __construct($storeClient)
{
$this->storeClient = $storeClient;
}

/**
* @return \Generated\Shared\Transfer\StoreTransfer
*/
public function getCurrentStore(): StoreTransfer
{
return $this->storeClient->getCurrentStore();
}
}
@@ -0,0 +1,16 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Client\ProductSearch\Dependency\Client;

interface ProductSearchToStoreClientInterface
{
/**
* @return \Generated\Shared\Transfer\StoreTransfer
*/
public function getCurrentStore();
}
Expand Up @@ -40,10 +40,12 @@ protected function getKey()
{
$currentLocale = $this->getCurrentLocale();

$storeName = $this->getFactory()->getStoreClient()->getCurrentStore()->getNameOrFail();

$key = $this
->getFactory()
->createProductSearchConfigExtensionKeyBuilder()
->generateKey([], $currentLocale);
->generateKey([], $currentLocale, $storeName);

return $key;
}
Expand All @@ -55,7 +57,7 @@ protected function getCurrentLocale()
{
$locale = $this
->getFactory()
->getStore()
->getLocaleClient()
->getCurrentLocale();

return $locale;
Expand Down
Expand Up @@ -9,14 +9,19 @@

use Spryker\Client\Kernel\AbstractDependencyProvider;
use Spryker\Client\Kernel\Container;
use Spryker\Shared\Kernel\Store;
use Spryker\Client\ProductSearch\Dependency\Client\ProductSearchToLocaleClientBridge;

class ProductSearchDependencyProvider extends AbstractDependencyProvider
{
/**
* @var string
*/
public const STORE = 'store';
public const CLIENT_LOCALE = 'CLIENT_LOCALE';

/**
* @var string
*/
public const CLIENT_STORE = 'CLIENT_STORE';

/**
* @var string
Expand All @@ -32,8 +37,9 @@ public function provideServiceLayerDependencies(Container $container)
{
$container = parent::provideServiceLayerDependencies($container);

$container = $this->provideStore($container);
$container = $this->addLocaleClient($container);
$container = $this->addStorageClient($container);
$container = $this->addStoreClient($container);

return $container;
}
Expand All @@ -43,10 +49,10 @@ public function provideServiceLayerDependencies(Container $container)
*
* @return \Spryker\Client\Kernel\Container
*/
protected function provideStore(Container $container)
protected function addStorageClient(Container $container)
{
$container->set(static::STORE, function () {
return Store::getInstance();
$container->set(static::CLIENT_STORAGE, function (Container $container) {
return $container->getLocator()->storage()->client();
});

return $container;
Expand All @@ -57,10 +63,26 @@ protected function provideStore(Container $container)
*
* @return \Spryker\Client\Kernel\Container
*/
protected function addStorageClient(Container $container)
protected function addStoreClient(Container $container): Container
{
$container->set(static::CLIENT_STORAGE, function (Container $container) {
return $container->getLocator()->storage()->client();
$container->set(static::CLIENT_STORE, function (Container $container) {
return $container->getLocator()->store()->client();
});

return $container;
}

/**
* @param \Spryker\Client\Kernel\Container $container
*
* @return \Spryker\Client\Kernel\Container
*/
protected function addLocaleClient(Container $container): Container
{
$container->set(static::CLIENT_LOCALE, function (Container $container) {
return new ProductSearchToLocaleClientBridge(
$container->getLocator()->locale()->client(),
);
});

return $container;
Expand Down
16 changes: 13 additions & 3 deletions src/Spryker/Client/ProductSearch/ProductSearchFactory.php
Expand Up @@ -8,6 +8,8 @@
namespace Spryker\Client\ProductSearch;

use Spryker\Client\Kernel\AbstractFactory;
use Spryker\Client\ProductSearch\Dependency\Client\ProductSearchToLocaleClientInterface;
use Spryker\Client\ProductSearch\Dependency\Client\ProductSearchToStoreClientInterface;
use Spryker\Shared\ProductSearch\Code\KeyBuilder\ProductSearchConfigExtensionKeyBuilder;

class ProductSearchFactory extends AbstractFactory
Expand All @@ -29,10 +31,18 @@ public function getStorageClient()
}

/**
* @return \Spryker\Shared\Kernel\Store
* @return \Spryker\Client\ProductSearch\Dependency\Client\ProductSearchToStoreClientInterface
*/
public function getStore()
public function getStoreClient(): ProductSearchToStoreClientInterface
{
return $this->getProvidedDependency(ProductSearchDependencyProvider::STORE);
return $this->getProvidedDependency(ProductSearchDependencyProvider::CLIENT_STORE);
}

/**
* @return \Spryker\Client\ProductSearch\Dependency\Client\ProductSearchToLocaleClientInterface
*/
public function getLocaleClient(): ProductSearchToLocaleClientInterface
{
return $this->getProvidedDependency(ProductSearchDependencyProvider::CLIENT_LOCALE);
}
}
Expand Up @@ -72,4 +72,8 @@
<transfer name="PageMap">
</transfer>

<transfer name="Store">
<property name="name" type="string"/>
</transfer>

</transfers>

0 comments on commit be3ed49

Please sign in to comment.