* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShop\PrestaShop\Adapter\Supplier\CommandHandler; use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\BulkDeleteSupplierCommand; use PrestaShop\PrestaShop\Core\Domain\Supplier\CommandHandler\BulkDeleteSupplierHandlerInterface; use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\CannotDeleteSupplierException; use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierException; /** * Class BulkDeleteSupplierHandler is responsible for deleting multiple suppliers. */ final class BulkDeleteSupplierHandler extends AbstractDeleteSupplierHandler implements BulkDeleteSupplierHandlerInterface { /** * {@inheritdoc} * * @throws SupplierException */ public function handle(BulkDeleteSupplierCommand $command) { foreach ($command->getSupplierIds() as $supplierId) { try { $this->removeSupplier($supplierId); } catch (SupplierException $e) { if (SupplierException::class === get_class($e)) { throw new CannotDeleteSupplierException(sprintf('Cannot delete Supplier object with id "%s".', $supplierId->getValue()), CannotDeleteSupplierException::FAILED_BULK_DELETE); } throw $e; } } } }