Skip to content

Commit

Permalink
APPS-7209: Fixed message handlers to work with Dynamic Multi Store (#…
Browse files Browse the repository at this point in the history
…10397)

APPS-7209 Fixed message handlers to work with Dynamic Multi Store
  • Loading branch information
oleksander-kiiashko authored Aug 21, 2023
1 parent f8d9f41 commit 4cae3bc
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Spryker/Zed/Store/Business/StoreBusinessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public function createMessageTransferValidator(): MessageValidatorInterface
{
return new MessageValidator(
$this->createStoreReader(),
$this->getIsDynamicStoreModeEnabled(),
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Spryker/Zed/Store/Business/StoreFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Spryker/Zed/Store/Business/StoreFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/Spryker/Zed/Store/Business/Validator/MessageValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -148,12 +156,4 @@ protected function getStorePropelQuery(): SpyStoreQuery
{
return SpyStoreQuery::create();
}

/**
* @return bool
*/
protected function isDynamicStoreEnabled(): bool
{
return (bool)getenv('SPRYKER_DYNAMIC_STORE_MODE');
}
}
8 changes: 6 additions & 2 deletions tests/SprykerTest/Zed/Store/Business/StoreFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit 4cae3bc

Please sign in to comment.