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.

Extend DiscountRule (add the Metadata field), in the discount entity

supportba88a0eb926b
diff --git a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
index 60bb23edf..adf252d25 100644
--- a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
@@ -157,11 +157,6 @@ namespace Grand.Business.Catalog.Services.Discounts
if (discount == null)
throw new ArgumentNullException(nameof(discount));
- foreach (var req in discount.DiscountRules)
- {
- req.DiscountId = discount.Id;
- }
-
await _discountRepository.UpdateAsync(discount);
await _cacheBase.RemoveByPrefix(CacheKey.DISCOUNTS_PATTERN_KEY);
@@ -190,32 +185,7 @@ namespace Grand.Business.Catalog.Services.Discounts
//event notification
await _mediator.EntityDeleted(discount);
}
-
- /// <summary>
- /// Delete discount requirement
- /// </summary>
- /// <param name="discountRequirement">Discount requirement</param>
- public virtual async Task DeleteDiscountRequirement(DiscountRule discountRequirement)
- {
- if (discountRequirement == null)
- throw new ArgumentNullException(nameof(discountRequirement));
-
- var discount = await _discountRepository.GetByIdAsync(discountRequirement.DiscountId);
- if (discount == null)
- throw new ArgumentNullException(nameof(discount));
- var req = discount.DiscountRules.FirstOrDefault(x => x.Id == discountRequirement.Id);
- if (req == null)
- throw new ArgumentNullException(nameof(req));
-
- discount.DiscountRules.Remove(req);
- await UpdateDiscount(discount);
-
- await _cacheBase.RemoveByPrefix(CacheKey.DISCOUNTS_PATTERN_KEY);
-
- //event notification
- await _mediator.EntityDeleted(discountRequirement);
- }
-
+
/// <summary>
/// Load discount by system name
/// </summary>
@@ -564,7 +534,8 @@ namespace Grand.Business.Catalog.Services.Discounts
var ruleRequest = new DiscountRuleValidationRequest
{
DiscountRequirementId = req.Id,
- DiscountId = req.DiscountId,
+ MetaData = req.Metadata,
+ DiscountId = discount.Id,
Customer = customer,
Store = _workContext.CurrentStore
};
diff --git a/src/Business/Grand.Business.Core/Interfaces/Catalog/Discounts/IDiscountService.cs b/src/Business/Grand.Business.Core/Interfaces/Catalog/Discounts/IDiscountService.cs
index f38b966c2..cf1ce1aca 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Catalog/Discounts/IDiscountService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Catalog/Discounts/IDiscountService.cs
@@ -45,12 +45,6 @@ namespace Grand.Business.Core.Interfaces.Catalog.Discounts
/// <param name="discount">Discount</param>
Task DeleteDiscount(Discount discount);
- /// <summary>
- /// Deletes the existing discount requirement
- /// </summary>
- /// <param name="discountRequirement">Discount requirement</param>
- Task DeleteDiscountRequirement(DiscountRule discountRequirement);
-
/// <summary>
/// Loads existing discount provider by system name
/// </summary>
diff --git a/src/Business/Grand.Business.Core/Utilities/Catalog/DiscountRuleValidationRequest.cs b/src/Business/Grand.Business.Core/Utilities/Catalog/DiscountRuleValidationRequest.cs
index c1b44ba95..5e68007a0 100644
--- a/src/Business/Grand.Business.Core/Utilities/Catalog/DiscountRuleValidationRequest.cs
+++ b/src/Business/Grand.Business.Core/Utilities/Catalog/DiscountRuleValidationRequest.cs
@@ -13,6 +13,11 @@ namespace Grand.Business.Core.Utilities.Catalog
/// </summary>
public string DiscountRequirementId { get; set; }
+ /// <summary>
+ /// Gets or sets the metadata
+ /// </summary>
+ public string MetaData { get; set; }
+
/// <summary>
/// Gets or sets the discount ID (identifier)
/// </summary>
diff --git a/src/Core/Grand.Domain/Discounts/DiscountRule.cs b/src/Core/Grand.Domain/Discounts/DiscountRule.cs
index 4f68356c7..bc4a9e573 100644
--- a/src/Core/Grand.Domain/Discounts/DiscountRule.cs
+++ b/src/Core/Grand.Domain/Discounts/DiscountRule.cs
@@ -5,15 +5,15 @@
/// </summary>
public partial class DiscountRule : SubBaseEntity
{
- /// <summary>
- /// Gets or sets the discount identifier
- /// </summary>
- public string DiscountId { get; set; }
-
/// <summary>
/// Gets or sets the discount requirement rule system name
/// </summary>
public string DiscountRequirementRuleSystemName { get; set; }
-
+
+ /// <summary>
+ /// Gets or sets the metadata
+ /// </summary>
+ public string Metadata { get; set; }
+
}
}