diff --git a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj index 2147887..11b9be0 100644 --- a/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.OrderProvider.csproj @@ -1,6 +1,6 @@  - 10.8.1 + 10.8.2 1.0.0.0 Order Provider Order Provider diff --git a/src/OrderProvider.cs b/src/OrderProvider.cs index f0bcb5c..d43ea75 100644 --- a/src/OrderProvider.cs +++ b/src/OrderProvider.cs @@ -23,6 +23,7 @@ namespace Dynamicweb.DataIntegration.Providers.OrderProvider; public class OrderProvider : BaseSqlProvider, IParameterOptions, ISource, IDestination { private const string OrderCustomerAccessUserExternalId = "OrderCustomerAccessUserExternalId"; + private const string OrderLineCalculatedDiscountPercentage = "OrderLineCalculatedDiscountPercentage"; private Job job = null; private Schema Schema { get; set; } private string SqlConnectionString { get; set; } @@ -102,6 +103,7 @@ public override Schema GetOriginalSourceSchema() orderLinesTable.AddColumn(new SqlColumn(column.Name, typeof(string), SqlDbType.NVarChar, orderLinesTable, -1, false, false, true)); } } + orderLinesTable.AddColumn(new SqlColumn(OrderLineCalculatedDiscountPercentage, typeof(double), SqlDbType.NVarChar, orderLinesTable, -1, false, false, true)); } return result; @@ -116,7 +118,7 @@ public override Schema GetOriginalDestinationSchema() if (table.Name == "EcomOrders") { table.AddColumn(new SqlColumn(OrderCustomerAccessUserExternalId, typeof(string), SqlDbType.NVarChar, table, -1, false, false, true)); - } + } } return result; diff --git a/src/OrderSourceReader.cs b/src/OrderSourceReader.cs index 824dc93..94d974c 100644 --- a/src/OrderSourceReader.cs +++ b/src/OrderSourceReader.cs @@ -54,7 +54,7 @@ private void LoadReader(string whereSql) if (_columnMappings.Count == 0) return; - string sql = "select " + GetColumns() + " from " + GetFromTables(); + string sql = $"SELECT * FROM (SELECT {GetColumns()} FROM {GetFromTables()}) AS innerTable "; if (!string.IsNullOrEmpty(whereSql)) sql = sql + " where " + whereSql; @@ -74,7 +74,7 @@ private void LoadReader(string whereSql) } protected override string GetColumns() { - string columns = GetDistinctColumnsFromMapping(new string[] { "OrderCustomerAccessUserExternalId" }); + string columns = GetDistinctColumnsFromMapping(new string[] { "OrderCustomerAccessUserExternalId", "OrderLineCalculatedDiscountPercentage" }); columns = columns.Substring(0, columns.Length - 2); switch (mapping.SourceTable.Name) { @@ -85,8 +85,18 @@ protected override string GetColumns() columns += ", [OrderId]"; } break; + case "EcomOrderLines": + columns = columns + ", (-1 * OrderLineTotalDiscountWithVAT) / OrderLinePriceWithVat * 100 as [OrderLineCalculatedDiscountPercentage]"; + break; + + } + if (mapping.Conditionals.Any()) + { + columns += $", {GetColumnsFromMappingConditions()}"; + columns = columns[..^2]; } + return columns; } @@ -190,7 +200,7 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC if (!string.IsNullOrEmpty(ids)) { command.CommandText = sql + string.Format(" WHERE [OrderID] IN ('{0}')", ids); - command.ExecuteNonQuery(); + command.ExecuteNonQuery(); ClearOrderCache(idsCollection); } taken = taken + step; @@ -199,7 +209,7 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC else { command.CommandText = sql + string.Format(" WHERE [OrderID] IN ('{0}')", string.Join("','", _ordersToExport)); - command.ExecuteNonQuery(); + command.ExecuteNonQuery(); ClearOrderCache(_ordersToExport); } command.Transaction.Commit();