bigbridge-nl / product-import

Fast product import library for Magento 2
MIT License
113 stars 32 forks source link

How to set out of stock threshold for backorders ? #42

Closed jchirschy closed 3 years ago

jchirschy commented 3 years ago

Hello,

I'm trying to use the importer to set the Out-of-Stock Threshold field. Actually, I'm trying to set a negative value per product. I know there is something like :

$stock = $product->defaultStockItem();
$stock->setBackorders(ProductStockItem::BACKORDERS_ALLOW_QTY_BELOW_0);
$stock->setUseConfigBackorders(false);

But I didn't see anything concerning this special use case. Did I miss something or could you indicate me how to accomplish this ?

By the way, what does $stock->setUseConfigBackorders exactly do ?

Thanks in advance for you help.

patrick-bigbridge commented 3 years ago

Hi,

Yes this is not very clear. What you need to use for Out of stock threshold is

$stock->setMinimumQuantity(-10);

"minimum quantity" is the internal name of the field (min_qty).

setUseConfigBackorders tells the system whether it should use the system's generic config value or not. Only if this field is set to false, will the product specific value be used.

jchirschy commented 3 years ago

Thanks @patrick-bigbridge ,

Actually, when you look at csv import file from the dashboard, there are two fields out_of_stock_qty and allow_backorders. Does $stock->setMinimumQuantity(-10); set the same field as the csv out_of_stock_qty one ?

Thanks.

garfix commented 3 years ago

Yes, the mapping can be found here:

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/CatalogImportExport/Model/Import/Product.php#L344

jchirschy commented 3 years ago

thanks @garfix