nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.08k stars 5.19k forks source link

Bug with AutomaticallyAddRequiredProducts when RequireOtherProducts is disabled #7206

Closed RomanovM closed 1 month ago

RomanovM commented 1 month ago

nopCommerce version: 4.70

Example You configured RequireOtherProducts - True RequiredProductIds - the list of products AutomaticallyAddRequiredProducts - True Save.

After it you disabled RequireOtherProducts - False

Nopcommerce will try to add the required products in the shopping cart. It doesn't check the RequireOtherProducts

The fix is to add the checking RequireOtherProducts The File ShoppingCartService.cs

 async Task addRequiredProductsToCartAsync(int qty = 0)
 {
     if (!product.RequireOtherProducts)
         return;
     //get these required products
     var requiredProducts = await _productService.GetProductsByIdsAsync(_productService.ParseRequiredProductIds(product));
     if (!requiredProducts.Any())
         return; 
     var finalRequiredProducts = requiredProducts.GroupBy(p => p.Id)
         .Select(g => new { Product = g.First(), Count = g.Count() });

Source: https://www.nopcommerce.com/boards/topic/99131/bug-with-adding-required-products

exileDev commented 1 month ago

Closed #7206