{"record":{"id":"e3a6d94d46876df1","repo":"nopSolutions/nopCommerce","slug":"you-cannot-specify-purchased-with-product-value","errorCode":null,"errorMessage":"You cannot specify \"Purchased with product\" value for \"Registered\" customer role","messagePattern":"You cannot specify \"Purchased with product\" value for \"Registered\" customer role","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs","lineNumber":155,"sourceCode":"    {\n        //try to get a customer role with the specified id\n        var customerRole = await _customerService.GetCustomerRoleByIdAsync(model.Id);\n        if (customerRole == null)\n            return RedirectToAction(\"List\");\n\n        try\n        {\n            if (ModelState.IsValid)\n            {\n                if (customerRole.IsSystemRole && !model.Active)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem\"));\n\n                if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase))\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem\"));\n\n                if (NopCustomerDefaults.RegisteredRoleName.Equals(customerRole.SystemName, StringComparison.InvariantCultureIgnoreCase) &&\n                    model.PurchasedWithProductId > 0)\n                    throw new NopException(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Fields.PurchasedWithProduct.Registered\"));\n\n                customerRole = model.ToEntity(customerRole);\n                await _customerService.UpdateCustomerRoleAsync(customerRole);\n\n                //activity log\n                await _customerActivityService.InsertActivityAsync(\"EditCustomerRole\",\n                    string.Format(await _localizationService.GetResourceAsync(\"ActivityLog.EditCustomerRole\"), customerRole.Name), customerRole);\n\n                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync(\"Admin.Customers.CustomerRoles.Updated\"));\n\n                return continueEditing ? RedirectToAction(\"Edit\", new { id = customerRole.Id }) : RedirectToAction(\"List\");\n            }\n\n            //prepare model\n            model = await _customerRoleModelFactory.PrepareCustomerRoleModelAsync(model, customerRole, true);\n\n            //if we got this far, something failed, redisplay form\n            return View(model);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/CustomerRoleController.cs#L137-L173","documentation":"Thrown in the CustomerRole Edit action when the role's SystemName equals NopCustomerDefaults.RegisteredRoleName (the built-in 'Registered' role) and the model.PurchasedWithProductId is greater than zero. The Registered role is assigned automatically upon customer registration; binding it to a product purchase would conflict with that auto-assignment logic. NopException, caught and shown as an error notification.","triggerScenarios":"POST to CustomerRole/Edit for the Registered system role with a PurchasedWithProductId > 0 (a product selected in the 'Purchased with product' picker).","commonSituations":"An admin tries to set up a 'buy X to become a member' flow and mistakenly targets the default Registered role instead of a custom role; a configuration tool applies purchased-with-product settings to all roles indiscriminately.","solutions":["Create a dedicated non-system customer role (e.g. 'Premium Member') and set PurchasedWithProduct on that role instead.","Clear the PurchasedWithProductId field (set to 0/none) when editing the Registered role.","Audit any role-seeding scripts to only assign PurchasedWithProduct to non-Registered roles."],"exampleFix":"// before — Registered role submitted with PurchasedWithProductId > 0 -> NopException\n\n// after — assign the purchased-with-product linkage to a custom role\nvar premiumRole = await _customerService.GetCustomerRoleBySystemNameAsync(\"PremiumMember\");\npremiumRole.PurchasedWithProductId = productId;\nawait _customerService.UpdateCustomerRoleAsync(premiumRole);","handlingStrategy":"validation","validationCode":"// Before saving: the Registered role must not carry a purchased-with product\nvar role = await _customerService.GetCustomerRoleByIdAsync(model.Id);\nif (NopCustomerDefaults.RegisteredRoleName.Equals(role?.SystemName, StringComparison.OrdinalIgnoreCase) && model.PurchasedWithProductId > 0)\n{\n    ModelState.AddModelError(\"PurchasedWithProductId\", \"Cannot set PurchasedWithProduct on the Registered role.\");\n    return View(model);\n}","typeGuard":"bool CanSetPurchasedWithProduct(CustomerRole role) => !NopCustomerDefaults.RegisteredRoleName.Equals(role?.SystemName, StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"// The Edit action's try/catch shows the localized notification; use a custom non-system role instead.","preventionTips":["Create a dedicated non-system role for purchase-triggered memberships.","Disable/hide the PurchasedWithProduct picker when editing the Registered role.","Document that the Registered role is auto-assigned on signup."],"tags":["nopcommerce","admin","customer-roles","business-rule","registered-role","purchased-with-product"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}