nopSolutions/nopCommerce · warning · Exception

Your cart is empty

Error message

Your cart is empty

What it means

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.

Solutions

  1. Refresh the checkout page so the cart is reloaded; if empty, add products again before editing the address.
  2. Ensure the customer is browsing the correct store and cart cookie is intact.
  3. Return a localized 'cart empty' message and redirect to the cart page instead of a generic JSON error.
  4. Check that cart-merging on login is enabled if the issue appears after login.

Example fix

// before
if (!cart.Any())
    throw new Exception("Your cart is empty");
// after (localized, with redirect hint)
if (!cart.Any())
    throw new Exception(await _localizationService.GetResourceAsync("ShoppingCart.CartIsEmpty"));
Defensive patterns

Strategy: validation

Validate before calling

// Check cart presence before allowing the address edit POST.
var cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);
if (!cart.Any())
    return Json(new { error = 1, message = "Your cart is empty", redirect = Url.RouteUrl(NopRouteNames.General.CART) });

Try / catch

// Already wrapped by EditAddressAsync's catch; returns JSON error.
catch (Exception exc) { return Json(new { error = 1, message = exc.Message }); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at src/Presentation/Nop.Web/Controllers/CheckoutController.cs:284

    }

    protected virtual async Task<JsonResult> EditAddressAsync(AddressModel addressModel, IFormCollection form, Func<Customer, IList<ShoppingCartItem>, Address, Task<JsonResult>> getResult)
    {
        try
        {
            if (!ModelState.IsValid)
            {
                var errors = string.Join(", ", ModelState.Values.Where(p => p.Errors.Any()).SelectMany(p => p.Errors)
                    .Select(p => p.ErrorMessage));

                throw new Exception(errors);
            }

            var customer = await _workContext.GetCurrentCustomerAsync();
            var store = await _storeContext.GetCurrentStoreAsync();
            var cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);
            if (!cart.Any())
                throw new Exception("Your cart is empty");

            //find address (ensure that it belongs to the current customer)
            var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)
                          ?? throw new Exception("Address can't be loaded");

            //custom address attributes
            var customAttributes = await _addressAttributeParser.ParseCustomAttributesAsync(form, NopCommonDefaults.AddressAttributeControlName);
            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);

            if (customAttributeWarnings.Any())
                return Json(new { error = 1, message = customAttributeWarnings });

            address = addressModel.ToEntity(address);
            address.CustomAttributes = customAttributes;

            await _addressService.UpdateAddressAsync(address);

            return await getResult(customer, cart, address);

View on GitHub (pinned to 64bdf2ff08)