Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnNotify(string notification, NotificationArgs args)
if (myArgs?.Document != null)
{
var settings = SettingsManager.GetSettingsByShop(myArgs.Order.ShopId);
if (settings != null && !settings.ErpControlsShipping)
if (settings != null && settings.ShippingControlMode == Constants.ShippingControlMode.DynamicwebControlsShipping)
{
var order = myArgs.Order;
var shipping = Services.Shippings.GetShipping(order.ShippingMethodId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,24 @@ internal static class OrderConfiguration

public const string DefaultShippingItemType = "ItemCharge";
}

/// <summary>
/// Provides string constants that define the available modes for controlling shipping calculation and data
/// exchange between Dynamicweb and an ERP system.
/// </summary>
/// <remarks>Use these constants to specify how shipping fees and information are managed in
/// integrations between Dynamicweb and ERP systems. Each mode determines whether shipping is calculated by
/// Dynamicweb, by the ERP, or based on selections made in Dynamicweb and processed by the ERP.</remarks>
public static class ShippingControlMode
{
/// <summary>Dynamicweb calculates and sends the shipping fee to the ERP.</summary>
public const string DynamicwebControlsShipping = "DynamicwebControlsShipping";

/// <summary>ERP controls shipping entirely; no shipping data is sent from Dynamicweb.</summary>
public const string ErpControlsShipping = "ErpControlsShipping";

/// <summary>The customer selects a shipping method in Dynamicweb; the ERP calculates the freight cost based on the selected method's identity fields.</summary>
public const string ErpCalculatesBasedOnDwSelection = "ErpCalculatesBasedOnDwSelection";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,16 @@ public interface ISettings
string ErpShippingItemKey { get; set; }

/// <summary>
/// Gets or sets if ERP controls shipping calculations
/// Gets or sets the shipping control mode.
/// </summary>
/// <value><c>true</c> if [ERP controls shipping calculations]; otherwise, <c>false</c>.</value>
string ShippingControlMode { get; set; }

/// <summary>
/// Gets or sets whether the ERP controls shipping. Use <see cref="ShippingControlMode"/> instead.
/// Setting <c>false</c> switches to <see cref="Constants.ShippingControlMode.DynamicwebControlsShipping"/>;
/// setting <c>true</c> restores <see cref="Constants.ShippingControlMode.ErpControlsShipping"/>.
/// </summary>
[System.Obsolete("Use ShippingControlMode instead.")]
bool ErpControlsShipping { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Settings()
WebServiceConnectionStatusGlobalTagName = "Global:LiveIntegration.IsWebServiceConnectionAvailable";

ErpControlsDiscount = true;
ErpControlsShipping = true;
ShippingControlMode = Constants.ShippingControlMode.ErpControlsShipping;

SetOrderlineFixed = false;

Expand Down Expand Up @@ -263,10 +263,33 @@ public string InstanceName
public bool ErpControlsDiscount { get; set; }

/// <summary>
/// Gets or sets if ERP controls shipping
/// Gets or sets the shipping control mode.
/// </summary>
/// <value><c>true</c> if [ERP controls shipping]; otherwise, <c>false</c>.</value>
public bool ErpControlsShipping { get; set; }
public string ShippingControlMode
{
get => _shippingControlMode;
set => _shippingControlMode = NormalizeShippingControlMode(value);
}
private string _shippingControlMode;

private static string NormalizeShippingControlMode(string value)
{
if (string.Equals(value, Constants.ShippingControlMode.DynamicwebControlsShipping, StringComparison.OrdinalIgnoreCase))
return Constants.ShippingControlMode.DynamicwebControlsShipping;
if (string.Equals(value, Constants.ShippingControlMode.ErpCalculatesBasedOnDwSelection, StringComparison.OrdinalIgnoreCase))
return Constants.ShippingControlMode.ErpCalculatesBasedOnDwSelection;
return Constants.ShippingControlMode.ErpControlsShipping;
}

/// <inheritdoc/>
[Obsolete("Use ShippingControlMode instead.")]
public bool ErpControlsShipping
{
get => ShippingControlMode != Constants.ShippingControlMode.DynamicwebControlsShipping;
set => ShippingControlMode = value
? Constants.ShippingControlMode.ErpControlsShipping
: Constants.ShippingControlMode.DynamicwebControlsShipping;
}

/// <summary>
/// Gets or sets the key for shipping item type.
Expand Down Expand Up @@ -470,7 +493,7 @@ public static void UpdateFrom(ISettings source, ISettings target)
target.SkipLedgerOrder = source.SkipLedgerOrder;
target.ErpControlsDiscount = source.ErpControlsDiscount;
target.DisableErpDiscountsForAnonymousUsers = source.DisableErpDiscountsForAnonymousUsers;
target.ErpControlsShipping = source.ErpControlsShipping;
target.ShippingControlMode = source.ShippingControlMode;
target.ErpShippingItemType = source.ErpShippingItemType;
target.ErpShippingItemKey = source.ErpShippingItemKey;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.21.5</Version>
<Version>10.21.6</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Live Integration</Title>
<Description>Live Integration</Description>
Expand All @@ -19,7 +19,7 @@
<IncludeSymbols>true</IncludeSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dynamicweb.Ecommerce.DynamicwebLiveIntegration", "Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj", "{5B09B2C6-8E15-A19A-AA43-E303D71A0874}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B09B2C6-8E15-A19A-AA43-E303D71A0874}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B09B2C6-8E15-A19A-AA43-E303D71A0874}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B09B2C6-8E15-A19A-AA43-E303D71A0874}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B09B2C6-8E15-A19A-AA43-E303D71A0874}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8116CA11-5865-48E8-9C90-5CBF48FF6A82}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,23 @@ public LiveIntegrationAddIn()
public bool ErpControlsDiscount { get; set; }

