Skip to content

Commit

Permalink
Resolves #1449 IgnoreCharges of shipping methods is not working if a …
Browse files Browse the repository at this point in the history
…localized name is specified
  • Loading branch information
mgesing committed May 16, 2018
1 parent db65314 commit 8f3b3a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ decimal GetOrderSubtotalDiscount(Customer customer,
/// <summary>
/// Adjust shipping rate (free shipping, additional charges, discounts)
/// </summary>
/// <param name="shippingRate">Shipping rate to adjust</param>
/// <param name="shippingOption">Shipping option</param>
/// <param name="cart">Cart</param>
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Adjusted shipping rate</returns>
decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedShoppingCartItem> cart,
string shippingMethodName, IList<ShippingMethod> shippingMethods, out Discount appliedDiscount);
decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedShoppingCartItem> cart,
ShippingOption shippingOption, IList<ShippingMethod> shippingMethods, out Discount appliedDiscount);

/// <summary>
/// Gets shopping cart additional shipping charge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected virtual void PrepareAuxiliaryServicesTaxingInfos(IList<OrganizedShoppi
{
// use last shipping option (get from cache)
var shippingMethods = _shippingService.GetAllShippingMethods(null, storeId);
shippingTotal = AdjustShippingRate(shippingOption.Rate, cart, shippingOption.Name, shippingMethods, out appliedDiscount);
shippingTotal = AdjustShippingRate(shippingOption.Rate, cart, shippingOption, shippingMethods, out appliedDiscount);
}
else
{
Expand Down Expand Up @@ -675,18 +675,18 @@ public virtual bool IsFreeShipping(IList<OrganizedShoppingCartItem> cart)
/// <param name="appliedDiscount">Applied discount</param>
/// <returns>Adjusted shipping rate</returns>
public virtual decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedShoppingCartItem> cart,
string shippingMethodName, IList<ShippingMethod> shippingMethods, out Discount appliedDiscount)
ShippingOption shippingOption, IList<ShippingMethod> shippingMethods, out Discount appliedDiscount)
{
appliedDiscount = null;

//free shipping
if (IsFreeShipping(cart))
return decimal.Zero;
if (IsFreeShipping(cart))
{
return decimal.Zero;
}

decimal adjustedRate = decimal.Zero;
decimal bundlePerItemShipping = decimal.Zero;
bool ignoreAdditionalShippingCharge = false;
ShippingMethod shippingMethod;
var adjustedRate = decimal.Zero;
var bundlePerItemShipping = decimal.Zero;
var ignoreAdditionalShippingCharge = false;

foreach (var sci in cart)
{
Expand All @@ -695,7 +695,9 @@ public virtual decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedS
if (sci.ChildItems != null)
{
foreach (var childItem in sci.ChildItems.Where(x => x.Item.IsShipEnabled && !x.Item.IsFreeShipping))
{
bundlePerItemShipping += shippingRate;
}
}
}
else if (adjustedRate == decimal.Zero)
Expand All @@ -706,22 +708,25 @@ public virtual decimal AdjustShippingRate(decimal shippingRate, IList<OrganizedS

adjustedRate += bundlePerItemShipping;

if (shippingMethodName.HasValue() && shippingMethods != null &&
(shippingMethod = shippingMethods.FirstOrDefault(x => x.Name.IsCaseInsensitiveEqual(shippingMethodName))) != null)
if (shippingOption != null && shippingMethods != null)
{
ignoreAdditionalShippingCharge = shippingMethod.IgnoreCharges;
var shippingMethod = shippingMethods.FirstOrDefault(x => x.Id == shippingOption.ShippingMethodId);
if (shippingMethod != null)
{
ignoreAdditionalShippingCharge = shippingMethod.IgnoreCharges;
}
}

//additional shipping charges
// Additional shipping charges.
if (!ignoreAdditionalShippingCharge)
{
decimal additionalShippingCharge = GetShoppingCartAdditionalShippingCharge(cart);
adjustedRate += additionalShippingCharge;
}

//discount
// Discount.
var customer = cart.GetCustomer();
decimal discountAmount = GetShippingDiscount(customer, adjustedRate, out appliedDiscount);
var discountAmount = GetShippingDiscount(customer, adjustedRate, out appliedDiscount);
adjustedRate = adjustedRate - discountAmount;

if (adjustedRate < decimal.Zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected CheckoutShippingMethodModel PrepareShippingMethodModel(IList<Organized

// Adjust rate.
Discount appliedDiscount = null;
var shippingTotal = _orderTotalCalculationService.AdjustShippingRate(shippingOption.Rate, cart, shippingOption.Name, shippingMethods, out appliedDiscount);
var shippingTotal = _orderTotalCalculationService.AdjustShippingRate(shippingOption.Rate, cart, shippingOption, shippingMethods, out appliedDiscount);
decimal rateBase = _taxService.GetShippingPrice(shippingTotal, customer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
soModel.FeeRaw = rate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ public ActionResult GetEstimateShipping(EstimateShippingModel shippingModel, Pro
//calculate discounted and taxed rate
Discount appliedDiscount = null;
decimal shippingTotal = _orderTotalCalculationService.AdjustShippingRate(
shippingOption.Rate, cart, shippingOption.Name, shippingMethods, out appliedDiscount);
shippingOption.Rate, cart, shippingOption, shippingMethods, out appliedDiscount);

decimal rateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer);
decimal rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency);
Expand Down

0 comments on commit 8f3b3a8

Please sign in to comment.