Skip to content

Commit

Permalink
nopSolutions#1910 Add settings to configure minimum order total when …
Browse files Browse the repository at this point in the history
…points are granted
  • Loading branch information
RomanovM committed Mar 5, 2018
1 parent d4ed4e5 commit 7fd8ab0
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class RewardPointsSettings : ISettings
/// </summary>
public int? PurchasesPointsValidity { get; set; }

/// <summary>
/// Gets or sets the minimum order total (exclude shipping cost) to award points for purchases
/// </summary>
public decimal MinOrderTotalToAwardPoints { get; set; }

/// <summary>
/// Gets or sets a delay before activation points
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6235,6 +6235,7 @@ protected virtual void InstallSettings(bool installSampleData)
RegistrationPointsValidity = 30,
PointsForPurchases_Amount = 10,
PointsForPurchases_Points = 1,
MinOrderTotalToAwardPoints = 0,
PurchasesPointsValidity = 45,
ActivationDelay = 0,
ActivationDelayPeriodId = 0,
Expand Down
12 changes: 8 additions & 4 deletions src/Libraries/Nop.Services/Orders/OrderProcessingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,10 @@ protected virtual void SendNotificationsAndSaveNotes(Order order)
/// <param name="order">Order</param>
protected virtual void AwardRewardPoints(Order order)
{
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
var points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints);
var totalForRewardPoints = _orderTotalCalculationService
.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
var points = totalForRewardPoints > decimal.Zero ?
_orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints) : 0;
if (points == 0)
return;

