Skip to content

Commit

Permalink
Resolves #1639 Shipping.ByTotal: Add option to calculate the shipping…
Browse files Browse the repository at this point in the history
… rate based on the net total instead of the gross total
  • Loading branch information
mgesing committed Jun 7, 2019
1 parent 3eee0d3 commit 676da0a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### New Features
* Page Builder: multistore support for stories.
* #1639 Shipping.ByTotal: Add option to calculate the shipping rate based on the net total instead of the gross total.


## SmartStore.NET 3.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public ActionResult Configure()
model.LimitMethodsToCreated = _shippingByTotalSettings.LimitMethodsToCreated;
model.SmallQuantityThreshold = _shippingByTotalSettings.SmallQuantityThreshold;
model.SmallQuantitySurcharge = _shippingByTotalSettings.SmallQuantitySurcharge;
model.CalculateTotalIncludingTax = _shippingByTotalSettings.CalculateTotalIncludingTax;
model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode;
model.GridPageSize = _adminAreaSettings.GridPageSize;

Expand Down Expand Up @@ -162,6 +163,7 @@ public ActionResult Configure(ByTotalListModel model)
_shippingByTotalSettings.LimitMethodsToCreated = model.LimitMethodsToCreated;
_shippingByTotalSettings.SmallQuantityThreshold = model.SmallQuantityThreshold;
_shippingByTotalSettings.SmallQuantitySurcharge = model.SmallQuantitySurcharge;
_shippingByTotalSettings.CalculateTotalIncludingTax = model.CalculateTotalIncludingTax;

_services.Settings.SaveSetting(_shippingByTotalSettings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
<LocaleResource Name="Fields.LimitMethodsToCreated.Hint">
<Value>Dem Kunden wird während des Checkouts kostenloser Versand als Fallback angeboten, wenn keine der festgelegten Bedingungen zutreffen. Aktivieren Sie diese Option, wenn das nicht gewünscht ist.</Value>
</LocaleResource>
<LocaleResource Name="Fields.CalculateTotalIncludingTax">
<Value>Berechne Bestellwert inkl. Steuer</Value>
</LocaleResource>
<LocaleResource Name="Fields.CalculateTotalIncludingTax.Hint">
<Value>Legt fest, ob der Bestellwert zur Berechnung der Versandkosten inkl. oder exkl. Steuern berechnet werden soll.</Value>
</LocaleResource>

<LocaleResource Name="Fields.BaseCharge">
<Value>Basisgebühr</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
<LocaleResource Name="Fields.LimitMethodsToCreated.Hint">
<Value>If you check this option, then your customers will be limited to shipping options configured here. Otherwise, they'll be able to choose any existing shipping options even if they're not configured here (zero shipping fee in this case).</Value>
</LocaleResource>
<LocaleResource Name="Fields.CalculateTotalIncludingTax">
<Value>Calculate order total incl. tax</Value>
</LocaleResource>
<LocaleResource Name="Fields.CalculateTotalIncludingTax.Hint">
<Value>Specifies whether to calculate the order total including or excluding taxes.</Value>
</LocaleResource>

<LocaleResource Name="Fields.BaseCharge">
<Value>Base fee</Value>
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/SmartStore.Shipping/Models/ByTotalListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public ByTotalListModel()
[SmartResourceDisplayName("Plugins.Shipping.ByTotal.Fields.SmallQuantitySurcharge")]
public decimal SmallQuantitySurcharge { get; set; }

[SmartResourceDisplayName("Plugins.Shipping.ByTotal.Fields.CalculateTotalIncludingTax")]
public bool CalculateTotalIncludingTax { get; set; }

public string PrimaryStoreCurrencyCode { get; set; }

public int GridPageSize { get; set; }
Expand Down
19 changes: 12 additions & 7 deletions src/Plugins/SmartStore.Shipping/Providers/ByTotalProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest get
int countryId = 0;
int stateProvinceId = 0;
string zip = null;
var taxRate = decimal.Zero;
decimal subTotal = decimal.Zero;
int storeId = _storeContext.CurrentStore.Id;

Expand All @@ -190,13 +189,19 @@ public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest get
continue;
}

var itemSubTotal = _priceCalculationService.GetSubTotal(shoppingCartItem, true);
var itemSubTotalInclTax = _taxService.GetProductPrice(shoppingCartItem.Item.Product, itemSubTotal, true, getShippingOptionRequest.Customer, out taxRate);
subTotal += itemSubTotalInclTax;
var itemSubTotalBase = _priceCalculationService.GetSubTotal(shoppingCartItem, true);
var itemSubTotal = _taxService.GetProductPrice(
shoppingCartItem.Item.Product,
itemSubTotalBase,
_shippingByTotalSettings.CalculateTotalIncludingTax,
getShippingOptionRequest.Customer,
out var _);

subTotal += itemSubTotal;
}

decimal sqThreshold = _shippingByTotalSettings.SmallQuantityThreshold;
decimal sqSurcharge = _shippingByTotalSettings.SmallQuantitySurcharge;
var sqThreshold = _shippingByTotalSettings.SmallQuantityThreshold;
var sqSurcharge = _shippingByTotalSettings.SmallQuantitySurcharge;

var shippingMethods = _shippingService.GetAllShippingMethods(getShippingOptionRequest, storeId);
foreach (var shippingMethod in shippingMethods)
Expand All @@ -206,7 +211,7 @@ public GetShippingOptionResponse GetShippingOptions(GetShippingOptionRequest get
{
if (rate > 0 && sqThreshold > 0 && subTotal <= sqThreshold)
{
// Add small quantity surcharge (Mindermengenzuschlag)
// Add small quantity surcharge (Mindermengenzuschlag).
rate += sqSurcharge;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ namespace SmartStore.Shipping
{
public class ShippingByTotalSettings : ISettings
{
public ShippingByTotalSettings()
{
CalculateTotalIncludingTax = true;
}

public bool LimitMethodsToCreated { get; set; }
public bool CalculateTotalIncludingTax { get; set; }

public decimal SmallQuantityThreshold { get; set; }
public decimal SmallQuantitySurcharge { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
@Html.ValidationMessageFor(model => model.SmallQuantitySurcharge)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.SmartLabelFor(model => model.CalculateTotalIncludingTax)
</td>
<td class="adminData">
@Html.EditorFor(model => model.CalculateTotalIncludingTax)
@Html.ValidationMessageFor(model => model.CalculateTotalIncludingTax)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.SmartLabelFor(model => model.LimitMethodsToCreated)
Expand Down

0 comments on commit 676da0a

Please sign in to comment.