{"record":{"id":"8d089fee8aaca983","repo":"nopSolutions/nopCommerce","slug":"product-not-found","errorCode":null,"errorMessage":"Product not found","messagePattern":"Product not found","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Factories/MenuModelFactory.cs","lineNumber":136,"sourceCode":"    /// <param name=\"model\">Menu item model</param>\n    /// <param name=\"entityId\">Entity identifier</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// </returns>\n    protected virtual async Task InitMenuItemModelEntityIdAsync(MenuItemModel model, int entityId)\n    {\n        ArgumentOutOfRangeException.ThrowIfZero(entityId);\n\n        try\n        {\n            switch ((MenuItemType)model.MenuItemTypeId)\n            {\n                case MenuItemType.Product:\n                {\n                    var product = await _productService.GetProductByIdAsync(entityId);\n\n                    if (product is null || product.Deleted)\n                        throw new NopException(\"Product not found\");\n\n                    model.ProductName = product.Name;\n                    model.ProductId = product.Id;\n                    break;\n                }\n                case MenuItemType.TopicPage:\n                {\n                    var topic = await _topicService.GetTopicByIdAsync(entityId) ?? throw new NopException(\"Topic not found\");\n                    model.TopicId = topic.Id;\n                    break;\n                }\n                case MenuItemType.Category:\n                {\n                    var category = await _categoryService.GetCategoryByIdAsync(entityId);\n\n                    if (category is null || category.Deleted)\n                        throw new NopException(\"Category not found\");\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Factories/MenuModelFactory.cs#L118-L154","documentation":"Thrown by MenuModelFactory when building a menu-item model for MenuItemType.Product and the referenced product is null or marked Deleted. Unlike the controller ArgumentExceptions, this is a NopException thrown from a factory (not a controller action), meaning it fires during model preparation rather than at the request boundary. The factory first guards entityId with ArgumentOutOfRangeException.ThrowIfZero, then for the Product case checks both null and the Deleted soft-delete flag before throwing.","triggerScenarios":"Configuring a custom menu item of type Product whose referenced ProductId was deleted (soft-deleted with Deleted=true) after the menu item was created. Also fires if the product id points to a record that never existed or was hard-purged. Triggered during menu rendering or menu-item model preparation, not during a direct CRUD operation.","commonSituations":"A merchant links a menu item to a product, then later deletes that product (soft delete); the next time the menu is rendered or edited, the factory throws. A product import/merge changed the product id, orphaning the menu item reference. A product was unpublished and then deleted by an admin unaware of the menu dependency.","solutions":["Edit the menu item in the admin menu management UI and point it to an existing, non-deleted product, or remove the menu item.","Restore or re-create the deleted product if it was removed in error, then the menu item resolves normally."],"exampleFix":"// before\nif (product is null || product.Deleted)\n    throw new NopException(\"Product not found\");\n\n// after\nif (product is null || product.Deleted)\n    return ErrorJson(\"Referenced product no longer exists. Reassign or remove this menu item.\");","handlingStrategy":"try-catch","validationCode":"// Before preparing the menu-item model, verify the product exists and is not deleted\nif ((MenuItemType)model.MenuItemTypeId == MenuItemType.Product)\n{\n    var product = await _productService.GetProductByIdAsync(entityId);\n    if (product is null || product.Deleted)\n        return ErrorJson(\"Referenced product no longer exists.\");\n}","typeGuard":"// C# extension/guard for soft-delete-safe product check\nstatic bool ProductIsUsable(Product product)\n    => product is not null && !product.Deleted;","tryCatchPattern":"try { await menuModelFactory.PrepareMenuItemModelAsync(model, entityId); }\ncatch (NopException ex) when (ex.Message == \"Product not found\")\n{ /* linked product was deleted — prompt user to reassign the menu item */ }","preventionTips":["When deleting a product, scan and unlink or reassign any menu items that reference it.","Before saving a Product-type menu item, validate the ProductId is non-zero and the product is not soft-deleted.","Use the menu management UI to audit orphaned references after bulk product deletions."],"tags":["nopcommerce","factory","not-found","menu","product","nop-exception","soft-delete"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}