diefenbach / django-lfs

An online-shop based on Django
http://www.getlfs.com
BSD 3-Clause "New" or "Revised" License
622 stars 222 forks source link

Sort by `effective_price` instead of `price` #41

Closed baffolobill closed 10 years ago

baffolobill commented 12 years ago

Sorting by price doesn't take into account the for_sale_price field.

diefenbach commented 12 years ago

Thanks for reporting this. I will look into it asap.

pigletto commented 11 years ago

I think that best solution for this would be to add extra field to the Product model that will store 'current' price. It will be updated with pre_save signal on product depending on 'for sale' being enabled.

baffolobill commented 11 years ago

effective_price is used for this, look at catalog/models.py:

class Product(models.Model):
    ...
    def save(self, *args, **kwargs):
        """
        Overwritten to save effective_price.
        """
        if self.for_sale:
            self.effective_price = self.for_sale_price
        else:
            self.effective_price = self.price

        super(Product, self).save(*args, **kwargs)
    ...

Look at the commit https://github.com/diefenbach/django-lfs/commit/67bab79c3d6353a5fd6e064399a4f9e90f0841f7, for example - everywhere is used price as default value to sort.