コード例 #1
0
        /// <summary>
        /// Sets the variant prices by looping through all of the variants.
        /// </summary>
        /// <param name="productFamily">The product family.</param>
        /// <param name="extendedPrice">The extended price.</param>
        /// <param name="isLowestPriceVariantSpecified">if set to <c>true</c> the lowest priced variant adjusted price is returned.</param>
        /// <param name="isLowestPriceVariantListPriceSpecified">if set to <c>true</c> the lowest priced variant list price is returned.</param>
        /// <param name="isHighestPriceVariantSpecified">if set to <c>true</c> the highest priced variant adjusted price.</param>
        protected virtual void SetVariantPricesFromProductVariants(ProductFamily productFamily, ExtendedCommercePrice extendedPrice, bool isLowestPriceVariantSpecified, bool isLowestPriceVariantListPriceSpecified, bool isHighestPriceVariantSpecified)
        {
            if (productFamily.Variants != null && productFamily.Variants.Count > 0)
            {
                decimal highestPrice = 0.0M;
                decimal lowestPrice = 0.0M;
                decimal basePrice = 0.0M;
                bool processingFirstItem = true;

                foreach (Variant variant in productFamily.Variants)
                {
                    if (!variant.IsListPriceNull())
                    {
                        if (processingFirstItem || variant.ListPrice < lowestPrice)
                        {
                            lowestPrice = variant.ListPrice;
                            basePrice = variant.DataRow.Table.Columns.Contains("BasePriceVariant") && variant.DataRow["BasePriceVariant"] != DBNull.Value ? Convert.ToDecimal(variant.DataRow["BasePriceVariant"], CultureInfo.InvariantCulture) : 0.0M;
                        }

                        if (processingFirstItem || variant.ListPrice > highestPrice)
                        {
                            highestPrice = variant.ListPrice;
                        }

                        processingFirstItem = false;
                    }
                }

                if (isLowestPriceVariantSpecified)
                {
                    extendedPrice.LowestPricedVariant = lowestPrice;
                }

                if (isLowestPriceVariantListPriceSpecified)
                {
                    extendedPrice.LowestPricedVariantListPrice = basePrice;
                }

                if (isHighestPriceVariantSpecified)
                {
                    extendedPrice.HighestPricedVariant = highestPrice;
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets the variant prices.
 /// </summary>
 /// <param name="productFamily">The product family.</param>
 /// <param name="extendedPrice">The extended price.</param>
 /// <param name="isLowestPriceVariantSpecified">if set to <c>true</c> the lowest priced variant adjusted price is returned.</param>
 /// <param name="isLowestPriceVariantListPriceSpecified">if set to <c>true</c> the lowest priced variant list price is returned.</param>
 /// <param name="isHighestPriceVariantSpecified">if set to <c>true</c> the highest priced variant adjusted price.</param>
 protected virtual void SetVariantPrices(ProductFamily productFamily, ExtendedCommercePrice extendedPrice, bool isLowestPriceVariantSpecified, bool isLowestPriceVariantListPriceSpecified, bool isHighestPriceVariantSpecified)
 {
     if (this.UseProductBasePriceAsVariantPrice)
     {
         this.SetVariantPricesFromBaseProduct(productFamily, extendedPrice, isLowestPriceVariantSpecified, isLowestPriceVariantListPriceSpecified, isHighestPriceVariantSpecified);
     }
     else
     {
         this.SetVariantPricesFromProductVariants(productFamily, extendedPrice, isLowestPriceVariantSpecified, isLowestPriceVariantListPriceSpecified, isHighestPriceVariantSpecified);
     }
 }
コード例 #3
0
        /// <summary>
        /// Sets the variant prices from base product.
        /// </summary>
        /// <param name="productFamily">The product family.</param>
        /// <param name="extendedPrice">The extended price.</param>
        /// <param name="isLowestPriceVariantSpecified">if set to <c>true</c> the lowest priced variant adjusted price is returned.</param>
        /// <param name="isLowestPriceVariantListPriceSpecified">if set to <c>true</c> the lowest priced variant list price is returned.</param>
        /// <param name="isHighestPriceVariantSpecified">if set to <c>true</c> the highest priced variant adjusted price.</param>
        protected virtual void SetVariantPricesFromBaseProduct(ProductFamily productFamily, ExtendedCommercePrice extendedPrice, bool isLowestPriceVariantSpecified, bool isLowestPriceVariantListPriceSpecified, bool isHighestPriceVariantSpecified)
        {
            decimal lowestPricedVariantAdjustedPrice;
            decimal lowestPricedVariantListPrice;

            if (productFamily.HasProperty("BasePrice") && productFamily["BasePrice"] != null)
            {
                lowestPricedVariantAdjustedPrice = productFamily.ListPrice;
                lowestPricedVariantListPrice = (productFamily["BasePrice"] as decimal?).Value;
            }
            else
            {
                // No base price is defined, the List price is set to the actual ListPrice define in the catalog
                lowestPricedVariantAdjustedPrice = productFamily.ListPrice;
                lowestPricedVariantListPrice = productFamily.ListPrice;
            }

            if (isLowestPriceVariantSpecified)
            {
                extendedPrice.LowestPricedVariant = lowestPricedVariantAdjustedPrice;
            }

            if (isLowestPriceVariantListPriceSpecified)
            {
                extendedPrice.LowestPricedVariantListPrice = lowestPricedVariantListPrice;
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets the variant prices by looping through all of the variants returned by the index.
        /// </summary>
        /// <param name="productDocument">The product document.</param>
        /// <param name="variantInfoList">The variant information list.</param>
        /// <param name="extendedPrice">The extended price.</param>
        /// <param name="isLowestPriceVariantSpecified">if set to <c>true</c> the lowest priced variant adjusted price is returned.</param>
        /// <param name="isLowestPriceVariantListPriceSpecified">if set to <c>true</c> the lowest priced variant list price is returned.</param>
        /// <param name="isHighestPriceVariantSpecified">if set to <c>true</c> the highest priced variant adjusted price.</param>
        protected virtual void SetVariantPricesFromProductVariants(
            CommerceProductSearchResultItem productDocument, 
            List<VariantIndexInfo> variantInfoList, 
            ExtendedCommercePrice extendedPrice,
            bool isLowestPriceVariantSpecified, 
            bool isLowestPriceVariantListPriceSpecified, 
            bool isHighestPriceVariantSpecified)
        {
            if (variantInfoList != null && variantInfoList.Count > 0)
            {
                decimal highestPrice = 0.0M;
                decimal lowestPrice = 0.0M;
                decimal basePrice = 0.0M;
                bool processingFirstItem = true;

                foreach (var variantInfo in variantInfoList)
                {
                    if (processingFirstItem || variantInfo.ListPrice < lowestPrice)
                    {
                        lowestPrice = variantInfo.ListPrice;
                        basePrice = variantInfo.BasePrice;
                    }

                    if (processingFirstItem || variantInfo.ListPrice > highestPrice)
                    {
                        highestPrice = variantInfo.ListPrice;
                    }

                    processingFirstItem = false;
                }

                if (isLowestPriceVariantSpecified)
                {
                    extendedPrice.LowestPricedVariant = lowestPrice;
                }

                if (isLowestPriceVariantListPriceSpecified)
                {
                    extendedPrice.LowestPricedVariantListPrice = basePrice;
                }

                if (isHighestPriceVariantSpecified)
                {
                    extendedPrice.HighestPricedVariant = highestPrice;
                }
            }
        }