Skip to content

Commit 82c89b9

Browse files
committed
nopSolutions#1917 We should not include shipping total when calculating reward points to be granted
1 parent afae861 commit 82c89b9

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/Libraries/Nop.Services/Orders/IOrderTotalCalculationService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ decimal GetTaxTotal(IList<ShoppingCartItem> cart, out SortedDictionary<decimal,
191191
/// <returns>true - reward points could use; false - cannot be used.</returns>
192192
bool CheckMinimumRewardPointsToUseRequirement(int rewardPoints);
193193

194+
/// <summary>
195+
/// Calculate how order total (maximum amount) for which reward points could be earned/reduced
196+
/// </summary>
197+
/// <param name="orderShippingInclTax">Order shipping (including tax)</param>
198+
/// <param name="orderTotal">Order total</param>
199+
/// <returns>Applicable order total</returns>
200+
decimal CalculateApplicableOrderTotalForRewardPoints(decimal orderShippingInclTax, decimal orderTotal);
194201
/// <summary>
195202
/// Calculate how much reward points will be earned/reduced based on certain amount spent
196203
/// </summary>

src/Libraries/Nop.Services/Orders/OrderProcessingService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ protected virtual void SendNotificationsAndSaveNotes(Order order)
765765
/// <param name="order">Order</param>
766766
protected virtual void AwardRewardPoints(Order order)
767767
{
768-
int points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, order.OrderTotal);
768+
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
769+
int points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints);
769770
if (points == 0)
770771
return;
771772

@@ -795,7 +796,8 @@ protected virtual void AwardRewardPoints(Order order)
795796
/// <param name="order">Order</param>
796797
protected virtual void ReduceRewardPoints(Order order)
797798
{
798-
int points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, order.OrderTotal);
799+
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
800+
int points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints);
799801
if (points == 0)
800802
return;
801803

src/Libraries/Nop.Services/Orders/OrderTotalCalculationService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,19 @@ public virtual bool CheckMinimumRewardPointsToUseRequirement(int rewardPoints)
13891389
return rewardPoints >= _rewardPointsSettings.MinimumRewardPointsToUse;
13901390
}
13911391

1392+
/// <summary>
1393+
/// Calculate how order total (maximum amount) for which reward points could be earned/reduced
1394+
/// </summary>
1395+
/// <param name="orderShippingInclTax">Order shipping (including tax)</param>
1396+
/// <param name="orderTotal">Order total</param>
1397+
/// <returns>Applicable order total</returns>
1398+
public virtual decimal CalculateApplicableOrderTotalForRewardPoints(decimal orderShippingInclTax, decimal orderTotal)
1399+
{
1400+
//do you give reward points for order total? or do you exclude shipping?
1401+
//since shipping costs vary some of store owners don't give reward points based on shipping total
1402+
//you can put your custom logic here
1403+
return orderTotal - orderShippingInclTax;
1404+
}
13921405
/// <summary>
13931406
/// Calculate how much reward points will be earned/reduced based on certain amount spent
13941407
/// </summary>

src/Presentation/Nop.Web/Factories/ShoppingCartModelFactory.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,12 @@ public virtual OrderTotalsModel PrepareOrderTotalsModel(IList<ShoppingCartItem>
10251025
}
10261026
}
10271027
else
1028+
{
10281029
model.HideShippingTotal = _shippingSettings.HideShippingTotal;
1030+
}
10291031

10301032
//payment method fee
1031-
var paymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(
1032-
SystemCustomerAttributeNames.SelectedPaymentMethod, _storeContext.CurrentStore.Id);
1033+
var paymentMethodSystemName = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.SelectedPaymentMethod, _storeContext.CurrentStore.Id);
10331034
decimal paymentMethodAdditionalFee = _paymentService.GetAdditionalHandlingFee(cart, paymentMethodSystemName);
10341035
decimal paymentMethodAdditionalFeeWithTaxBase = _taxService.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, _workContext.CurrentCustomer);
10351036
if (paymentMethodAdditionalFeeWithTaxBase > decimal.Zero)
@@ -1132,8 +1133,14 @@ public virtual OrderTotalsModel PrepareOrderTotalsModel(IList<ShoppingCartItem>
11321133
_rewardPointsSettings.DisplayHowMuchWillBeEarned &&
11331134
shoppingCartTotalBase.HasValue)
11341135
{
1135-
model.WillEarnRewardPoints = _orderTotalCalculationService
1136-
.CalculateRewardPoints(_workContext.CurrentCustomer, shoppingCartTotalBase.Value);
1136+
decimal? shippingBaseInclTax = model.RequiresShipping
1137+
? _orderTotalCalculationService.GetShoppingCartShippingTotal(cart, true)
1138+
: 0;
1139+
if (shippingBaseInclTax.HasValue)
1140+
{
1141+
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(shippingBaseInclTax.Value, shoppingCartTotalBase.Value);
1142+
model.WillEarnRewardPoints = _orderTotalCalculationService.CalculateRewardPoints(_workContext.CurrentCustomer, totalForRewardPoints);
1143+
}
11371144
}
11381145

11391146
}

0 commit comments

Comments
 (0)