calculate unit price when having tier prices and product variant attributes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Now the attributes total price is added to the price before the tier prices and it should be after that.

Now:
        public static decimal GetUnitPrice(ShoppingCartItem shoppingCartItem, Customer customer,
            bool includeDiscounts)
        {
            decimal finalPrice = decimal.Zero;
            var productVariant = shoppingCartItem.ProductVariant;
            if (productVariant != null)
            {
                decimal attributesTotalPrice = decimal.Zero;

                var pvaValues = ProductAttributeHelper.ParseProductVariantAttributeValues(shoppingCartItem.AttributesXml);
                foreach (var pvaValue in pvaValues)
                {
                    attributesTotalPrice += pvaValue.PriceAdjustment;
                }

                if (productVariant.CustomerEntersPrice)
                {
                    finalPrice = shoppingCartItem.CustomerEnteredPrice;
                }
                else
                {
                    finalPrice = GetFinalPrice(productVariant, customer, attributesTotalPrice, includeDiscounts);

                    if (productVariant.TierPrices.Count > 0)
                    {
                        decimal tierPrice = GetTierPrice(productVariant, shoppingCartItem.Quantity);
                        finalPrice = Math.Min(finalPrice, tierPrice);
                    }
                }
            }

            finalPrice = Math.Round(finalPrice, 2);

            return finalPrice;
        }


Good:

        public static decimal GetUnitPrice(ShoppingCartItem shoppingCartItem, Customer customer,
            bool includeDiscounts)
        {
            decimal finalPrice = decimal.Zero;
            var productVariant = shoppingCartItem.ProductVariant;
            if (productVariant != null)
            {
                decimal attributesTotalPrice = decimal.Zero;

                var pvaValues = ProductAttributeHelper.ParseProductVariantAttributeValues(shoppingCartItem.AttributesXml);
                foreach (var pvaValue in pvaValues)
                {
                    attributesTotalPrice += pvaValue.PriceAdjustment;
                }

                if (productVariant.CustomerEntersPrice)
                {
                    finalPrice = shoppingCartItem.CustomerEnteredPrice;
                }
                else
                {
                    finalPrice = GetFinalPrice(productVariant, customer, 0, includeDiscounts);

                    if (productVariant.TierPrices.Count > 0)
                    {
                        decimal tierPrice = GetTierPrice(productVariant, shoppingCartItem.Quantity);
                        finalPrice = Math.Min(finalPrice, tierPrice);
                    }
                    finalPrice += attributesTotalPrice;
                }
            }

            finalPrice = Math.Round(finalPrice, 2);

            return finalPrice;
        }
13 years ago
Thanks. It'll be fixed in the next release
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.