* @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\OrderState\CommandHandler; use PrestaShop\PrestaShop\Core\Domain\OrderState\Command\BulkDeleteOrderStateCommand; use PrestaShop\PrestaShop\Core\Domain\OrderState\CommandHandler\BulkDeleteOrderStateHandlerInterface; use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\BulkDeleteOrderStateException; use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\OrderStateException; /** * Handles command which deletes OrderStatees in bulk action */ class BulkDeleteOrderStateHandler extends AbstractOrderStateHandler implements BulkDeleteOrderStateHandlerInterface { /** * {@inheritdoc} * * @throws BulkDeleteOrderStateException */ public function handle(BulkDeleteOrderStateCommand $command): void { $errors = []; foreach ($command->getOrderStateIds() as $orderStateId) { try { $orderState = $this->getOrderState($orderStateId); if (!$this->deleteOrderState($orderState)) { $errors[] = $orderState->id; } } catch (OrderStateException $e) { $errors[] = $orderStateId->getValue(); } } if (!empty($errors)) { throw new BulkDeleteOrderStateException( $errors, 'Failed to delete all of selected order statuses' ); } } }