|
12 | 12 | using SmartStore.Services.Customers; |
13 | 13 | using SmartStore.Services.Common; |
14 | 14 | using SmartStore.Services.Configuration; |
| 15 | +using SmartStore.Services.Orders; |
15 | 16 |
|
16 | 17 | namespace SmartStore.Services.Discounts |
17 | 18 | { |
@@ -317,52 +318,55 @@ public virtual bool IsDiscountValid(Discount discount, Customer customer, string |
317 | 318 | } |
318 | 319 |
|
319 | 320 | //check date range |
320 | | - DateTime now = DateTime.UtcNow; |
321 | | - int storeId = _storeContext.CurrentStore.Id; |
| 321 | + var now = DateTime.UtcNow; |
| 322 | + var store = _storeContext.CurrentStore; |
322 | 323 |
|
323 | 324 | if (discount.StartDateUtc.HasValue) |
324 | 325 | { |
325 | | - DateTime startDate = DateTime.SpecifyKind(discount.StartDateUtc.Value, DateTimeKind.Utc); |
| 326 | + var startDate = DateTime.SpecifyKind(discount.StartDateUtc.Value, DateTimeKind.Utc); |
326 | 327 | if (startDate.CompareTo(now) > 0) |
327 | 328 | return false; |
328 | 329 | } |
329 | 330 | if (discount.EndDateUtc.HasValue) |
330 | 331 | { |
331 | | - DateTime endDate = DateTime.SpecifyKind(discount.EndDateUtc.Value, DateTimeKind.Utc); |
| 332 | + var endDate = DateTime.SpecifyKind(discount.EndDateUtc.Value, DateTimeKind.Utc); |
332 | 333 | if (endDate.CompareTo(now) < 0) |
333 | 334 | return false; |
334 | 335 | } |
335 | 336 |
|
336 | 337 | if (!CheckDiscountLimitations(discount, customer)) |
337 | 338 | return false; |
338 | 339 |
|
339 | | - // discount requirements |
340 | | - var requirements = discount.DiscountRequirements; |
| 340 | + // better not to apply discounts if there are gift cards in the cart cause the customer could "earn" money through that. |
| 341 | + if (discount.DiscountType == DiscountType.AssignedToOrderTotal || discount.DiscountType == DiscountType.AssignedToOrderSubTotal) |
| 342 | + { |
| 343 | + var cart = customer.ShoppingCartItems |
| 344 | + .Filter(ShoppingCartType.ShoppingCart, store.Id) |
| 345 | + .ToList(); |
| 346 | + |
| 347 | + if (cart.Any(x => x.Product.IsGiftCard)) |
| 348 | + return false; |
| 349 | + } |
| 350 | + |
| 351 | + // discount requirements |
| 352 | + var requirements = discount.DiscountRequirements; |
341 | 353 | foreach (var req in requirements) |
342 | 354 | { |
343 | | - var requirementRule = LoadDiscountRequirementRuleBySystemName(req.DiscountRequirementRuleSystemName, storeId); |
| 355 | + var requirementRule = LoadDiscountRequirementRuleBySystemName(req.DiscountRequirementRuleSystemName, store.Id); |
344 | 356 | if (requirementRule == null) |
345 | 357 | continue; |
346 | 358 |
|
347 | | - var request = new CheckDiscountRequirementRequest() |
| 359 | + var request = new CheckDiscountRequirementRequest |
348 | 360 | { |
349 | 361 | DiscountRequirement = req, |
350 | 362 | Customer = customer, |
351 | | - Store = _storeContext.CurrentStore |
| 363 | + Store = store |
352 | 364 | }; |
| 365 | + |
353 | 366 | if (!requirementRule.Value.CheckRequirement(request)) |
354 | 367 | return false; |
355 | 368 | } |
356 | 369 |
|
357 | | - // better not to apply discounts if there are gift cards in the cart cause the customer could "earn" money through that. |
358 | | - if (discount.DiscountType == DiscountType.AssignedToOrderTotal || discount.DiscountType == DiscountType.AssignedToOrderSubTotal) |
359 | | - { |
360 | | - var cart = customer.GetCartItems(ShoppingCartType.ShoppingCart, storeId); |
361 | | - |
362 | | - if (cart.Any(x => x.Item.Product.IsGiftCard)) |
363 | | - return false; |
364 | | - } |
365 | | - |
366 | 370 | return true; |
367 | 371 | } |
368 | 372 |
|
|
0 commit comments