{"record":{"id":"68b55877832aa865","repo":"nopSolutions/nopCommerce","slug":"selected-shipping-option-is-unavailable","errorCode":null,"errorMessage":"Selected shipping option is unavailable","messagePattern":"Selected shipping option is unavailable","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Payments.PayPalCommerce/Services/PayPalCommerceServiceManager.cs","lineNumber":675,"sourceCode":"        if (details.Placement == ButtonPlacement.PaymentMethod && !isApplePay)\n        {\n            shipping.Type = details.IsPickup\n                ? ShippingType.SHIPPING.ToString().ToUpper() //PICKUP_IN_STORE option doesn't work for some reason\n                : ShippingType.SHIPPING.ToString().ToUpper();\n\n            return shipping;\n        }\n\n        var (shippingOptions, pickupPoints) = await PrepareShippingOptionsAsync(details);\n        if (!shippingOptions?.Any() ?? true)\n            throw new NopException(\"No available shipping options\");\n\n        var selectedShippingOption = shippingOptions.FirstOrDefault();\n        if (!string.IsNullOrEmpty(selectedOptionId))\n        {\n            var existingOption = shippingOptions\n                .FirstOrDefault(option => string.Equals(option.Name, selectedOptionId, StringComparison.InvariantCultureIgnoreCase))\n                ?? throw new NopException(\"Selected shipping option is unavailable\");\n\n            selectedShippingOption = existingOption;\n        }\n\n        if (selectedShippingOption is null)\n            throw new NopException(\"Selected shipping option is unavailable\");\n\n        PickupPoint pickupPoint = null;\n        if (selectedShippingOption.IsPickupInStore)\n        {\n            pickupPoint = await pickupPoints.FirstOrDefaultAwaitAsync(async point =>\n                string.Equals(await GetShippingOptionNameAsync(new() { Name = point.Name, IsPickupInStore = true }), selectedShippingOption.Name) &&\n                string.Equals(point.ProviderSystemName, selectedShippingOption.ShippingRateComputationMethodSystemName));\n\n            details.IsPickup = true;\n            details.PickupPoint = pickupPoint;\n\n            //if the shipping option type is set to PICKUP, then the full name should start with S2S meaning ship to store (for example, S2S My Store)","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Payments.PayPalCommerce/Services/PayPalCommerceServiceManager.cs#L657-L693","documentation":"Thrown when a specific shipping option was selected by the customer (selectedOptionId is non-empty) but no available shipping option matches that name. This indicates the previously chosen option is no longer in the list of available options returned by the shipping providers.","triggerScenarios":"PrepareShippingAsync receives a non-empty selectedOptionId; shippingOptions from PrepareShippingOptionsAsync contains options, but none have a Name matching selectedOptionId (case-insensitive comparison).","commonSituations":"The selected shipping method was deactivated or its rate expired between selection and payment; shipping provider rates changed between page loads; session-stored selection references a stale option name; shipping rate computation method returned different options due to configuration changes.","solutions":["Clear the stored shipping selection and prompt the customer to re-select a shipping option","Verify shipping rate computation methods are consistently returning the same option names across requests","Check for time-sensitive or rate-limited shipping options that may expire during checkout","Ensure no concurrent configuration changes to shipping methods during active checkout sessions"],"exampleFix":"// before\nvar existingOption = shippingOptions\n    .FirstOrDefault(option => string.Equals(option.Name, selectedOptionId, StringComparison.InvariantCultureIgnoreCase))\n    ?? throw new NopException(\"Selected shipping option is unavailable\");\n\n// after\nvar existingOption = shippingOptions\n    .FirstOrDefault(option => string.Equals(option.Name, selectedOptionId, StringComparison.InvariantCultureIgnoreCase));\nif (existingOption is null)\n{\n    //fall back to the first available option instead of failing\n    existingOption = shippingOptions.FirstOrDefault();\n    await _logger.WarningAsync($\"Selected shipping option '{selectedOptionId}' no longer available, falling back\");\n}","handlingStrategy":"validation","validationCode":"// Validate selected shipping option is still available\nif (!string.IsNullOrEmpty(selectedOptionId))\n{\n    var options = await _shippingService.GetShippingOptionsAsync(cart, address, \"\", storeId);\n    var exists = options.ShippingOptions.Any(o =>\n        string.Equals(o.Name, selectedOptionId, StringComparison.InvariantCultureIgnoreCase));\n    if (!exists)\n        selectedOptionId = null; // reset to force re-selection\n}","typeGuard":null,"tryCatchPattern":"var (result, error) = await manager.PrepareShippingAsync(settings, details, selectedOptionId, isApplePay);\nif (!string.IsNullOrEmpty(error) && error == \"Selected shipping option is unavailable\")\n{\n    //reset selection and retry with first available option\n    var (retryResult, retryError) = await manager.PrepareShippingAsync(settings, details, null, isApplePay);\n}","preventionTips":["Clear stale shipping selections when options change","Validate the selected option name against current options on each request","Handle session timeouts gracefully by re-prompting for shipping selection"],"tags":["shipping","shipping-options","stale-selection","paypal-commerce","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}