Пример #1
0
        /// <summary>
        /// Formats the price
        /// </summary>
        /// <param name="price">Price</param>
        /// <param name="showCurrency">A value indicating whether to show a currency</param>
        /// <param name="targetCurrency">Target currency</param>
        /// <param name="language">Language</param>
        /// <param name="priceIncludesTax">A value indicating whether price includes tax</param>
        /// <param name="showTax">A value indicating whether to show tax suffix</param>
        /// <returns>Price</returns>
        public virtual string FormatPrice(decimal price, bool showCurrency,
                                          Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax)
        {
            //we should round it no matter of "ShoppingCartSettings.RoundPricesDuringCalculation" setting
            price = RoundingHelper.RoundPrice(price);

            string currencyString = GetCurrencyString(price, showCurrency, targetCurrency);

            if (showTax)
            {
                //show tax suffix
                string formatStr;
                if (priceIncludesTax)
                {
                    formatStr = _localizationService.GetResource("Articles.InclTaxSuffix", language.Id, false);
                    if (String.IsNullOrEmpty(formatStr))
                    {
                        formatStr = "{0} incl tax";
                    }
                }
                else
                {
                    formatStr = _localizationService.GetResource("Articles.ExclTaxSuffix", language.Id, false);
                    if (String.IsNullOrEmpty(formatStr))
                    {
                        formatStr = "{0} excl tax";
                    }
                }
                return(string.Format(formatStr, currencyString));
            }

            return(currencyString);
        }
Пример #2
0
        /// <summary>
        /// Gets the shopping cart unit price (one item)
        /// </summary>
        /// <param name="article">Article</param>
        /// <param name="customer">Customer</param>
        /// <param name="shoppingCartType">Shopping cart type</param>
        /// <param name="quantity">Quantity</param>
        /// <param name="attributesXml">Article atrributes (XML format)</param>
        /// <param name="customerEnteredPrice">Customer entered price (if specified)</param>
        /// <param name="rentalStartDate">Rental start date (null for not rental articles)</param>
        /// <param name="rentalEndDate">Rental end date (null for not rental articles)</param>
        /// <param name="includeDiscounts">A value indicating whether include discounts or not for price computation</param>
        /// <param name="discountAmount">Applied discount amount</param>
        /// <param name="appliedDiscounts">Applied discounts</param>
        /// <returns>Shopping cart unit price (one item)</returns>
        public virtual decimal GetUnitPrice(Article article,
                                            Customer customer,
                                            ShoppingCartType shoppingCartType,
                                            int quantity,
                                            string attributesXml,
                                            decimal customerEnteredPrice,
                                            DateTime?rentalStartDate, DateTime?rentalEndDate,
                                            bool includeDiscounts,
                                            out decimal discountAmount
                                            )
        {
            if (article == null)
            {
                throw new ArgumentNullException("article");
            }

            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            discountAmount = decimal.Zero;


            decimal finalPrice;

            var combination = _articleAttributeParser.FindArticleAttributeCombination(article, attributesXml);

            if (combination != null && combination.OverriddenPrice.HasValue)
            {
                finalPrice = GetFinalPrice(article,
                                           customer,
                                           combination.OverriddenPrice.Value,
                                           decimal.Zero,
                                           includeDiscounts,
                                           quantity,
                                           article.IsRental ? rentalStartDate : null,
                                           article.IsRental ? rentalEndDate : null,
                                           out discountAmount);
            }
            else
            {
                //summarize price of all attributes
                decimal attributesTotalPrice = decimal.Zero;
                var     attributeValues      = _articleAttributeParser.ParseArticleAttributeValues(attributesXml);
                if (attributeValues != null)
                {
                    foreach (var attributeValue in attributeValues)
                    {
                        attributesTotalPrice += GetArticleAttributeValuePriceAdjustment(attributeValue);
                    }
                }

                //get price of a article (with previously calculated price of all attributes)

                int qty;

                qty = quantity;

                finalPrice = GetFinalPrice(article,
                                           customer,
                                           attributesTotalPrice,
                                           includeDiscounts,
                                           qty,
                                           article.IsRental ? rentalStartDate : null,
                                           article.IsRental ? rentalEndDate : null,
                                           out discountAmount);
            }

            //rounding
            if (_shoppingCartSettings.RoundPricesDuringCalculation)
            {
                finalPrice = RoundingHelper.RoundPrice(finalPrice);
            }

            return(finalPrice);
        }