0

I'm trying to update some code that i have with deprecated methods and i want to use the new inventory API but i can't save the source item. After load or create a new product with the product repository i try to update the the status and stock with the new interfaces SourceItem and sourceItemSave but i receive a validation error

In SourceItemsSaveHandler.php line 71:

After save the product i have this code:

try {
                    $this->productRepository->save($product);

                } catch (\Exception $exception) {
                    $logger->info($sku . " Deu merda a salvar: Exception:  " . $exception->getMessage());
                    print_r($exception->getMessage());
                }
                //STOCK
                $sourceItem = $this->getSourceItemsBySku->execute($product->getSku());
                if (count($sourceItem) == 0){
                    $this->sourceItem->setSku($product->getSku());
                    $this->sourceItem->setQuantity(3);
                    $this->sourceItem->setStatus(1);
                    $this->sourceItem->setSourceCode(null);
                    $this->sourceItemsSave->execute(array($this->sourceItem));

                }

Is there any official way to save quantity and status of the product in 2.3?

Thanks for your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.