* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Adapter\Store\CommandHandler; use PrestaShop\PrestaShop\Core\Domain\Store\Command\BulkUpdateStoreStatusCommand; use PrestaShop\PrestaShop\Core\Domain\Store\CommandHandler\BulkUpdateStoreStatusHandlerInterface; use PrestaShop\PrestaShop\Core\Domain\Store\Exception\CannotToggleStoreStatusException; use PrestaShop\PrestaShop\Core\Domain\Store\Repository\StoreRepository; /** * Handles command that toggle store status */ class BulkUpdateStoreStatusHandler implements BulkUpdateStoreStatusHandlerInterface { /** * @var StoreRepository */ private $storeRepository; public function __construct(StoreRepository $storeRepository) { $this->storeRepository = $storeRepository; } /** * {@inheritdoc} */ public function handle(BulkUpdateStoreStatusCommand $command): void { foreach ($command->getStoreIds() as $storeId) { $store = $this->storeRepository->get($storeId); $store->active = $command->getExpectedStatus(); $this->storeRepository->partialUpdate( $store, ['active'], CannotToggleStoreStatusException::BULK_TOGGLE ); } } }