Close

Profile: TSpearman

Avatar

User posts

Free Sample
11 years ago

Hi Boyko

If you go to the following url http://www.tileexperience.co.uk/en/wall-tiles and then sort by Price (either way) you'll notice that the prices aren't sorted properly on any page. This only happens when the filters are enabled and is fine when you disable them form the admin panel.

This seems to me that there is something in the Ajax Filters that is resorting the products after the GetProductVariantWithMinimalPrice function or that there is another function called before the filter is.

Tom

Free Sample
11 years ago

Hi Boyko

We're currently using version 2.81 of the Ajax Filters and 2.80 Nop Commerce.

The code that has change is the GetProductVariantWithMinimalPrice function within PriceCalculationService.cs. (It's not too clean but it works)

public virtual ProductVariant GetProductVariantWithMinimalPrice(IList<ProductVariant> variants,
            Customer customer, bool includeDiscounts, int quantity, out decimal? minPrice)
        {
            int intCount = 0;
            minPrice = null;
            if (variants == null)
                throw new ArgumentNullException("variants");

            if (variants.Count == 0)
                return null;

            ProductVariant minPriceVariant = null;
            foreach (var variant in variants)
            {
                var finalPrice = GetFinalPrice(variant, customer, decimal.Zero, includeDiscounts, quantity);
                // If finalPrice is 0 then use the previous entry as we don't want to show £0
                // If it's because someone has added a sample product
                // The flag intCount means we know somethings been set, if not then we can use
                // The £0 as it might actually be a free product
                if (!minPrice.HasValue || finalPrice < minPrice.Value)
                {
                    if (intCount == 0)
                    {
                        if (finalPrice > 0)
                        {
                            intCount++;
                            minPriceVariant = variant;
                            minPrice = finalPrice;
                        }
                        else
                        {
                            minPriceVariant = variant;
                            minPrice = finalPrice;
                        }
                    }
                }
            }
            return minPriceVariant;
            //previous implementation (compares only Price property but much faster)
            //var tmp1 = variants.ToList();
            //tmp1.Sort(new GenericComparer<ProductVariant>("Price", GenericComparer<ProductVariant>.SortOrder.Ascending));
            //return tmp1.Count > 0 ? tmp1[0] : null;
        }

Free Sample
11 years ago

Hi,

I have a quick query regarding the Ajax Filters. Our products on our webpage have tier pricing which sorts by Price absolutely fine with and without the Ajax Filters applied.

However, when we put free samples on each of these products (an additional value of £0) the sorting fails.This only happens when the Ajax Filters are applied as we've tweaked the code around the page load to compensate for the £0 values (ignore them). This has lead us to presume there is an additional sort that is done inside the DLL however we have tried multiple things and can not get around this.

Does anyone know if there a way to turn this functionality off? Or if there is a way to alter how the filter works?

Many thanks,

Tom