{"record":{"id":"ed2f2b45109ac1c0","repo":"nopSolutions/nopCommerce","slug":"your-cart-is-empty","errorCode":null,"errorMessage":"Your cart is empty","messagePattern":"Your cart is empty","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Controllers/CheckoutController.cs","lineNumber":284,"sourceCode":"    }\r\n\r\n    protected virtual async Task<JsonResult> EditAddressAsync(AddressModel addressModel, IFormCollection form, Func<Customer, IList<ShoppingCartItem>, Address, Task<JsonResult>> getResult)\r\n    {\r\n        try\r\n        {\r\n            if (!ModelState.IsValid)\r\n            {\r\n                var errors = string.Join(\", \", ModelState.Values.Where(p => p.Errors.Any()).SelectMany(p => p.Errors)\r\n                    .Select(p => p.ErrorMessage));\r\n\r\n                throw new Exception(errors);\r\n            }\r\n\r\n            var customer = await _workContext.GetCurrentCustomerAsync();\r\n            var store = await _storeContext.GetCurrentStoreAsync();\r\n            var cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);\r\n            if (!cart.Any())\r\n                throw new Exception(\"Your cart is empty\");\r\n\r\n            //find address (ensure that it belongs to the current customer)\r\n            var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)\r\n                          ?? throw new Exception(\"Address can't be loaded\");\r\n\r\n            //custom address attributes\r\n            var customAttributes = await _addressAttributeParser.ParseCustomAttributesAsync(form, NopCommonDefaults.AddressAttributeControlName);\r\n            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);\r\n\r\n            if (customAttributeWarnings.Any())\r\n                return Json(new { error = 1, message = customAttributeWarnings });\r\n\r\n            address = addressModel.ToEntity(address);\r\n            address.CustomAttributes = customAttributes;\r\n\r\n            await _addressService.UpdateAddressAsync(address);\r\n\r\n            return await getResult(customer, cart, address);\r","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Controllers/CheckoutController.cs#L266-L302","documentation":"Thrown in EditAddressAsync (billing/shipping address edit) when the customer's shopping cart for the current store has no items. The factory loads cart via GetShoppingCartAsync(ShoppingCart); if cart.Any() is false it throws Exception(\"Your cart is empty\"). The catch at line 304 logs a warning and returns JSON { error = 1 }. It prevents address editing when there is nothing to check out, e.g., after the cart expired or was emptied in another tab.","triggerScenarios":"Customer submits an address edit during checkout but their ShoppingCart-type cart for the current store is empty. Triggered by the cart being emptied/expired in another session, a store mismatch, or completing checkout in a second tab before editing the address here.","commonSituations":"Cart expired (session/cookie) or cleared in another tab; customer already placed the order elsewhere; multi-store cookie confusion; guest-to-registered conversion that reset the cart; AB-testing/return-visitor with a stale checkout page.","solutions":["Refresh the checkout page so the cart is reloaded; if empty, add products again before editing the address.","Ensure the customer is browsing the correct store and cart cookie is intact.","Return a localized 'cart empty' message and redirect to the cart page instead of a generic JSON error.","Check that cart-merging on login is enabled if the issue appears after login."],"exampleFix":"// before\nif (!cart.Any())\n    throw new Exception(\"Your cart is empty\");\n// after (localized, with redirect hint)\nif (!cart.Any())\n    throw new Exception(await _localizationService.GetResourceAsync(\"ShoppingCart.CartIsEmpty\"));","handlingStrategy":"validation","validationCode":"// Check cart presence before allowing the address edit POST.\nvar cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);\nif (!cart.Any())\n    return Json(new { error = 1, message = \"Your cart is empty\", redirect = Url.RouteUrl(NopRouteNames.General.CART) });","typeGuard":null,"tryCatchPattern":"// Already wrapped by EditAddressAsync's catch; returns JSON error.\ncatch (Exception exc) { return Json(new { error = 1, message = exc.Message }); }","preventionTips":["Disable address-edit controls when the cart is empty.","Ensure cart merging on login is enabled to avoid empty carts after login.","Watch for multi-tab checkout where one tab completes the order first."],"tags":["nopcommerce","checkout","cart","empty-cart","session"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}