Skip to content

Commit 9bcade5

Browse files
VCST-4203: Remove obsolete code (#129)
1 parent 0c19c09 commit 9bcade5

File tree

9 files changed

+75
-47
lines changed

9 files changed

+75
-47
lines changed

src/VirtoCommerce.CatalogCsvImportModule.Core/Model/CsvProduct.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,21 @@ public string Sku
260260

261261
public string ParentSku { get; set; }
262262

263+
private string _categoryPath;
263264
public string CategoryPath
264265
{
265266
get
266267
{
267-
if (Category == null)
268+
if (Category != null)
268269
{
269-
return null;
270+
return Category.Path;
270271
}
271272

272-
return Category.Path;
273+
return _categoryPath;
273274
}
274275
set
275276
{
276-
Category = new Category { Path = value };
277+
_categoryPath = value;
277278
}
278279
}
279280

src/VirtoCommerce.CatalogCsvImportModule.Core/VirtoCommerce.CatalogCsvImportModule.Core.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
1616
<PackageReference Include="ValueInjecter" Version="3.2.0" />
17-
<PackageReference Include="VirtoCommerce.AssetsModule.Core" Version="3.808.0" />
18-
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.889.0" />
19-
<PackageReference Include="VirtoCommerce.InventoryModule.Core" Version="3.813.0" />
20-
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.895.0" />
21-
<PackageReference Include="VirtoCommerce.PricingModule.Core" Version="3.809.0" />
17+
<PackageReference Include="VirtoCommerce.AssetsModule.Core" Version="3.814.0" />
18+
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.904.0" />
19+
<PackageReference Include="VirtoCommerce.InventoryModule.Core" Version="3.815.0" />
20+
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.917.0" />
21+
<PackageReference Include="VirtoCommerce.PricingModule.Core" Version="3.822.0" />
2222
</ItemGroup>
2323
</Project>

src/VirtoCommerce.CatalogCsvImportModule.Data/Services/CsvCatalogImporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ private async Task<IList<PropertyDictionaryItem>> GetExistingDictionaryItems(Lis
290290
}
291291

292292
/// <summary>
293-
/// Try to find (create if not) categories for products with Category.Path
293+
/// Try to find (create if not) categories for products with CategoryPath
294294
/// </summary>
295295
private async Task SaveCategoryTree(Catalog catalog, IEnumerable<CsvProduct> csvProducts, ExportImportProgressInfo progressInfo, Action<ExportImportProgressInfo> progressCallback)
296296
{
297297
var cachedCategoryMap = new Dictionary<string, Category>();
298298
var outline = new StringBuilder();
299299

300-
foreach (var csvProduct in csvProducts.Where(x => x.Category != null && !string.IsNullOrEmpty(x.Category.Path)))
300+
foreach (var csvProduct in csvProducts.Where(x => x.Category is null && !string.IsNullOrEmpty(x.CategoryPath)))
301301
{
302302
outline.Clear();
303303
string parentCategoryId = null;
304304
var count = progressInfo.ProcessedCount;
305-
var productCategoryNames = csvProduct.Category.Path.Split(_categoryDelimiters);
305+
var productCategoryNames = csvProduct.CategoryPath.Split(_categoryDelimiters);
306306

307307
foreach (var categoryName in productCategoryNames)
308308
{

src/VirtoCommerce.CatalogCsvImportModule.Data/VirtoCommerce.CatalogCsvImportModule.Data.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<GenerateDocumentationFile>true</GenerateDocumentationFile>
55
<IsPackable>True</IsPackable>
66
<noWarn>1591</noWarn>
7-
<LangVersion>latest</LangVersion>
87
<PublishRepositoryUrl>true</PublishRepositoryUrl>
98
<EmbedUntrackedSources>true</EmbedUntrackedSources>
109
<IncludeSymbols>true</IncludeSymbols>
@@ -19,16 +18,16 @@
1918
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
2019
<PackageReference Include="CsvHelper" Version="33.0.1" />
2120
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
22-
<PackageReference Include="VirtoCommerce.CatalogModule.Data" Version="3.889.0" />
23-
<PackageReference Include="VirtoCommerce.StoreModule.Core" Version="3.818.0" />
21+
<PackageReference Include="VirtoCommerce.CatalogModule.Data" Version="3.904.0" />
22+
<PackageReference Include="VirtoCommerce.StoreModule.Core" Version="3.823.0" />
2423
</ItemGroup>
2524
<ItemGroup>
2625
<ProjectReference Include="..\VirtoCommerce.CatalogCsvImportModule.Core\VirtoCommerce.CatalogCsvImportModule.Core.csproj" />
2726
</ItemGroup>
2827

2928
<!--Workaround for vulnerable transitive packages-->
3029
<ItemGroup>
31-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
30+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="[8.0.1,9)" />
3231
</ItemGroup>
3332

3433
</Project>

src/VirtoCommerce.CatalogCsvImportModule.Web/VirtoCommerce.CatalogCsvImportModule.Web.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<GenerateDocumentationFile>true</GenerateDocumentationFile>
55
<noWarn>1591</noWarn>
66
<IsPackable>False</IsPackable>
7-
<LangVersion>latest</LangVersion>
87
<OutputType>Library</OutputType>
98
</PropertyGroup>
109
<PropertyGroup>
@@ -22,8 +21,8 @@
2221
<None Remove="node_modules\**" />
2322
</ItemGroup>
2423
<ItemGroup>
25-
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.821.0" />
26-
<PackageReference Include="VirtoCommerce.Platform.Hangfire" Version="3.895.0" />
24+
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.824.0" />
25+
<PackageReference Include="VirtoCommerce.Platform.Hangfire" Version="3.917.0" />
2726
</ItemGroup>
2827
<ItemGroup>
2928
<ProjectReference Include="..\VirtoCommerce.CatalogCsvImportModule.Core\VirtoCommerce.CatalogCsvImportModule.Core.csproj" />

src/VirtoCommerce.CatalogCsvImportModule.Web/module.manifest

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<version>3.817.0</version>
55
<version-tag />
66

7-
<platformVersion>3.895.0</platformVersion>
7+
<platformVersion>3.917.0</platformVersion>
88
<dependencies>
9-
<dependency id="VirtoCommerce.Assets" version="3.808.0" />
10-
<dependency id="VirtoCommerce.Catalog" version="3.889.0" />
11-
<dependency id="VirtoCommerce.Core" version="3.821.0" />
12-
<dependency id="VirtoCommerce.Inventory" version="3.813.0" />
13-
<dependency id="VirtoCommerce.Pricing" version="3.809.0" />
14-
<dependency id="VirtoCommerce.Store" version="3.818.0" />
9+
<dependency id="VirtoCommerce.Assets" version="3.814.0" />
10+
<dependency id="VirtoCommerce.Catalog" version="3.904.0" />
11+
<dependency id="VirtoCommerce.Core" version="3.824.0" />
12+
<dependency id="VirtoCommerce.Inventory" version="3.815.0" />
13+
<dependency id="VirtoCommerce.Pricing" version="3.822.0" />
14+
<dependency id="VirtoCommerce.Store" version="3.823.0" />
1515
</dependencies>
1616

1717
<title>CSV Catalog Export and Import Module</title>

tests/VirtoCommerce.CatalogCsvImportModule.Test/ImporterTests.cs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,30 @@ public async Task DoImport_ProductNameShouldBeTrimmed()
15351535
Assert.Equal(expectedProductName, product.Name);
15361536
}
15371537

1538+
[Fact]
1539+
public async Task DoImport_ProductShouldBePlacedInCorrectCategory()
1540+
{
1541+
// Arrange
1542+
var product = GetCsvProductBase();
1543+
product.CategoryPath = "Category1/Category2/Category3";
1544+
product.Category = null;
1545+
1546+
var target = GetImporter();
1547+
var exportInfo = new ExportImportProgressInfo();
1548+
1549+
// Act
1550+
await target.DoImport([product], GetCsvImportInfo(), exportInfo, _ => { });
1551+
1552+
// Assert
1553+
Assert.NotNull(product.Category);
1554+
Assert.Equal("Category3", product.Category.Name);
1555+
1556+
Assert.Equal(3, _categoriesInternal.Count);
1557+
Assert.Equal("Category1", _categoriesInternal[0].Name);
1558+
Assert.Equal("Category2", _categoriesInternal[1].Name);
1559+
Assert.Equal("Category3", _categoriesInternal[2].Name);
1560+
}
1561+
15381562

15391563
private CsvCatalogImporter GetImporter(IPropertyDictionaryItemService propertyDictionaryItemService = null, bool? createDictionaryValues = false)
15401564
{
@@ -1560,8 +1584,8 @@ private CsvCatalogImporter GetImporter(IPropertyDictionaryItemService propertyDi
15601584

15611585
var categoryService = new Mock<ICategoryService>();
15621586
categoryService
1563-
.Setup(x => x.SaveChangesAsync(It.IsAny<Category[]>()))
1564-
.Returns((Category[] cats) =>
1587+
.Setup(x => x.SaveChangesAsync(It.IsAny<IList<Category>>()))
1588+
.Returns((IList<Category> cats) =>
15651589
{
15661590
foreach (var category in cats.Where(x => x.Id == null))
15671591
{
@@ -1602,7 +1626,24 @@ private CsvCatalogImporter GetImporter(IPropertyDictionaryItemService propertyDi
16021626
.ReturnsAsync((CategorySearchCriteria criteria, bool _) =>
16031627
{
16041628
var result = new CategorySearchResult();
1605-
var categories = _categoriesInternal.Where(x => criteria.CatalogIds.Contains(x.CatalogId) || criteria.ObjectIds.Contains(x.Id)).ToList();
1629+
var query = _categoriesInternal.AsQueryable();
1630+
1631+
if (!criteria.CatalogIds.IsNullOrEmpty())
1632+
{
1633+
query = query.Where(x => criteria.CatalogIds.Contains(x.CatalogId));
1634+
}
1635+
1636+
if (!string.IsNullOrEmpty(criteria.CategoryId) && !criteria.SearchOnlyInRoot)
1637+
{
1638+
query = query.Where(x => x.ParentId == criteria.CategoryId);
1639+
}
1640+
1641+
if (criteria.SearchOnlyInRoot)
1642+
{
1643+
query = query.Where(x => x.ParentId == null);
1644+
}
1645+
1646+
var categories = query.ToList();
16061647
var cloned = categories.Select(x => x.CloneTyped()).ToList();
16071648
foreach (var category in cloned)
16081649
{
@@ -1989,11 +2030,7 @@ private static CsvProduct GetCsvProductBase()
19892030

19902031
return new CsvProduct
19912032
{
1992-
Category = new Category
1993-
{
1994-
Parents = [],
1995-
Path = "TestCategory",
1996-
},
2033+
CategoryPath = "TestCategory",
19972034
Code = "TST1",
19982035
Currency = "USD",
19992036
EditorialReview = review,
@@ -2018,11 +2055,7 @@ private static CsvProduct GetCsvProductWithMainProduct(string mainProductIdOrSku
20182055

20192056
return new CsvProduct
20202057
{
2021-
Category = new Category
2022-
{
2023-
Parents = [],
2024-
Path = "TestCategory",
2025-
},
2058+
CategoryPath = "TestCategory",
20262059
Code = "TST2",
20272060
Currency = "USD",
20282061
EditorialReview = review,
@@ -2048,8 +2081,7 @@ private Category CreateCategory(CsvProduct existingProduct)
20482081
Id = Guid.NewGuid().ToString(),
20492082
Catalog = _catalog,
20502083
CatalogId = _catalog.Id,
2051-
Name = existingProduct.Category.Path,
2052-
Path = existingProduct.CategoryPath,
2084+
Name = existingProduct.CategoryPath,
20532085
Properties = new List<Property>(),
20542086
};
20552087

tests/VirtoCommerce.CatalogCsvImportModule.Test/MappingTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public async Task CsvProductMapTest_CsvHasCategoryPath_CategoryPathMapped()
147147
var product = csvProducts.First();
148148

149149
Assert.Equal("TestCategory1", product.CategoryPath);
150-
Assert.Equal("TestCategory1", product.Category.Path);
151150
}
152151

153152
[Fact]
@@ -170,7 +169,6 @@ public async Task CsvProductMapTest_MappingHasDefaultCategoryPath_DefaultCategor
170169
var product = csvProducts.First();
171170

172171
Assert.Equal(defaultCategoryPath, product.CategoryPath);
173-
Assert.Equal(defaultCategoryPath, product.Category.Path);
174172
}
175173

176174
[Fact]

tests/VirtoCommerce.CatalogCsvImportModule.Test/VirtoCommerce.CatalogCsvImportModule.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<GenerateDocumentationFile>true</GenerateDocumentationFile>
55
<noWarn>1591</noWarn>
6-
<LangVersion>latest</LangVersion>
76
</PropertyGroup>
87
<ItemGroup>
98
<PackageReference Include="AutoFixture" Version="4.18.1" />

0 commit comments

Comments
 (0)