public ActionResult ShippingMethod()
        {
            var customer        = HttpContext.GetCustomer();
            var storeId         = AppLogic.StoreID();
            var cart            = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, storeId);
            var shippingAddress = EffectiveShippingAddressProvider.GetEffectiveShippingAddress(customer);
            var checkoutContext = PersistedCheckoutContextProvider.LoadCheckoutContext(customer);

            var shippingMethodModels = CachedShippingMethodCollectionProvider
                                       .Get(customer, shippingAddress, cart.CartItems, storeId)
                                       .Select(shippingMethod => new ShippingMethodRenderModel(
                                                   id: shippingMethod.Id,
                                                   name: shippingMethod.GetNameForDisplay(),
                                                   rateDisplay: GetShippingMethodRateDisplay(shippingMethod, customer, cart),
                                                   imageFileName: shippingMethod.ImageFileName));

            var selectedShippingMethodModel = shippingMethodModels
                                              .Where(shippingMethod => shippingMethod.Id == checkoutContext.SelectedShippingMethodId)
                                              .FirstOrDefault();

            var model = new SelectShippingMethodViewModel
            {
                RenderModel = new SelectShippingMethodRenderModel(
                    shippingMethods: shippingMethodModels,
                    selectedShippingMethod: selectedShippingMethodModel,
                    showShippingIcons: AppConfigProvider.GetAppConfigValue <bool>("ShowShippingIcons"),
                    cartIsAllFreeShipping: !AppConfigProvider.GetAppConfigValue <bool>("FreeShippingAllowsRateSelection") && cart.IsAllFreeShippingComponents(),
                    numberOfMethodsToShow: AppConfigProvider.GetAppConfigValue <int>("NumberOfShippingMethodsToDisplay"),
                    hideShippingOptions: AppConfigProvider.GetAppConfigValue <bool>("shipping.hide.options")),
                SelectedShippingMethodId = checkoutContext.SelectedShippingMethodId,
            };

            return(PartialView(ViewNames.ShippingMethodPartial, model));
        }
        public CartContext Apply(PreCheckoutRuleContext context)
        {
            var shippingAddress = EffectiveShippingAddressProvider.GetEffectiveShippingAddress(context.Customer);

            var availableShippingMethods = CachedShippingMethodCollectionProvider
                                           .Get(context.Customer, shippingAddress, context.CartContext.Cart.CartItems, AppLogic.StoreID());

            // If there are no available shipping methods, the customer hasn't selected one, or the customer selected an invalid one, selectedShipping will be null.
            var selectedShippingMethod = availableShippingMethods
                                         .Where(shippingMethod => shippingMethod.Id == context.PersistedCheckoutContext.SelectedShippingMethodId)
                                         .FirstOrDefault();

            // No matter what shipping method was selected but the customer, if there is only one available shipping method, set the customers selection to it.
            if (availableShippingMethods.Count() == 1)
            {
                selectedShippingMethod = availableShippingMethods.First();
            }

            // Update all cart items to the updated selection. If the selection is null, then it clears the selection from the cart items and the customer has to select a new one.
            ShippingMethodCartItemApplicator.UpdateCartItemsShippingMethod(
                context.Customer,
                context.CartContext.Cart,
                selectedShippingMethod);

            return(new CartContext(
                       cartContext: context.CartContext,
                       cart: CachedShoppingCartProvider.Get(context.Customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }