Skip to content

Commit

Permalink
Resolves #1788: Added setting options to restrict order amount in gen…
Browse files Browse the repository at this point in the history
…eral and for customer roles in specific.

* also applied fixes and some modifications to already existing functionality. For example:
* offcanvas-cart now hides checkout button dynamically
* cart & checkout both now check and use the same validation method for min/max values
* streamlined settings - easy config, & more refactoring
  • Loading branch information
Marcel Schmidt committed Jul 30, 2020
1 parent 1459302 commit e6ddbbf
Show file tree
Hide file tree
Showing 24 changed files with 731 additions and 337 deletions.
12 changes: 12 additions & 0 deletions src/Libraries/SmartStore.Core/Domain/Customers/CustomerRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public partial class CustomerRole : BaseEntity, IRulesContainer
[Index("IX_CustomerRole_SystemName_IsSystemRole", 1)]
public string SystemName { get; set; }

/// <summary>
/// Gets or sets a minimum order amount
/// </summary>
[DataMember]
public decimal MinOrderAmount { get; set; }

/// <summary>
/// Gets or sets a maximum order amount
/// </summary>
[DataMember]
public decimal MaxOrderAmount { get; set; }

/// <summary>
/// Gets or sets the permission role mappings.
/// </summary>
Expand Down
15 changes: 10 additions & 5 deletions src/Libraries/SmartStore.Core/Domain/Orders/OrderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ public OrderSettings()
public bool IsReOrderAllowed { get; set; }

/// <summary>
/// Gets or sets a minimum order subtotal amount
/// Gets or sets a minimum order total amount
/// </summary>
public decimal MinOrderSubtotalAmount { get; set; }
public decimal MinOrderAmount { get; set; }

/// <summary>
/// Gets or sets a minimum order total amount
/// Gets or sets a maximum order total amount
/// </summary>
public decimal MinOrderTotalAmount { get; set; }

public decimal MaxOrderAmount { get; set; }

/// <summary>
/// Gets or sets a value indicating whether min/max order amount is relating to order amount subtotal
/// </summary>
public bool ApplyToSubtotal { get; set; }