Expand Down Expand Up @@ -916,8 +918,10 @@ protected virtual void AwardRewardPoints(Order order)
/// <param name="order">Order</param>
protected virtual void ReduceRewardPoints(Order order)
{
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
var points = _orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints);
var totalForRewardPoints = _orderTotalCalculationService
.CalculateApplicableOrderTotalForRewardPoints(order.OrderShippingInclTax, order.OrderTotal);
var points = totalForRewardPoints > decimal.Zero ?
_orderTotalCalculationService.CalculateRewardPoints(order.Customer, totalForRewardPoints) : 0;
if (points == 0)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,13 @@ public virtual decimal CalculateApplicableOrderTotalForRewardPoints(decimal orde
//do you give reward points for order total? or do you exclude shipping?
//since shipping costs vary some of store owners don't give reward points based on shipping total
//you can put your custom logic here
return orderTotal - orderShippingInclTax;
var totalForRewardPoints = orderTotal - orderShippingInclTax;

//check the minimum total to award points
if (totalForRewardPoints < _rewardPointsSettings.MinOrderTotalToAwardPoints)
return decimal.Zero;

return totalForRewardPoints;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7764,6 +7764,12 @@
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.ActivationDelay.Hint">
<Value>Specify how many days (hours) must elapse before earned points become active. Points earned by purchase cannot be redeemed until activated. For example, you may set the days before the points become available to 7. In this case, the points earned will be available for spending only 7 days after the purchase.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.MinOrderTotalToAwardPoints">
<Value>Minimum order total</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.MinOrderTotalToAwardPoints.Hint">
<Value>Specify the minimum order total (exclude shipping cost) to award points for purchases.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.PointsForRegistration">
<Value>Points for registration</Value>
</LocaleResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ public virtual IActionResult RewardPoints()
model.RegistrationPointsValidity_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.RegistrationPointsValidity, storeScope);
model.PointsForPurchases_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.PointsForPurchases_Amount, storeScope) ||
_settingService.SettingExists(rewardPointsSettings, x => x.PointsForPurchases_Points, storeScope);
model.MinOrderTotalToAwardPoints_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.MinOrderTotalToAwardPoints, storeScope);
model.PurchasesPointsValidity_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.PurchasesPointsValidity, storeScope);
model.ActivationDelay_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.ActivationDelay, storeScope);
model.DisplayHowMuchWillBeEarned_OverrideForStore = _settingService.SettingExists(rewardPointsSettings, x => x.DisplayHowMuchWillBeEarned, storeScope);
Expand Down Expand Up @@ -1036,6 +1037,7 @@ public virtual IActionResult RewardPoints(RewardPointsSettingsModel model)
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.RegistrationPointsValidity, model.RegistrationPointsValidity_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.PointsForPurchases_Amount, model.PointsForPurchases_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.PointsForPurchases_Points, model.PointsForPurchases_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.MinOrderTotalToAwardPoints, model.MinOrderTotalToAwardPoints_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.PurchasesPointsValidity, model.PurchasesPointsValidity_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.ActivationDelay, model.ActivationDelay_OverrideForStore, storeScope, false);
_settingService.SaveSettingOverridablePerStore(rewardPointsSettings, x => x.ActivationDelayPeriodId, model.ActivationDelay_OverrideForStore, storeScope, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ public AdminMapperConfiguration()
.ForMember(dest => dest.PointsForRegistration_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.RegistrationPointsValidity_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.PointsForPurchases_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.MinOrderTotalToAwardPoints_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.PurchasesPointsValidity_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.ActivationDelay_OverrideForStore, mo => mo.Ignore())
.ForMember(dest => dest.ActivatePointsImmediately, mo => mo.Ignore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public partial class RewardPointsSettingsModel : BaseNopModel
public int PointsForPurchases_Points { get; set; }
public bool PointsForPurchases_OverrideForStore { get; set; }

[NopResourceDisplayName("Admin.Configuration.Settings.RewardPoints.MinOrderTotalToAwardPoints")]
public decimal MinOrderTotalToAwardPoints { get; set; }
public bool MinOrderTotalToAwardPoints_OverrideForStore { get; set; }

[NopResourceDisplayName("Admin.Configuration.Settings.RewardPoints.PurchasesPointsValidity")]
[UIHint("Int32Nullable")]
public int? PurchasesPointsValidity { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
<span asp-validation-for="PurchasesPointsValidity"></span>
</div>
</div>
<div class="form-group advanced-setting">
<div class="col-md-3">
<nop-override-store-checkbox asp-for="MinOrderTotalToAwardPoints_OverrideForStore" asp-input="MinOrderTotalToAwardPoints" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
<nop-label asp-for="MinOrderTotalToAwardPoints" />
</div>
<div class="col-md-9">
<nop-editor asp-for="MinOrderTotalToAwardPoints" asp-postfix="@Model.PrimaryStoreCurrencyCode" />
<span asp-validation-for="MinOrderTotalToAwardPoints"></span>
</div>
</div>
<div class="form-group advanced-setting">
<div class="col-md-3">
<nop-override-store-checkbox asp-for="PointsForRegistration_OverrideForStore" asp-input="PointsForRegistration" asp-store-scope="@Model.ActiveStoreScopeConfiguration" />
Expand Down
18 changes: 8 additions & 10 deletions src/Presentation/Nop.Web/Factories/ShoppingCartModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,18 +1186,16 @@ public virtual OrderTotalsModel PrepareOrderTotalsModel(IList<ShoppingCartItem>
}

//reward points to be earned
if (_rewardPointsSettings.Enabled &&
_rewardPointsSettings.DisplayHowMuchWillBeEarned &&
shoppingCartTotalBase.HasValue)
if (_rewardPointsSettings.Enabled && _rewardPointsSettings.DisplayHowMuchWillBeEarned && shoppingCartTotalBase.HasValue)
{
var shippingBaseInclTax = model.RequiresShipping
? _orderTotalCalculationService.GetShoppingCartShippingTotal(cart, true)
: 0;
if (shippingBaseInclTax.HasValue)
{
var totalForRewardPoints = _orderTotalCalculationService.CalculateApplicableOrderTotalForRewardPoints(shippingBaseInclTax.Value, shoppingCartTotalBase.Value);
//get shipping total
var shippingBaseInclTax = !model.RequiresShipping ? 0 : _orderTotalCalculationService.GetShoppingCartShippingTotal(cart, true) ?? 0;

//get total for reward points
var totalForRewardPoints = _orderTotalCalculationService
.CalculateApplicableOrderTotalForRewardPoints(shippingBaseInclTax, shoppingCartTotalBase.Value);
if (totalForRewardPoints > decimal.Zero)
model.WillEarnRewardPoints = _orderTotalCalculationService.CalculateRewardPoints(_workContext.CurrentCustomer, totalForRewardPoints);
}
}

}
Expand Down
14 changes: 14 additions & 0 deletions upgradescripts/4.00-4.10 (under development)/upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ set @resources='
<LocaleResource Name="Admin.Customers.Customers.RewardPoints.Fields.PointsValidity.Postfix">
<Value>Days</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.MinOrderTotalToAwardPoints">
<Value>Minimum order total</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.Settings.RewardPoints.MinOrderTotalToAwardPoints.Hint">
<Value>Specify the minimum order total (exclude shipping cost) to award points for purchases.</Value>
</LocaleResource>
</Language>
'

Expand Down Expand Up @@ -1179,4 +1185,12 @@ BEGIN
INSERT [Setting] ([Name], [Value], [StoreId])
VALUES (N'rewardpointssettings.purchasespointsvalidity', N'45', 0)
END
GO

--new setting
IF NOT EXISTS (SELECT 1 FROM [Setting] WHERE [Name] = N'rewardpointssettings.minordertotaltoawardpoints')
BEGIN
INSERT [Setting] ([Name], [Value], [StoreId])
VALUES (N'rewardpointssettings.minordertotaltoawardpoints', N'0', 0)
END
GO

0 comments on commit 7fd8ab0

Please sign in to comment.