Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Recommended products - add operation insert/delete from product service

KrzysztofPajak2df845241260
diff --git a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
index a77f95039..14a0983ee 100644
--- a/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Interfaces/Products/IProductService.cs
@@ -273,6 +273,22 @@ namespace Grand.Business.Catalog.Interfaces.Products
#endregion
+ #region Recommmended products
+
+ /// <summary>
+ /// Inserts a recommended product
+ /// </summary>
+ /// <param name="recommendedProduct">Recommended product</param>
+ Task InsertRecommendedProduct(string productId, string recommendedProductId);
+
+ /// <summary>
+ /// Deletes a recommended product
+ /// </summary>
+ /// <param name="recommendedProduct">Recommended identifier</param>
+ Task DeleteRecommendedProduct(string productId, string recommendedProductId);
+
+ #endregion
+
#region Bundle products
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
index 2f077b889..23d687d21 100644
--- a/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Products/ProductService.cs
@@ -897,6 +897,47 @@ namespace Grand.Business.Catalog.Services.Products
#endregion
+ #region Recommmended products
+
+ /// <summary>
+ /// Inserts a recommended product
+ /// </summary>
+ /// <param name="recommendedProduct">Recommended product</param>
+ public virtual async Task InsertRecommendedProduct(string productId, string recommendedProductId)
+ {
+ if (productId == null)
+ throw new ArgumentNullException(nameof(productId));
+
+ if (recommendedProductId == null)
+ throw new ArgumentNullException(nameof(recommendedProductId));
+
+ await _productRepository.AddToSet(productId, x => x.RecommendedProduct, recommendedProductId);
+
+ //cache
+ await _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));
+
+ }
+
+ /// <summary>
+ /// Deletes a recommended product
+ /// </summary>
+ /// <param name="recommendedProduct">Recommended identifier</param>
+ public virtual async Task DeleteRecommendedProduct(string productId, string recommendedProductId)
+ {
+ if (productId == null)
+ throw new ArgumentNullException(nameof(productId));
+
+ if (recommendedProductId == null)
+ throw new ArgumentNullException(nameof(recommendedProductId));
+
+ await _productRepository.Pull(productId, x => x.RecommendedProduct, recommendedProductId);
+
+ //cache
+ await _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, productId));
+ }
+
+ #endregion
+
#region Tier prices