Skip to content

Commit a1bf022

Browse files
committed
New import column mapping (part 2)
1 parent 0a8121c commit a1bf022

19 files changed

Lines changed: 376 additions & 318 deletions

File tree

src/Libraries/SmartStore.Core/Domain/DataExchange/ImportProfile.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public ImportEntityType EntityType
7070
/// </summary>
7171
public int Take { get; set; }
7272

73+
/// <summary>
74+
/// Whether to only update existing data
75+
/// </summary>
76+
public bool UpdateOnly { get; set; }
77+
78+
/// <summary>
79+
/// Name of key fields to identify existing records during import
80+
/// </summary>
81+
public string KeyFieldNames { get; set; }
82+
7383
/// <summary>
7484
/// File type specific configuration
7585
/// </summary>

src/Libraries/SmartStore.Data/Mapping/DataExchange/ImportProfileMap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public ImportProfileMap()
1212

1313
this.Property(x => x.Name).IsRequired().HasMaxLength(100);
1414
this.Property(x => x.FolderName).IsRequired().HasMaxLength(100);
15+
this.Property(x => x.KeyFieldNames).HasMaxLength(1000);
1516
this.Property(x => x.FileTypeConfiguration).IsMaxLength();
1617
this.Property(x => x.ColumnMapping).IsMaxLength();
1718
this.Property(x => x.ResultInfo).IsMaxLength();

src/Libraries/SmartStore.Data/Migrations/201512151526290_ImportFramework.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,16 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
199199
builder.AddOrUpdate("Admin.Promotions.NewsLetterSubscriptions.Fields.NewsLetterSubscriptionGuid", "Subscription GUID", "Abonnement GUID");
200200

201201
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.Note",
202-
"For each field of the import file you can optionally set whether and to which object property the data is to be imported. Not yet selected properties are highlighted in the selection list. It is also possible to define a default value which is applied when the import field is empty. Through <b>Clear</b> all made assignments are reset to their original values.",
203-
"Sie können optional für jedes Feld der Importdatei festlegen, ob und nach welcher Objekteigenschaft dessen Daten importiert werden sollen. Noch nicht ausgewählte Eigenschaften sind dabei in der Auswahlliste hervorgehoben. Zudem ist die Angabe eines Standardwertes möglich, der angewendet wird, wenn das Importfeld leer ist. Über <b>Zurücksetzen</b> werden alle getätigten Zuordnungen auf ihre Ursprungswerte zurückgesetzt.");
202+
"You can optionally set for each field of the import file whether and for which object property the data should be imported. Fields with equal names are always imported as long as they are not explicitly ignored. Not yet selected properties are highlighted in the selection list. It is also possible to define a default value which is applied when the import field is empty.",
203+
"Sie können optional für jedes Feld der Importdatei festlegen, ob und nach welcher Objekteigenschaft dessen Daten zu importieren sind. Gleichnamige Felder werden grundsätzlich immer importiert, sofern sie nicht explizit ignoriert werden sollen. Noch nicht ausgewählte Eigenschaften sind in der Auswahlliste hervorgehoben. Zudem ist die Angabe eines Standardwertes möglich, der angewendet wird, wenn das Importfeld leer ist.");
204204

205205
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.ImportField", "Import Field", "Importfeld");
206206
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.EntityProperty", "Object property", "Eigenschaft des Objektes");
207207
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.DefaultValue", "Default Value", "Standardwert");
208208

209-
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.Validate.EntityMultipleMapped",
210-
"The object property \"{0}\" was assigned several times. Please assign each property only once.",
211-
"Die Objekteigenschaft \"{0}\" wurde mehrfach zugeodnet. Bitte ordnen Sie jede Eigenschaft nur einmal zu.");
209+
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.Validate.MultipleMappedIgnored",
210+
"The following object properties were multiple assigned and thus ignored: {0}",
211+
"Die folgenden Objekteigenschaft wurden mehrfach zugeodnet und deshalb ignoriert: {0}");
212212

213213

