0

I am creating new import module and I have issue with new created Product. Product doesn't want to create:

In StockRegistry.php line 194:

  The Product with the "13.111.116" SKU doesn't exist.  

My code is:

$this->state->setAreaCode(Area::AREA_FRONTEND);
/** @var Product $product */
$product = $this->productFactory->create();
$sku = $item->getSku();
$product->setSku($sku);
$description = $item->getDescription();
$name = explode(',', $description);
if (key_exists(0, $name)) {
    $product->setName($name[0]);
}
$product->setDescription($description);
$product->setPrice($item->getRecommendedPriceAmount());
$product->setStatus(Status::STATUS_ENABLED);
$product->setAttributeSetId(4);
$product->setTypeId(Type::TYPE_SIMPLE);
$product->setVisibility(Visibility::VISIBILITY_BOTH);
$qty = $item->getAvailableQuantity();
$isAvailable = ($qty > 0 && strcmp($item->getAvailabilityCode(), 'available') === 0);
$extensionAttributes = $product->getExtensionAttributes();
$extensionAttributes->setWebsiteIds([1]);
/** @var StockItemInterface $stockItem */
$stockItem = $extensionAttributes->getStockItem() ?: $this->stockItemInterfaceFactory->create();
$stockItem->setQty($qty);
$stockItem->setIsInStock($isAvailable);
$extensionAttributes->setStockItem($stockItem);
$product->setExtensionAttributes($extensionAttributes);
$this->productRepository->save($product, true);

I am getting exception on save step. Adding product via API is working. I think it can be problem with AreaCode or MySQL. If I save via Product Resource Model, I am getting Lock wait timeout exceeded.

Maybe some one know solution. I tried different ways to save

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.