Skip to content

Commit

Permalink
Merge pull request #38 from dynamicweb/dbe/22539-OrderIsExported-is-n…
Browse files Browse the repository at this point in the history
…ot-set-to-True-after-job-execution

OrderIsExported is not set to True after job execution
  • Loading branch information
DWDBE authored Dec 18, 2024
2 parents 9303fe1 + bc62906 commit ec846a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.9.0</Version>
<Version>10.9.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Order Provider</Title>
<Description>Order Provider</Description>
Expand Down
35 changes: 28 additions & 7 deletions src/OrderSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void LoadReader(string whereSql)
if (_columnMappings.Count == 0)
return;

string sql = $"SELECT * FROM (SELECT {GetColumns()} FROM {GetFromTables()}) AS innerTable ";
string sql = $"SELECT * FROM (SELECT {GetColumns()} FROM {GetFromTables()}) AS innerTable";

if (!string.IsNullOrEmpty(whereSql))
sql = sql + " where " + whereSql;
Expand All @@ -72,6 +72,7 @@ private void LoadReader(string whereSql)
throw new Exception("Failed to open sqlSourceReader. Reason: " + ex.Message, ex);
}
}

protected override string GetColumns()
{
string columns = GetDistinctColumnsFromMapping(new string[] { "OrderCustomerAccessUserExternalId", "OrderLineCalculatedDiscountPercentage" });
Expand All @@ -80,7 +81,7 @@ protected override string GetColumns()
{
case "EcomOrders":
columns = columns + ", [AccessUserExternalId] as [OrderCustomerAccessUserExternalId]";
if (!columns.Split(',').Any(c => c.Trim(new char[] { ' ', '[', ']' }).Equals("OrderId", StringComparison.OrdinalIgnoreCase)))
if (!columns.Split(',').Any(c => c.Trim([' ', '[', ']']).Equals("OrderId", StringComparison.OrdinalIgnoreCase)))
{
columns += ", [OrderId]";
}
Expand All @@ -91,10 +92,30 @@ protected override string GetColumns()

}

string[] standardConditionColumns = ["OrderIsExported", "OrderIntegrationOrderId", "OrderCart", "OrderComplete"];

if (mapping.Conditionals.Any())
{
columns += $", {GetColumnsFromMappingConditions()}";
columns = columns[..^2];
var columnsToSkip = columns.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Union(standardConditionColumns)
.Union(["OrderCustomerAccessUserExternalId", "OrderLineCalculatedDiscountPercentage"])
.Select(c => c.Trim([' ', '[', ']']));
var conditionColumns = GetColumnsFromMappingConditions(columnsToSkip.ToArray());
if (!string.IsNullOrEmpty(conditionColumns))
{
columns += $", {conditionColumns}";
columns = columns[..^2];
}
}

// Add Order source provider standard conditional columns
var splittedColumns = columns.Split(',');
foreach (var column in standardConditionColumns)
{
if (!splittedColumns.Any(c => c.Trim(new char[] { ' ', '[', ']' }).Equals(column, StringComparison.OrdinalIgnoreCase)))
{
columns += $", [{column}]";
}
}

return columns;
Expand Down Expand Up @@ -178,11 +199,11 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC
SqlCommand command = new SqlCommand { Connection = connection };
try
{
command.Transaction = connection.BeginTransaction("OrderProviderTransaction");

if (connection.State.ToString() != "Open")
connection.Open();

command.Transaction = connection.BeginTransaction("OrderProviderTransaction");

string sql = "UPDATE EcomOrders SET OrderIsExported = 1";

if (!string.IsNullOrEmpty(orderStateIDAfterExport))
Expand Down Expand Up @@ -216,7 +237,7 @@ public static void UpdateExportedOrdersInDb(string orderStateIDAfterExport, SqlC
}
catch (Exception ex)
{
command.Transaction.Rollback();
command?.Transaction?.Rollback();
throw new Exception(string.Format("A rollback is made as exception is made with message: {0} Sql query: {1}", ex.Message, command.CommandText), ex);
}
finally
Expand Down

0 comments on commit ec846a5

Please sign in to comment.