6 declare(strict_types=1);
14 use Magento\InventoryApi\Api\Data\StockInterfaceFactory;
15 use Psr\Log\LoggerInterface;
25 private $stockResource;
30 private $stockFactory;
44 StockInterfaceFactory $stockFactory,
45 LoggerInterface $logger
47 $this->stockResource = $stockResource;
55 public function execute(
int $stockId)
58 $stock = $this->stockFactory->create();
61 if (
null ===
$stock->getStockId()) {
64 'There is no stock with "%fieldValue" for "%fieldName". Verify and try again.',
67 'fieldValue' => $stockId
74 $this->stockResource->delete(
$stock);
75 }
catch (\Exception $e) {
76 $this->logger->error($e->getMessage());
77 throw new CouldNotDeleteException(
__(
'Could not delete Stock'), $e);
__construct(StockResourceModel $stockResource, StockInterfaceFactory $stockFactory, LoggerInterface $logger)