Beispiel #1
0
        // 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 = shippingOption.GetBySite(siteService.CurrentSite.SiteID, 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"));
        }
 /// <summary>
 /// Returns an enumerable collection of all enabled shipping options.
 /// </summary>
 /// <returns>Collection of enabled shipping options. See <see cref="ShippingOptionInfo"/> for detailed information.</returns>
 public IEnumerable <ShippingOptionInfo> GetAllEnabled()
 {
     return(RepositoryCacheHelper.CacheObjects(() =>
     {
         return shippingOptionInfoProvider.GetBySite(SiteContext.CurrentSiteID, true);
     }, $"{nameof(KenticoShippingOptionRepository)}|{nameof(GetAllEnabled)}"));
 }