Skip to content

website_sale sorting of products

Michael Karrer edited this page Sep 30, 2015 · 7 revisions
    # See webite_sale models product.py line 148 to 178 def set_sequence_top ...
    # @http.route()
    # def shop(self, page=0, category=None, search='', **post):
    #     res = super(website_sale_categories, self).shop(page, category, search, **post)
    #     res.qcontext['products'].sorted(key=lambda r: r.website_sequence)
    #     return res

Simple solution

add a sequence field to the products and make them dragable in the backend

Complex solution

Find the current visible neighbour and exchange places

CAT A

B(1), C(2), A(3), D(4), E(5)

CAT B

B(1), C(2), D(4), E(5)

Example:

In CAT B we move Product D one Place Up - so in front of Product C:

RESULT: B(1), D(2), C(3), E(5)

FULL RESULT: B(1), D(2), C(3), A(4), E(5)

Steps to complete:

  1. Find visible neighbor of Product D = Produkt C(2)
  2. Find all products with a higher or equal sequence number to C except D = C(2), A(3), E(5)
  3. Resort all found products beginning with sequence number of C + 1 = 3 = C(3), A(4), E(5) (so we found the highest start number 3 and then we add +1 for every other product found in point 2)
  4. Set D to the initial sequence number of C = D(2)

Clone this wiki locally