Close

Free Sample

TSpearman
11 years ago
#3479 Quote
Avatar
  • 3
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
Boyko
11 years ago
#3481 Quote
Avatar
  • 1570
Hi Tom,

Could you let us know which version of the Ajax Filters and nopCommerce respectfully you are using?
Also what changes exactly you have made in the code - "we've tweaked the code around the page load to compensate for the £0 values (ignore them)".
This way we could advice if it will be possible to make the Ajax Filters work in the same way.

Thanks
Regards,
Nop-Templates.com Team
TSpearman
11 years ago
#3483 Quote
Avatar
  • 3
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;
        }
Boyko
11 years ago
#3497 Quote
Avatar
  • 1570
Hi TSPEARMAN,

Thank you for the code but I still don't see how the sorting of the products relates to the price calculation.
Could you please let us know exactly what is not working in the sorting?

Thanks
Regards,
Nop-Templates.com Team
TSpearman
11 years ago
#3499 Quote
Avatar
  • 3
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
YashChandra
11 years ago
#3519 Quote
Avatar
  • Moderator
  • 62
Hi TSpearman,

The sorting does not work in your case because the Nop Ajax Filters always look at the first ProductVariant.Price to sort the products by price. The filters cannot use the GetFinalPrice method because the query will take so much time to sort the products that it would make it really infeasible.
If you update to nopCommerce 3.0 and Nop Ajax Filters 3.0, the sorting will work.
If you update to nopCommerce 3.1, the sorting price would not work no matter if you are using the filters or not. This is due to a bug introduced with the transition to grouped products, which is due to be fixed in nopCommerce 3.2.
I hope this is useful!

Best Regards
Regards,
Milen Kovachev
Nop-Templates.com