stockValidator = $stockValidator; $this->stockResource = $stockResource; $this->logger = $logger; } /** * @inheritdoc */ public function execute(StockInterface $stock): int { $validationResult = $this->stockValidator->validate($stock); if (!$validationResult->isValid()) { throw new ValidationException(__('Validation Failed'), null, 0, $validationResult); } try { $this->stockResource->save($stock); return (int)$stock->getStockId(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Stock'), $e); } } }