Products changing to Unpublished after order

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
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
2 years ago
Change line 166 in ProductServices.cs from

    product.Published = !stockDec && stockInc;

to

    product.Published = !stockDec && (stockInc || product.Published);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.