From 4cae3bcb065468ea0d32ea3a2e4cb8c624d56205 Mon Sep 17 00:00:00 2001 From: Oleksandr Kiiashko <80702205+oleksander-kiiashko@users.noreply.github.com> Date: Mon, 21 Aug 2023 18:35:01 +0300 Subject: [PATCH] APPS-7209: Fixed message handlers to work with Dynamic Multi Store (#10397) APPS-7209 Fixed message handlers to work with Dynamic Multi Store --- .../Zed/Store/Business/StoreBusinessFactory.php | 1 + src/Spryker/Zed/Store/Business/StoreFacade.php | 2 ++ .../Zed/Store/Business/StoreFacadeInterface.php | 3 +++ .../Business/Validator/MessageValidator.php | 12 +++++++++++- .../StoreReferenceMessageValidatorPlugin.php | 2 ++ .../Store/_support/Helper/StoreDataHelper.php | 16 ++++++++-------- .../Zed/Store/Business/StoreFacadeTest.php | 8 ++++++-- 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Spryker/Zed/Store/Business/StoreBusinessFactory.php b/src/Spryker/Zed/Store/Business/StoreBusinessFactory.php index ba878e2..cf1abc4 100644 --- a/src/Spryker/Zed/Store/Business/StoreBusinessFactory.php +++ b/src/Spryker/Zed/Store/Business/StoreBusinessFactory.php @@ -275,6 +275,7 @@ public function createMessageTransferValidator(): MessageValidatorInterface { return new MessageValidator( $this->createStoreReader(), + $this->getIsDynamicStoreModeEnabled(), ); } diff --git a/src/Spryker/Zed/Store/Business/StoreFacade.php b/src/Spryker/Zed/Store/Business/StoreFacade.php index a2f86d4..0aa77b3 100644 --- a/src/Spryker/Zed/Store/Business/StoreFacade.php +++ b/src/Spryker/Zed/Store/Business/StoreFacade.php @@ -305,6 +305,8 @@ public function expandAccessTokenRequest(AccessTokenRequestTransfer $accessToken * * @api * + * @deprecated Will be removed without replacement. + * * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $messageTransfer * * @return \Generated\Shared\Transfer\MessageValidationResponseTransfer diff --git a/src/Spryker/Zed/Store/Business/StoreFacadeInterface.php b/src/Spryker/Zed/Store/Business/StoreFacadeInterface.php index 06fb5c9..2ea2012 100644 --- a/src/Spryker/Zed/Store/Business/StoreFacadeInterface.php +++ b/src/Spryker/Zed/Store/Business/StoreFacadeInterface.php @@ -263,11 +263,14 @@ public function expandAccessTokenRequest(AccessTokenRequestTransfer $accessToken /** * Specification: + * - Validates only if dynamic store is disabled, otherwise return `MessageValidationResponse.isValid` === true. * - Validates if `storeReference` from the message matches `storeReference` of one the configured stores. * - Executes stack of {@link \Spryker\Zed\StoreExtension\Dependency\Plugin\StoreCollectionExpanderPluginInterface} plugins. * * @api * + * @deprecated Will be removed without replacement. + * * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $messageTransfer * * @return \Generated\Shared\Transfer\MessageValidationResponseTransfer diff --git a/src/Spryker/Zed/Store/Business/Validator/MessageValidator.php b/src/Spryker/Zed/Store/Business/Validator/MessageValidator.php index 9d3c2f4..c9a0462 100644 --- a/src/Spryker/Zed/Store/Business/Validator/MessageValidator.php +++ b/src/Spryker/Zed/Store/Business/Validator/MessageValidator.php @@ -27,12 +27,18 @@ class MessageValidator implements MessageValidatorInterface */ protected $storeReader; + /** + * @var bool + */ + protected $isDynamicMultiStoreEnabled; + /** * @param \Spryker\Zed\Store\Business\Model\StoreReaderInterface $storeReader */ - public function __construct(StoreReaderInterface $storeReader) + public function __construct(StoreReaderInterface $storeReader, bool $isDynamicMultiStoreEnabled) { $this->storeReader = $storeReader; + $this->isDynamicMultiStoreEnabled = $isDynamicMultiStoreEnabled; } /** @@ -44,6 +50,10 @@ public function validate(TransferInterface $messageTransfer): MessageValidationR { $messageValidationResponse = new MessageValidationResponseTransfer(); + if ($this->isDynamicMultiStoreEnabled) { + return $messageValidationResponse->setIsValid(true); + } + if (!method_exists($messageTransfer, 'getMessageAttributes')) { $this->getLogger()->error( sprintf('MessageTransfer `%s` must have method getMessageAttributes().', get_class($messageTransfer)), diff --git a/src/Spryker/Zed/Store/Communication/Plugin/MessageBroker/StoreReferenceMessageValidatorPlugin.php b/src/Spryker/Zed/Store/Communication/Plugin/MessageBroker/StoreReferenceMessageValidatorPlugin.php index 7d34f8a..d2672c4 100644 --- a/src/Spryker/Zed/Store/Communication/Plugin/MessageBroker/StoreReferenceMessageValidatorPlugin.php +++ b/src/Spryker/Zed/Store/Communication/Plugin/MessageBroker/StoreReferenceMessageValidatorPlugin.php @@ -12,6 +12,8 @@ use Spryker\Zed\MessageBrokerExtension\Dependency\Plugin\MessageValidatorPluginInterface; /** + * @deprecated Will be removed without replacement. + * * @method \Spryker\Zed\Store\Business\StoreFacadeInterface getFacade() * @method \Spryker\Zed\Store\StoreConfig getConfig() * @method \Spryker\Zed\Store\Communication\StoreCommunicationFactory getFactory() diff --git a/tests/SprykerTest/Shared/Store/_support/Helper/StoreDataHelper.php b/tests/SprykerTest/Shared/Store/_support/Helper/StoreDataHelper.php index 1c11fe6..aef6353 100644 --- a/tests/SprykerTest/Shared/Store/_support/Helper/StoreDataHelper.php +++ b/tests/SprykerTest/Shared/Store/_support/Helper/StoreDataHelper.php @@ -89,6 +89,14 @@ public function getAllowedStore(): StoreTransfer return new StoreTransfer(); } + /** + * @return bool + */ + public function isDynamicStoreEnabled(): bool + { + return (bool)getenv('SPRYKER_DYNAMIC_STORE_MODE'); + } + /** * @return \Spryker\Zed\Store\Business\StoreFacadeInterface */ @@ -148,12 +156,4 @@ protected function getStorePropelQuery(): SpyStoreQuery { return SpyStoreQuery::create(); } - - /** - * @return bool - */ - protected function isDynamicStoreEnabled(): bool - { - return (bool)getenv('SPRYKER_DYNAMIC_STORE_MODE'); - } } diff --git a/tests/SprykerTest/Zed/Store/Business/StoreFacadeTest.php b/tests/SprykerTest/Zed/Store/Business/StoreFacadeTest.php index a601607..7d80294 100644 --- a/tests/SprykerTest/Zed/Store/Business/StoreFacadeTest.php +++ b/tests/SprykerTest/Zed/Store/Business/StoreFacadeTest.php @@ -515,7 +515,9 @@ public function testMessageTransferValidationFailsWhenCurrentStoreIsMissing(): v $messageValidationResponseTransfer = $this->tester->getFacade()->validateMessageTransfer($messageTransfer); // Assert - $this->assertFalse($messageValidationResponseTransfer->getIsValid()); + $this->tester->isDynamicStoreEnabled() + ? $this->assertTrue($messageValidationResponseTransfer->getIsValid()) + : $this->assertFalse($messageValidationResponseTransfer->getIsValid()); } /** @@ -532,7 +534,9 @@ public function testMessageTransferValidationFailsWhenStoreReferenceMismatch(): $messageValidationResponseTransfer = $this->tester->getFacade()->validateMessageTransfer($messageTransfer); // Assert - $this->assertFalse($messageValidationResponseTransfer->getIsValid()); + $this->tester->isDynamicStoreEnabled() + ? $this->assertTrue($messageValidationResponseTransfer->getIsValid()) + : $this->assertFalse($messageValidationResponseTransfer->getIsValid()); } /**