// Prepares a shipping option select list together with calculated shipping prices
        private SelectList CreateShippingOptionList(ShoppingCartInfo cart)
        {
            // Gets the shipping options configured and enabled for the current site
            IEnumerable <ShippingOptionInfo> shippingOptions = ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true);

            // Creates a collection of SelectListItems
            IEnumerable <SelectListItem> selectList = shippingOptions.Select(shippingOption =>
            {
                // Calculates the shipping price for a given shipping option based on the contents of the current
                // shopping cart and currently running store promotions (e.g., free shipping offers)
                decimal shippingPrice = shoppingService.CalculateShippingOptionPrice(shippingOption);

                // Gets the currency information from the shopping cart
                CurrencyInfo currency = cart.Currency;

                // Creates a select list item with shipping option name and a calculate shipping price
                return(new SelectListItem
                {
                    Value = shippingOption.ShippingOptionID.ToString(),
                    Text = $"{shippingOption.ShippingOptionDisplayName} ({String.Format(currency.CurrencyFormatString, shippingPrice)})"
                });
            });

            // Returns a new SelectList instance
            return(new SelectList(selectList, "Value", "Text"));
        }
Exemplo n.º 2
0
        private SelectList CreateShippingOptionList()
        {
            var shippingOptions = mShippingOptionRepository.GetAllEnabled();
            var cart            = mShoppingService.GetCurrentShoppingCart();

            var selectList = shippingOptions.Select(s =>
            {
                var shippingPrice = mShoppingService.CalculateShippingOptionPrice(s);
                var currency      = cart.Currency;

                return(new SelectListItem
                {
                    Value = s.ShippingOptionID.ToString(),
                    Text = $"{s.ShippingOptionDisplayName} ({String.Format(currency.CurrencyFormatString, shippingPrice)})"
                });
            });

            return(new SelectList(selectList, "Value", "Text"));
        }