Products changing to Unpublished after order

Hace 2 meses
Hi Support,
I have upgraded from 3.90 to 4.40.  For products that have inventory tracking turned on and also have the Low Stock Activity set to Unpublish, they will unpublish after each order even though they still have quantity greater than zero.

Here is a link to the inventory tracking:
https://www.birdbraindesigns.net/nopcommerce-error

This is for the following product:
https://www.birdbraindesigns.net/just-be-claus-words-brown-on-natural-mas8424-et

Has anything changed with Inventory Tracking in the new version or is this a problem?

Thanks,

Jeff
Hace 2 meses
Minimum stock qty controls the Low stock activity options
So when stock goes below Minimum stock qty it will either
Do nothing , Disable Buy Button or Unpublish depending on the option selected
See https://docs.nopcommerce.com/en/running-your-store/order-management/inventory-management.html
Hace un mes
The problem is that the Stock quantity is 12 and the minimum stock quantity is zero.  The product should stay published until the stock quantity gets to zero, but instead it unpublishes each time someone makes a purchase.

You can see my settings using the link below:
https://www.birdbraindesigns.net/nopcommerce-error

Thanks,
Jeff
Hace un mes
We had the same problem...
The problem is in Libraries\Nop.Services\Catalog\ProductService.cs lines 152-173

protected virtual async Task ApplyLowStockActivityAsync(Product product, int totalStock)
        {
            var stockDec = product.MinStockQuantity >= totalStock;
            var stockInc = _catalogSettings.PublishBackProductWhenCancellingOrders && product.MinStockQuantity < totalStock;

            switch (product.LowStockActivity)
            {
                case LowStockActivity.DisableBuyButton:
                    product.DisableBuyButton = stockDec && !stockInc;
                    product.DisableWishlistButton = stockDec && !stockInc;
                    await UpdateProductAsync(product);
                    break;

                case LowStockActivity.Unpublish:
                    product.Published = !stockDec && stockInc;
                    await UpdateProductAsync(product);
                    break;

                default:
                    break;
            }
        }

If the setting "catalogsettings.publishbackproductwhencancellingorders" is set to True, then the LowStockActivity products don't get unpublished, otherwise the line
product.Published = !stockDec && stockInc;
always gets evaluated to False, thus unpublishing the product.
I think the formula should include the previous value of Published anyways with an or operator...

....
    case LowStockActivity.Unpublish:
      product.Published = product.Published || (!stockDec && stockInc);
      await UpdateProductAsync(product);
....


So the quick and dirty solution is to set catalogsettings.publishbackproductwhencancellingorders to True (and ignoring the actual function of the setting) or the right way to change the code, update & recompile the website.

edit: it's not so simple... just tried some other input values and it doesn't work if the product is already published... will update the post soon with the correct way
Hace un mes
Change line 166 in ProductServices.cs from

    product.Published = !stockDec && stockInc;

to

    product.Published = !stockDec && (stockInc || product.Published);