nopSolutions/nopCommerce · error · ArgumentException

Admin.Orders.Import.ProductsDontExist

Error message

Admin.Orders.Import.ProductsDontExist

What it means

Thrown during order XLSX import when product SKUs referenced in the order-item lines do not exist in the database. nopCommerce batches all referenced order-item SKUs into one SQL check (GetNotExistingProductsAsync) and aborts the entire import with an ArgumentException listing the missing SKUs.

Source

Thrown at src/Libraries/Nop.Services/ExportImport/ImportManager.cs:1623

                if (!string.IsNullOrEmpty(customerGuidString) && Guid.TryParse(customerGuidString, out var customerGuid))
                    allCustomerGuids.Add(customerGuid);
            }

            //counting the number of orders
            countOrdersInFile++;

            endRow++;
        }

        //performance optimization, the check for the existence of the customers in one SQL request
        var notExistingCustomerGuids = await _customerService.GetNotExistingCustomersAsync(allCustomerGuids.ToArray());
        if (notExistingCustomerGuids.Any())
            throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync("Admin.Orders.Import.CustomersDontExist"), string.Join(", ", notExistingCustomerGuids)));

        //performance optimization, the check for the existence of the order items in one SQL request
        var notExistingProductSkus = await _productService.GetNotExistingProductsAsync(allOrderItemSkus.ToArray());
        if (notExistingProductSkus.Any())
            throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync("Admin.Orders.Import.ProductsDontExist"), string.Join(", ", notExistingProductSkus)));

        return (new ImportOrderMetadata
        {
            EndRow = endRow,
            Manager = manager,
            Properties = defaultProperties,
            CountOrdersInFile = countOrdersInFile,
            OrderItemManager = orderItemManager,
            AllOrderGuids = allOrderGuids,
            AllCustomerGuids = allCustomerGuids
        }, worksheet);
    }

    /// <returns>A task that represents the asynchronous operation</returns>
    protected virtual async Task<(ImportPriceListMetadata, IXLWorksheet)> PrepareImportPriceListDataAsync(IXLWorkbook workbook)
    {
        var languages = await _languageService.GetAllLanguagesAsync(showHidden: true);

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Import products first and ensure each order-item SKU matches an existing product SKU exactly (trim/whitespace-sensitive).
  2. Export current product SKUs and diff against the order file to find mismatches.
  3. Remove order-item rows referencing non-existent SKUs.
  4. When migrating, import products before orders and keep SKUs stable across environments.

Example fix

// before
await _importManager.ImportOrdersFromXlsxAsync(stream);

// after — validate order-item SKUs up front
var existingSkus = (await _productService.SearchProductsAsync(0, int.MaxValue)).products.Select(p => p.Sku).Where(s => !string.IsNullOrWhiteSpace(s)).ToHashSet(StringComparer.OrdinalIgnoreCase);
var badSkus = orderItemSkus.Where(s => !existingSkus.Contains(s.Trim())).ToList();
if (badSkus.Any())
    return BadRequest($"These product SKUs do not exist: {string.Join(", ", badSkus)}");
await _importManager.ImportOrdersFromXlsxAsync(stream);
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate order-item SKUs against existing products
var skus = (await _productService.SearchProductsAsync(0, int.MaxValue)).products
    .Select(p => p.Sku).Where(s => !string.IsNullOrWhiteSpace(s))
    .ToHashSet(StringComparer.OrdinalIgnoreCase);
var bad = orderItemSkus.Where(s => !skus.Contains(s.Trim())).ToList();
if (bad.Any())
    return BadRequest($"These product SKUs do not exist: {string.Join(", ", bad)}");
await _importManager.ImportOrdersFromXlsxAsync(stream);

Try / catch

try { await _importManager.ImportOrdersFromXlsxAsync(stream); }
catch (ArgumentException ex) when (ex.Message.Contains("ProductsDontExist"))
{ /* surface the missing order-item SKUs */ }

Prevention

When it happens

Trigger: Calling ImportOrdersFromXlsxAsync with an XLSX whose order-item SKU column references SKUs that have no matching Product. Fires after the customer-GUID check, just before ImportOrderMetadata is returned.

Common situations: Order spreadsheet references products whose SKUs were never migrated or were changed; products deleted after export; SKUs contain leading/trailing whitespace or casing differences; importing orders before products on a fresh DB.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/81c29717b8f06500. Report an issue: GitHub.