Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.24</Version>
<Version>10.0.25</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Ecom Provider</Title>
<Description>Ecom Provider</Description>
Expand All @@ -14,7 +14,7 @@
<Copyright>Copyright © 2023 Dynamicweb Software A/S</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -23,8 +23,8 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.0.19" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.0.9" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.4.0" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.4.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
116 changes: 33 additions & 83 deletions src/EcomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,99 +820,49 @@ public override ISourceReader GetReader(Mapping mapping)
return new EcomSourceReader(mapping, Connection, GetGroupNamesForVariantOptions, GetManufacturerNamesForProducts, GetGroupNamesForProduct, GetVariantGroupNamesForProduct, GetRelatedProductsByName, GetRelatedProductGroupsByName, SourceLanguage, SourceShop);
}

public override void OrderTablesInJob(Job job, bool isSource)
private readonly Dictionary<string, List<string>> tableRelations = new()
{
MappingCollection tables = new MappingCollection();

var mappings = GetMappingsByName(job.Mappings, "EcomLanguages", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomCountries", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomCurrencies", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomStockLocation", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomGroups", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomManufacturers", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomVariantGroups", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomVariantsOptions", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomProducts", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomProductItems", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomProductsRelated", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomStockUnit", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomDetails", isSource);
if (mappings != null)
tables.AddRange(mappings);

mappings = GetMappingsByName(job.Mappings, "EcomProductCategoryFieldValue", isSource);
if (mappings != null)
tables.AddRange(mappings);
{ "EcomCurrencies", [ "EcomLanguages" ]},
{ "EcomGroups", [ "EcomLanguages" ]},
{ "EcomVariantGroups", [ "EcomLanguages" ]},
{ "EcomProducts", [ "EcomLanguages" ]},
{ "EcomAssortmentShopRelations", [ "EcomShops" ]}
};

public override bool IsSortable(Job job, bool isSource)
{
Func<Mapping, string> tableSelector = isSource ?
(map => map.SourceTable.Name) :
(map => map.DestinationTable.Name);

mappings = GetMappingsByName(job.Mappings, "EcomPrices", isSource);
if (mappings != null)
tables.AddRange(mappings);
var mappedTables = new HashSet<string>(job.Mappings.Select(tableSelector));

mappings = GetMappingsByName(job.Mappings, "EcomDiscount", isSource);
if (mappings != null)
tables.AddRange(mappings);
foreach (var (table, dependencies) in tableRelations)
if (mappedTables.Contains(table) && dependencies.All(mappedTables.Contains))
return false;

mappings = GetMappingsByName(job.Mappings, "EcomAssortments", isSource);
if (mappings != null)
tables.AddRange(mappings);
return true;
}

mappings = GetMappingsByName(job.Mappings, "EcomAssortmentPermissions", isSource);
if (mappings != null)
tables.AddRange(mappings);
public override void OrderTablesInJob(Job job, bool isSource)
{
Func<Mapping, string> tableSelector = isSource ?
(map => map.SourceTable.Name) :
(map => map.DestinationTable.Name);

mappings = GetMappingsByName(job.Mappings, "EcomAssortmentGroupRelations", isSource);
if (mappings != null)
tables.AddRange(mappings);
HashSet<string> priorityTables = tableRelations.Values.SelectMany(v => v).ToHashSet();

mappings = GetMappingsByName(job.Mappings, "EcomAssortmentProductRelations", isSource);
if (mappings != null)
tables.AddRange(mappings);
if (!job.Mappings.Any(m => priorityTables.Any(relations => relations == tableSelector(m))))
return;

mappings = GetMappingsByName(job.Mappings, "EcomAssortmentShopRelations", isSource);
if (mappings != null)
tables.AddRange(mappings);
var priorityMappings = job.Mappings
.Where(m => priorityTables.Contains(tableSelector(m)))
.OrderBy(m => priorityTables.IndexOf(tableSelector(m)));

mappings = GetMappingsByName(job.Mappings, "EcomVariantOptionsProductRelation", isSource);
if (mappings != null)
tables.AddRange(mappings);
var nonPriorityMappings = job.Mappings
.Where(m => !priorityTables.Contains(tableSelector(m)));

job.Mappings = tables;
job.Mappings = [.. priorityMappings.Concat(nonPriorityMappings)];
}

internal static IEnumerable<Mapping> GetMappingsByName(MappingCollection collection, string name, bool isSource)
Expand Down