214214
builder.Delete(

src/Libraries/SmartStore.Data/Migrations/201601201138510_ImportFramework1.resx

Lines changed: 0 additions & 126 deletions
This file was deleted.

src/Libraries/SmartStore.Data/Migrations/201601201138510_ImportFramework1.Designer.cs renamed to src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Libraries/SmartStore.Data/Migrations/201601201138510_ImportFramework1.cs renamed to src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ public partial class ImportFramework1 : DbMigration, ILocaleResourcesProvider, I
77
{
88
public override void Up()
99
{
10+
AddColumn("dbo.ImportProfile", "UpdateOnly", c => c.Boolean(nullable: false));
11+
AddColumn("dbo.ImportProfile", "KeyFieldNames", c => c.String(maxLength: 1000));
1012
AddColumn("dbo.ImportProfile", "ResultInfo", c => c.String());
1113
}
1214

1315
public override void Down()
1416
{
1517
DropColumn("dbo.ImportProfile", "ResultInfo");
18+
DropColumn("dbo.ImportProfile", "KeyFieldNames");
19+
DropColumn("dbo.ImportProfile", "UpdateOnly");
1620
}
1721

1822
public bool RollbackOnFailure
@@ -75,12 +79,28 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
7579
"Import von Profil \"{0}\" ist abgeschlossen");
7680

7781
builder.AddOrUpdate("Admin.DataExchange.Import.ColumnMapping",
78-
"Mapping of import fields",
82+
"Assignment of import fields",
7983
"Zuordnung der Importfelder");
8084

8185
builder.AddOrUpdate("Admin.DataExchange.Import.SelectTargetProperty",
82-
"Create new mapping here",
86+
"Create new assignment here",
8387
"Hier neue Zuordnung vornehmen");
88+
89+
builder.AddOrUpdate("Admin.DataExchange.Import.UpdateOnly",
90+
"Only update",
91+
"Nur aktualisieren",
92+
"If this option is enabled, only existing data is updated but no new records are added.",
93+
"Ist diese Option aktiviert, werden nur vorhandene Daten aktualisiert, aber keine neue Datensätze hinzugefügt.");
94+
95+
builder.AddOrUpdate("Admin.DataExchange.Import.KeyFieldNames",
96+
"Key fields",
97+
"Schlüsselfelder",
98+
"Existing records can be identified on the basis of key fields. The key fields are processed in the order that is defined here.",
99+
"Anhand von Schlüsselfeldern können vorhandene Datensätze identifiziert werden. Die Schlüsselfelder werden in der hier festgelegten Reihenfolge verarbeitet.");
100+
101+
builder.AddOrUpdate("Admin.DataExchange.ColumnMapping.Validate.OneMappingRequired",
102+
"At least one field assignment is required.",
103+
"Es ist mindestens eine Feldzuordnung erforderlich.");
84104
}
85105
}
86106
}

src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/SmartStore.Data/SmartStore.Data.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@
376376
<Compile Include="Migrations\201512151526290_ImportFramework.Designer.cs">
377377
<DependentUpon>201512151526290_ImportFramework.cs</DependentUpon>
378378
</Compile>
379-
<Compile Include="Migrations\201601201138510_ImportFramework1.cs" />
380-
<Compile Include="Migrations\201601201138510_ImportFramework1.Designer.cs">
381-
<DependentUpon>201601201138510_ImportFramework1.cs</DependentUpon>
379+
<Compile Include="Migrations\201601262000441_ImportFramework1.cs" />
380+
<Compile Include="Migrations\201601262000441_ImportFramework1.Designer.cs">
381+
<DependentUpon>201601262000441_ImportFramework1.cs</DependentUpon>
382382
</Compile>
383383
<Compile Include="Setup\Builder\ActivityLogTypeMigrator.cs" />
384384
<Compile Include="Setup\Builder\PermissionMigrator.cs" />
@@ -707,8 +707,8 @@
707707
<EmbeddedResource Include="Migrations\201512151526290_ImportFramework.resx">
708708
<DependentUpon>201512151526290_ImportFramework.cs</DependentUpon>
709709
</EmbeddedResource>
710-
<EmbeddedResource Include="Migrations\201601201138510_ImportFramework1.resx">
711-
<DependentUpon>201601201138510_ImportFramework1.cs</DependentUpon>
710+
<EmbeddedResource Include="Migrations\201601262000441_ImportFramework1.resx">
711+
<DependentUpon>201601262000441_ImportFramework1.cs</DependentUpon>
712712
</EmbeddedResource>
713713
<EmbeddedResource Include="Sql\Indexes.sql" />
714714
<EmbeddedResource Include="Sql\StoredProcedures.sql" />

src/Libraries/SmartStore.Services/Catalog/Importer/CategoryImporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ private int ProcessCategories(IImportExecuteContext context,
223223
context.Result.AddError("The 'Name' field is required for new categories. Skipping row.", row.GetRowInfo(), "Name");
224224
continue;
225225
}
226+
227+
if (context.UpdateOnly)
228+
{
229+
continue;
230+
}
231+
226232
category = new Category
227233
{
228234
CategoryTemplateId = defaultTemplateId

src/Libraries/SmartStore.Services/Catalog/Importer/ProductImporter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ private int ProcessProducts(IImportExecuteContext context, ImportRow<Product>[]
412412
context.Result.AddError("The 'Name' field is required for new products. Skipping row.", row.GetRowInfo(), "Name");
413413
continue;
414414
}
415+
416+
if (context.UpdateOnly)
417+
{
418+
continue;
419+
}
420+
415421
product = new Product();
416422
}
417423

0 commit comments

Comments
 (0)