{"record":{"id":"81c29717b8f06500","repo":"nopSolutions/nopCommerce","slug":"admin-orders-import-productsdontexist","errorCode":null,"errorMessage":"Admin.Orders.Import.ProductsDontExist","messagePattern":"Admin\\.Orders\\.Import\\.ProductsDontExist","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/ExportImport/ImportManager.cs","lineNumber":1623,"sourceCode":"                if (!string.IsNullOrEmpty(customerGuidString) && Guid.TryParse(customerGuidString, out var customerGuid))\r\n                    allCustomerGuids.Add(customerGuid);\r\n            }\r\n\r\n            //counting the number of orders\r\n            countOrdersInFile++;\r\n\r\n            endRow++;\r\n        }\r\n\r\n        //performance optimization, the check for the existence of the customers in one SQL request\r\n        var notExistingCustomerGuids = await _customerService.GetNotExistingCustomersAsync(allCustomerGuids.ToArray());\r\n        if (notExistingCustomerGuids.Any())\r\n            throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync(\"Admin.Orders.Import.CustomersDontExist\"), string.Join(\", \", notExistingCustomerGuids)));\r\n\r\n        //performance optimization, the check for the existence of the order items in one SQL request\r\n        var notExistingProductSkus = await _productService.GetNotExistingProductsAsync(allOrderItemSkus.ToArray());\r\n        if (notExistingProductSkus.Any())\r\n            throw new ArgumentException(string.Format(await _localizationService.GetResourceAsync(\"Admin.Orders.Import.ProductsDontExist\"), string.Join(\", \", notExistingProductSkus)));\r\n\r\n        return (new ImportOrderMetadata\r\n        {\r\n            EndRow = endRow,\r\n            Manager = manager,\r\n            Properties = defaultProperties,\r\n            CountOrdersInFile = countOrdersInFile,\r\n            OrderItemManager = orderItemManager,\r\n            AllOrderGuids = allOrderGuids,\r\n            AllCustomerGuids = allCustomerGuids\r\n        }, worksheet);\r\n    }\r\n\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    protected virtual async Task<(ImportPriceListMetadata, IXLWorksheet)> PrepareImportPriceListDataAsync(IXLWorkbook workbook)\r\n    {\r\n        var languages = await _languageService.GetAllLanguagesAsync(showHidden: true);\r\n\r","sourceCodeStart":1605,"sourceCodeEnd":1641,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ExportImport/ImportManager.cs#L1605-L1641","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Import products first and ensure each order-item SKU matches an existing product SKU exactly (trim/whitespace-sensitive).","Export current product SKUs and diff against the order file to find mismatches.","Remove order-item rows referencing non-existent SKUs.","When migrating, import products before orders and keep SKUs stable across environments."],"exampleFix":"// before\nawait _importManager.ImportOrdersFromXlsxAsync(stream);\n\n// after — validate order-item SKUs up front\nvar existingSkus = (await _productService.SearchProductsAsync(0, int.MaxValue)).products.Select(p => p.Sku).Where(s => !string.IsNullOrWhiteSpace(s)).ToHashSet(StringComparer.OrdinalIgnoreCase);\nvar badSkus = orderItemSkus.Where(s => !existingSkus.Contains(s.Trim())).ToList();\nif (badSkus.Any())\n    return BadRequest($\"These product SKUs do not exist: {string.Join(\", \", badSkus)}\");\nawait _importManager.ImportOrdersFromXlsxAsync(stream);","handlingStrategy":"validation","validationCode":"// Pre-validate order-item SKUs against existing products\nvar skus = (await _productService.SearchProductsAsync(0, int.MaxValue)).products\n    .Select(p => p.Sku).Where(s => !string.IsNullOrWhiteSpace(s))\n    .ToHashSet(StringComparer.OrdinalIgnoreCase);\nvar bad = orderItemSkus.Where(s => !skus.Contains(s.Trim())).ToList();\nif (bad.Any())\n    return BadRequest($\"These product SKUs do not exist: {string.Join(\", \", bad)}\");\nawait _importManager.ImportOrdersFromXlsxAsync(stream);","typeGuard":null,"tryCatchPattern":"try { await _importManager.ImportOrdersFromXlsxAsync(stream); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ProductsDontExist\"))\n{ /* surface the missing order-item SKUs */ }","preventionTips":["Import products before orders and keep SKUs stable across environments.","Trim and reconcile SKUs case-insensitively before importing.","Remove order-item rows whose SKUs no longer exist."],"tags":["import","orders","products","sku","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}