0

Currently when I am creating a new configurable product, it is by default set to out of stock, even though I have added quantity to each of the configurable products. To set the product as in stock I have goto each of the products and change the stock status. Is there any way to set the configurable product as in stock while creating the product itself. I am using Magento 2.3.3

2
  • are you using \Magento\Catalog\Model\ProductFactory to create a new paroduct ? Mar 9, 2020 at 12:02
  • I am not sure, I am doing it through admin. Mar 9, 2020 at 12:47

1 Answer 1

0

Try creating like this.

// \Magento\Catalog\Model\ProductFactory $product

$product = $this->product->create();
//set data you want to set here
$product->setMetaTitle($name);
$product->setMetaKeyword($name);
$product->setMetaDescription($description);
$product->setPrice((int)$price);

$product->setStockData([
                    'use_config_manage_stock' => 1,
                    'manage_stock' => 1,
                    'is_in_stock' => 1,
                    'qty' => (int)$qty
                ]);
$product->getResource()->save($product);

$productId = $product->getEntityId();

Hope this will help you !!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.