/// <summary>
/// Gets or sets a value indicating whether anonymous checkout allowed
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace SmartStore.Data.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class AddCustomerRoleOrderAmount : DbMigration
{
public override void Up()
{
AddColumn("dbo.CustomerRole", "MinOrderAmount", c => c.Decimal(nullable: false, precision: 18, scale: 2));
AddColumn("dbo.CustomerRole", "MaxOrderAmount", c => c.Decimal(nullable: false, precision: 18, scale: 2));
}

public override void Down()
{
DropColumn("dbo.CustomerRole", "MinOrderAmount");
DropColumn("dbo.CustomerRole", "MaxOrderAmount");
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void Seed(SmartObjectContext context)
{
context.MigrateLocaleResources(MigrateLocaleResources);
MigrateSettings(context);
}
}

public void MigrateSettings(SmartObjectContext context)
{
Expand Down Expand Up @@ -134,6 +134,53 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
"Legt eine Farbe für das Farbflächen-Steuerelement fest.");

builder.AddOrUpdate("Common.Entity.CheckoutAttributeValue", "Checkout attribute option", "Checkout-Attribut-Option");

builder.AddOrUpdate("Checkout.MaxOrderSubtotalAmount",
"The maximum order value for the subtotal is {0}.",
"Der Höchstbestellwert für die Zwischensumme ist {0}.");

builder.AddOrUpdate("Checkout.MaxOrderTotalAmount",
"The maximum order value for the total is {0}.",
"Der Höchstbestellwert der Gesamtsumme ist {0}.");

builder.AddOrUpdate("Admin.Configuration.Settings.Order.MinOrderAmount",
"Min order amount",
"Mindestbestellwert",
"Enter minimum order amount.",
"Legt den Mindestbestellwert fest.");

builder.AddOrUpdate("Admin.Configuration.Settings.Order.MaxOrderAmount",
"Max order amount",
"Höchstbestellwert",
"Enter maximum order amount.",
"Legt den Höchstbestellwert fest.");

builder.AddOrUpdate("Admin.Configuration.Settings.Order.ApplyToSubtotal",
"Order amount related to subtotal",
"Bestellwert bezogen auf Zwischensumme",
"Determines whether the min/max order amount refers to the order subtotal, otherwise it refers to the total amount.",
"Bestimmt, ob sich der Mindest-/Höchstbetrag auf die Auftragszwischensumme bezieht, andernfalls bezieht er sich auf den Gesamtbetrag.");

builder.Delete("Admin.Configuration.Settings.Order.MaxOrderSubtotalAmount");
builder.Delete("Admin.Configuration.Settings.Order.MaxOrderSubtotalAmount.Hint");
builder.Delete("Admin.Configuration.Settings.Order.MaxOrderTotalAmount");
builder.Delete("Admin.Configuration.Settings.Order.MaxOrderTotalAmount.Hint");
builder.Delete("Admin.Configuration.Settings.Order.MinOrderSubtotalAmount");
builder.Delete("Admin.Configuration.Settings.Order.MinOrderSubtotalAmount.Hint");
builder.Delete("Admin.Configuration.Settings.Order.MinOrderTotalAmount");
builder.Delete("Admin.Configuration.Settings.Order.MinOrderTotalAmount.Hint");

builder.AddOrUpdate("Admin.Customers.CustomerRoles.Fields.MinOrderAmount",
"Min order amount",
"Mindestbestellwert",
"Enter minimum order amount for user in this customer group.",
"Legt den Mindestbestellwert für Nutzer in der Kundengruppe fest.");

builder.AddOrUpdate("Admin.Customers.CustomerRoles.Fields.MaxOrderAmount",
"Max order amount",
"Höchstbestellwert",
"Enter maximum order amount for user in this customer group.",
"Legt den Höchstbestellwert für Nutzer in der Kundengruppe fest.");
}
}
}
7 changes: 7 additions & 0 deletions src/Libraries/SmartStore.Data/SmartStore.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@
<Compile Include="Migrations\202007291847004_NewPropertiesAndIndexes.Designer.cs">
<DependentUpon>202007291847004_NewPropertiesAndIndexes.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\202007301117363_AddCustomerRoleOrderAmount.cs" />
<Compile Include="Migrations\202007301117363_AddCustomerRoleOrderAmount.Designer.cs">
<DependentUpon>202007301117363_AddCustomerRoleOrderAmount.cs</DependentUpon>
</Compile>
<Compile Include="ObjectContextBase.SaveChanges.cs" />
<Compile Include="Setup\Builder\ActivityLogTypeMigrator.cs" />
<Compile Include="Setup\Builder\SettingsBuilder.cs" />
Expand Down Expand Up @@ -888,6 +892,9 @@
<EmbeddedResource Include="Migrations\202007291847004_NewPropertiesAndIndexes.resx">
<DependentUpon>202007291847004_NewPropertiesAndIndexes.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\202007301117363_AddCustomerRoleOrderAmount.resx">
<DependentUpon>202007301117363_AddCustomerRoleOrderAmount.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Sql\Indexes.sql" />
<EmbeddedResource Include="Sql\StoredProcedures.sql" />
</ItemGroup>
Expand Down
44 changes: 28 additions & 16 deletions src/Libraries/SmartStore.Services/Orders/IOrderProcessingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,42 @@ IList<string> GetOrderPlacementWarnings(
/// <returns>Result</returns>
bool IsReturnRequestAllowed(Order order);


/// <summary>
/// Valdiate minimum order sub-total amount
/// Valdiate minimum order amount.
/// Gets min order amount from customer role.
/// When no min order amount is defined in customer role, default order settings are used as fallback.
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <returns>true - OK; false - minimum order sub-total amount is not reached</returns>
bool ValidateMinOrderSubtotalAmount(IList<OrganizedShoppingCartItem> cart);
/// <returns>true - OK; false - minimum order amount is not reached</returns>
(bool isValid, decimal minOrderAmount) ValidateMinOrderAmount(IList<OrganizedShoppingCartItem> cart, int[] customerRoleIds);

/// <summary>
/// Valdiate minimum order total amount
/// Valdiate maximum order amount.
/// Gets max order amount from customer role.
/// When no max order amount is defined in customer role, default order settings are used as fallback.
/// </summary>
/// <param name="cart">Shopping cart</param>
/// <returns>true - OK; false - minimum order total amount is not reached</returns>
bool ValidateMinOrderTotalAmount(IList<OrganizedShoppingCartItem> cart);
/// <param name="cart">Shopping cart, customer role ids</param>
/// <returns>true - OK; false - maximum order amount is exceeded</returns>
(bool isValid, decimal maxOrderAmount) ValidateMaxOrderAmount(IList<OrganizedShoppingCartItem> cart, int[] customerRoleIds);

/// <summary>
/// Adds a shipment to an order.
/// </summary>
/// <param name="order">Order.</param>
/// <param name="trackingNumber">Tracking number.</param>
/// <summary>
/// Valdiate minimum and maximum order amount.
/// Gets min/max order amount from customer role.
/// When no min or max order amount is defined in customer role, default order settings are used as fallback.
/// </summary>
/// <param name="cart">Shopping cart, customer role ids</param>
/// <returns>true - OK; false - minimum amount is not reached or maximum amount is exceeded</returns>
bool ValidateOrderAmount(IList<OrganizedShoppingCartItem> cart, int[] customerRoleIds);

/// <summary>
/// Adds a shipment to an order.
/// </summary>
/// <param name="order">Order.</param>
/// <param name="trackingNumber">Tracking number.</param>
/// <param name="trackingUrl">Tracking URL.</param>
/// <param name="quantities">Quantities by order item identifiers. <c>null</c> to use the remaining total number of products for each order item.</param>
/// <returns>New shipment, <c>null</c> if no shipment was added.</returns>
Shipment AddShipment(
/// <param name="quantities">Quantities by order item identifiers. <c>null</c> to use the remaining total number of products for each order item.</param>
/// <returns>New shipment, <c>null</c> if no shipment was added.</returns>
Shipment AddShipment(
Order order,
string trackingNumber,
string trackingUrl,
Expand Down
Loading

0 comments on commit e6ddbbf

Please sign in to comment.