Home Page Categories - Show Prices Starting From..

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
For the homepagecategories module, I'd like it to show prices starting from as well.  Is there a more efficient way to do this apart from pass in the category ID and getALLProducts back in a collection and then sort to show the cheapest price??

Any advice appreciated?
13 лет назад
Anyone?
13 лет назад
Shame the community isn't as alive as the umbraco one :(  Thats what is making it thrive..

Anyway I am still trying to get this working and am doing it something like this - I have added a new property onto the Category class



        /// <summary>
        /// Gets the Cheapest Price of a product in the Category
        /// </summary>
        public Decimal PricesFrom
        {
            get
            {
                Decimal PriceFrom = 0;
                int TheOut = 0;
                List<Decimal> AllPrices = new List<Decimal>();
                var featuredProducts = ProductManager.GetAllProducts(this.CategoryId, 0, 0, null, int.MaxValue - 1, 0, out TheOut);
                if(featuredProducts.Count > 0)
                {
                    foreach (var item in featuredProducts)
                    {
                        var productVariantCollection = item.ProductVariants;
                        var productVariant = productVariantCollection[0];
                        AllPrices.Add(productVariant.Price);
                    }
                    AllPrices.Sort();
                    PriceFrom = Convert.ToDecimal(AllPrices.Take(1).ToString());
                }
                return PriceFrom;
            }
        }



I haven't tried this yet, but would be interested in hearing anyone who has done this?
13 лет назад
I got this working, albeit not ideal as its rather DB heavy and only takes into consideration the first variant on each product - But it does what it needs to do:

This is what I ended up with in case anyone else wants the same:


        /// <summary>
        /// Gets the Cheapest Price of a product in the Category
        /// </summary>
        public Decimal PricesFrom
        {
            get
            {
                Decimal PriceFrom = 0;
                int TheOut = 0;
                List<Decimal> AllPrices = new List<Decimal>();
                var featuredProducts = ProductManager.GetAllProducts(this.CategoryId, 0, 0, null, int.MaxValue - 1, 0, out TheOut);
                if (featuredProducts.Count > 0)
                {
                    foreach (var item in featuredProducts)
                    {
                        var productVariantCollection = item.ProductVariants;
                        var productVariant = productVariantCollection[0];
                        AllPrices.Add(productVariant.Price);
                    }
                    AllPrices.Sort();
                    PriceFrom = Convert.ToDecimal(AllPrices[0].ToString());
                }
                return PriceFrom;
            }
        }
13 лет назад
Where did you add this to make it work?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.