/// <summary>
/// Gets or sets if ERP controls shipping calculations
/// Gets or sets the shipping control mode.
/// </summary>
/// <value><c>true</c> if [ERP controls shipping calculations]; otherwise, <c>false</c>.</value>
[AddInParameter("ERP controls shipping calculations")]
[AddInParameterEditor(typeof(YesNoParameterEditor), "")]
[AddInParameter("Shipping control")]
[AddInParameterEditor(typeof(DropDownParameterEditor), "none=false")]
[AddInParameterGroup("Orders")]
[AddInParameterOrder(157)]
public bool ErpControlsShipping { get; set; }
public string ShippingControlMode { get; set; }

/// <inheritdoc/>
[Obsolete("Use ShippingControlMode instead.")]
public bool ErpControlsShipping
{
get => ShippingControlMode != Constants.ShippingControlMode.DynamicwebControlsShipping;
set => ShippingControlMode = value
? Constants.ShippingControlMode.ErpControlsShipping
: Constants.ShippingControlMode.DynamicwebControlsShipping;
}

/// <summary>
/// Gets or sets the key for shipping item type.
Expand Down Expand Up @@ -750,11 +759,16 @@ IEnumerable<ParameterOption> IParameterOptions.GetParameterOptions(string dropdo
options.Add(new("Fixed Asset", "FixedAsset"));
options.Add(new("Resource", "Resource"));
break;
case "Shipping control":
options.Add(new("Dynamicweb controls shipping", Constants.ShippingControlMode.DynamicwebControlsShipping));
options.Add(new("ERP controls shipping", Constants.ShippingControlMode.ErpControlsShipping));
options.Add(new("ERP calculates shipping cost based on Dynamicweb selection", Constants.ShippingControlMode.ErpCalculatesBasedOnDwSelection));
break;
case "ConnectionToType":
options.Add(new(nameof(ConnectionType.Endpoint), ConnectionType.Endpoint));
options.Add(new("Dynamicweb connector web service", ConnectionType.WebService));
break;
case "ERP Local Currency":
case "ERP Local Currency":
foreach (var currency in Services.Currencies.GetAllCurrencies())
{
options.Add(new($"{currency.GetName(Services.Languages.GetDefaultLanguageId())} - {currency.Code}", currency.Code));
Expand Down Expand Up @@ -796,7 +810,7 @@ IEnumerable<string> IParameterVisibility.GetHiddenParameterNames(string paramete
result.Add("Include variants in the product information request");
result.Add("Max products per request");
}
break;
break;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Discounts;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Extensions;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Logging;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Shipping;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.XmlGenerators;
using Dynamicweb.Ecommerce.Orders;
using Dynamicweb.Ecommerce.Prices;
Expand Down Expand Up @@ -91,6 +92,12 @@ private static ResponseCacheLevel GetOrderCacheLevel(Settings settings)

bool erpControlsDiscount = user.IsUserErpDiscountAllowed(settings);

if (IsAllOrderLinesDiscounts(erpControlsDiscount, order, liveIntegrationSubmitType))
{
Diagnostics.ExecutionTable.Current.Add("DynamicwebLiveIntegration.OrderHandler.UpdateOrder END");
return null;
}
Comment thread
DWDBE marked this conversation as resolved.

Comment thread
DWDBE marked this conversation as resolved.
// default states
successOrderStateId ??= settings.OrderStateAfterExportSucceeded;

Expand All @@ -103,7 +110,7 @@ private static ResponseCacheLevel GetOrderCacheLevel(Settings settings)
LiveIntegrationSubmitType = liveIntegrationSubmitType,
ReferenceName = "OrdersPut",
ErpControlsDiscount = erpControlsDiscount,
ErpControlsShipping = settings.ErpControlsShipping,
ShippingControlMode = settings.ShippingControlMode,
ErpShippingItemKey = settings.ErpShippingItemKey,
ErpShippingItemType = settings.ErpShippingItemType,
CalculateOrderUsingProductNumber = settings.CalculateOrderUsingProductNumber,
Expand Down Expand Up @@ -904,7 +911,7 @@ private static bool ProcessResponse(in OrderResponseContext ctx, XmlDocument res
{
XmlNode orderNode = response.SelectSingleNode("//item [@table='EcomOrders']");
PriceInfo shippingFeeSentInRequest = null;
if (!createOrder && !ctx.Settings.ErpControlsShipping && !string.IsNullOrEmpty(order.ShippingMethodId))
if (!createOrder && ctx.Settings.ShippingControlMode == Constants.ShippingControlMode.DynamicwebControlsShipping && !string.IsNullOrEmpty(order.ShippingMethodId))
{
shippingFeeSentInRequest = order.ShippingFee;
}
Expand Down Expand Up @@ -954,8 +961,15 @@ private static bool ProcessResponse(in OrderResponseContext ctx, XmlDocument res
else
{
SetOrderPrices(order, orderNode, ctx, logger, orderId, out updatePriceBeforeFeesFromOrderPrice);
}
if (ctx.Settings.ShippingControlMode == Constants.ShippingControlMode.ErpCalculatesBasedOnDwSelection)
{
ErpShippingFeeProvider.ProcessShipping(ctx.Settings, order, orderNode, logger);
}
else if (ctx.Settings.ShippingControlMode != Constants.ShippingControlMode.DynamicwebControlsShipping)
{
LiveShippingFeeProvider.ProcessShipping(ctx.Settings, order, orderNode, logger);
}
LiveShippingFeeProvider.ProcessShipping(ctx.Settings, order, orderNode, logger);
}
else
{
Expand All @@ -979,7 +993,7 @@ private static bool ProcessResponse(in OrderResponseContext ctx, XmlDocument res
}
else
{
if (!ctx.Settings.ErpControlsShipping && shippingFeeSentInRequest != null)
if (ctx.Settings.ShippingControlMode == Constants.ShippingControlMode.DynamicwebControlsShipping && shippingFeeSentInRequest != null)
{
UpdateDynamicwebShipping(order, orderNode, shippingFeeSentInRequest, ctx.Settings, logger, updatePriceBeforeFeesFromOrderPrice);
}
Expand Down Expand Up @@ -1174,7 +1188,7 @@ private static void SetPrices(Settings settings, Order order, XmlNode orderNode,
/// <param name="orderNode">The order node.</param>
private static void SetShippingWarning(Settings settings, Order order, XmlNode orderNode)
{
if (!settings.ErpControlsShipping)
if (settings.ShippingControlMode == Constants.ShippingControlMode.DynamicwebControlsShipping)
{
var node = orderNode.SelectSingleNode("column [@columnName='OrderShippingWarning']");
if (node != null)
Expand Down Expand Up @@ -1397,6 +1411,19 @@ internal static void SetCurrentlyProcessingOrder(Order order)
internal static void RemoveCurrentlyProcessingOrder(Order order)
{
Caching.Cache.Current.Remove(OrderCacheKey(order));
}
}

private static bool IsAllOrderLinesDiscounts(bool erpControlsDiscountForUser, Order order, SubmitType liveIntegrationSubmitType)
{
//If no product lines and all lines are discounts remove discount lines and recalculate order
if (!order.Complete && erpControlsDiscountForUser && liveIntegrationSubmitType == SubmitType.LiveOrderOrCart && order.OrderLines.All(ol => ol.IsDiscount()))
{
order.OrderLines.RemoveDiscounts();
order.AllowOverridePrices = false;
Services.Orders.ForcePriceRecalculation(order);
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.NotificationSubscribers;
using Dynamicweb.Ecommerce.Prices;
using Dynamicweb.Extensibility.Notifications;

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Shipping
{
[Subscribe(Ecommerce.Notifications.Ecommerce.Cart.AfterShippingCalculation)]
public class CartAfterShippingCalculation : NotificationSubscriberBase
{
public override void OnNotify(string notification, NotificationArgs args)
{
if (args is null || Context.Current?.Items is null)
return;

var calculationArgs = (Ecommerce.Notifications.Ecommerce.Cart.AfterShippingCalculationArgs)args;
if (string.IsNullOrEmpty(calculationArgs.Shipping?.Id) || calculationArgs.Order is null || Context.Current.Session?[ErpShippingFeeProvider.OrderMarkerKey(calculationArgs.Order.Id)] is null)
{
return;
}

var cached = Context.Current.Session[ErpShippingFeeProvider.MethodCacheKey(calculationArgs.Order.Id, calculationArgs.Shipping?.Id)] as PriceInfo;
if (cached is null)
return;

calculationArgs.Price.PriceWithVAT = cached.PriceWithVAT;
calculationArgs.Price.PriceWithoutVAT = cached.PriceWithoutVAT;
calculationArgs.Price.VAT = cached.VAT;
calculationArgs.Price.VATPercent = cached.VATPercent;
}
}
}
Loading
Loading