Fix: Text import variant parsing now correctly handles value, price, and stock
- Fixed variant parsing to accept 3 fields: value, price override, stock quantity - Removed invalid VariantTypes navigation property reference - Auto-detect variant type (Weight for grams, Quantity for units) - Format: - VariantValue; PriceOverride; StockQuantity 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
daa59e3271
commit
77d29e14c1
@ -605,7 +605,7 @@ public class ProductImportService : IProductImportService
|
||||
var variantLines = lines.Where(l => l.TrimStart().StartsWith("-")).ToList();
|
||||
for (int i = 0; i < variantLines.Count; i++)
|
||||
{
|
||||
await ParseAndImportVariantLine(product.Id, variantLines[i], i);
|
||||
await ParseAndImportVariantLine(product.Id, variantLines[i], i, variantCollectionId);
|
||||
}
|
||||
|
||||
// Parse and import multi-buys (lines starting with +)
|
||||
@ -656,27 +656,31 @@ public class ProductImportService : IProductImportService
|
||||
return properties;
|
||||
}
|
||||
|
||||
private async Task ParseAndImportVariantLine(Guid productId, string line, int sortOrder)
|
||||
private async Task ParseAndImportVariantLine(Guid productId, string line, int sortOrder, Guid? variantCollectionId)
|
||||
{
|
||||
// Format: - VariantName; Price; OptionalStockLevel
|
||||
// Example: - Small; 8.00; 50
|
||||
// Format: - VariantValue; PriceOverride; StockQuantity
|
||||
// Example: - 10; 30.00; 100 (for "10 tablets at £30.00 with 100 in stock")
|
||||
var content = line.TrimStart('-').Trim();
|
||||
var parts = content.Split(';').Select(p => p.Trim()).ToArray();
|
||||
|
||||
if (parts.Length < 2) return; // Need at least name and price
|
||||
if (parts.Length < 3) return; // Need variant value, price, and stock
|
||||
|
||||
var variantName = parts[0];
|
||||
var price = ParseDecimal(parts[1], "variant price");
|
||||
var stockLevel = parts.Length > 2 ? ParseInt(parts[2], "variant stock") : 0;
|
||||
var variantValue = parts[0]; // The value (e.g., "10", "25", "3.5g", "28g")
|
||||
var priceOverride = ParseDecimal(parts[1], "variant price");
|
||||
var stockQuantity = ParseInt(parts[2], "variant stock");
|
||||
|
||||
// Determine variant type based on the value format
|
||||
// If it contains 'g' (grams), use "Weight", otherwise use "Quantity"
|
||||
string variantType = variantValue.ToLower().Contains("g") ? "Weight" : "Quantity";
|
||||
|
||||
var variantDto = new CreateProductVariantDto
|
||||
{
|
||||
ProductId = productId,
|
||||
Name = variantName,
|
||||
Price = price,
|
||||
StockLevel = stockLevel,
|
||||
Name = variantValue,
|
||||
Price = priceOverride,
|
||||
StockLevel = stockQuantity,
|
||||
SortOrder = sortOrder,
|
||||
VariantType = "Standard"
|
||||
VariantType = variantType
|
||||
};
|
||||
|
||||
await _productService.CreateProductVariantAsync(variantDto);
|
||||
|
||||
@ -79,7 +79,7 @@ Dutch import
|
||||
category: Vitamins
|
||||
price: 30.00
|
||||
weight: 10
|
||||
unit: Single
|
||||
unit: Unit
|
||||
stock: 100
|
||||
|
||||
- 10; 30.00; 100
|
||||
@ -94,7 +94,7 @@ stock: 100
|
||||
category: Vitamins
|
||||
price: 40.00
|
||||
weight: 10
|
||||
unit: Single
|
||||
unit: Unit
|
||||
stock: 100
|
||||
|
||||
- 10; 40.00; 100
|
||||
@ -105,7 +105,7 @@ stock: 100
|
||||
category: Vitamins
|
||||
price: 30.00
|
||||
weight: 10
|
||||
unit: Single
|
||||
unit: Unit
|
||||
stock: 100
|
||||
|
||||
- 10; 30.00; 100
|
||||
@ -147,7 +147,7 @@ stock: 100
|
||||
category: Vitamins
|
||||
price: 50.00
|
||||
weight: 10
|
||||
unit: Single
|
||||
unit: Unit
|
||||
stock: 100
|
||||
|
||||
- 10; 50.00; 100
|
||||
@ -159,7 +159,7 @@ stock: 100
|
||||
category: Herbal
|
||||
price: 60.00
|
||||
weight: 10
|
||||
unit: Single
|
||||
unit: Unit
|
||||
stock: 100
|
||||
|
||||
- 10; 60.00; 100
|
||||
|
||||
Loading…
Reference in New Issue
Block a user