3

I am updating a Configurable product to just set quantity.but it keeps showing 0 in admin and not updating it.

$product->setQuantityAndStockStatus(['qty' => 32, 'is_in_stock' => 1]);
2
  • configurable product does not have own Qty and its qty is its child products
    – Amit Bera
    Feb 26, 2019 at 10:37
  • So amit what should i set while saving a configurable product.When i leave configurable blank while saving programmaticly it does not make it out of stock.
    – Anees
    Feb 26, 2019 at 11:19

1 Answer 1

1

Use below code to update stock.

$product->setStockData(array(
    'use_config_manage_stock' => 0,
    'manage_stock'=>1,
    'min_sale_qty'=>1,
    'max_sale_qty'=>1000,
    'is_in_stock' => 1,
    'qty' => '170'
));

Happy coding :)

4
  • Unfortunately its not working.
    – Anees
    Feb 26, 2019 at 9:32
  • Add your entire code
    – Vish V
    Feb 26, 2019 at 9:46
  • can i make product out of stock by putting this code $product->setQuantityAndStockStatus(['qty' => 0, 'is_in_stock' => 0]);
    – Anees
    Feb 26, 2019 at 10:10
  • As i want to out of stock the configurable product
    – Anees
    Feb 26, 2019 at 10:11

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.