stockFactory = $stockFactory; $this->stockRepository = $stockRepository; $this->stockSourceLinkProcessor = $stockSourceLinkProcessor; $this->dataObjectHelper = $dataObjectHelper; $this->eventManager = $eventManager; } /** * Save stock process action * * @param int|null $stockId * @param RequestInterface $request * @return int */ public function process($stockId, RequestInterface $request): int { if (null === $stockId) { $stock = $this->stockFactory->create(); } else { $stock = $this->stockRepository->get($stockId); } $requestData = $request->getParams(); $this->dataObjectHelper->populateWithArray($stock, $requestData['general'], StockInterface::class); $this->eventManager->dispatch( 'controller_action_inventory_populate_stock_with_data', [ 'request' => $request, 'stock' => $stock, ] ); $stockId = $this->stockRepository->save($stock); $this->eventManager->dispatch( 'save_stock_controller_processor_after_save', [ 'request' => $request, 'stock' => $stock, ] ); $assignedSources = isset($requestData['sources']['assigned_sources']) && is_array($requestData['sources']['assigned_sources']) ? $requestData['sources']['assigned_sources'] : []; $this->stockSourceLinkProcessor->process($stockId, $assignedSources); return $stockId; } }