Change sort order in cart to keep subevents together (#2730)

Co-authored-by: Richard Schreiber <wiffbi@gmail.com>
This commit is contained in:
Raphael Michel
2022-07-25 18:35:10 +02:00
committed by GitHub
parent b06e98ace4
commit c90cb1f19c

View File

@@ -173,13 +173,14 @@ class CartMixin:
# standalone positions are grouped by main product position id, addons below them also sorted by position id
i, addon_penalty, pos.positionid if isinstance(pos, OrderPosition) else pos.pk,
# all other places are only used for positions that can be grouped. We just put zeros.
) + (0, ) * 10
) + (0, ) * 12
# positions are sorted and grouped by various attributes
category_key = (pos.item.category.position, pos.item.category.id) if pos.item.category is not None else (0, 0)
item_key = pos.item.position, pos.item_id
variation_key = (pos.variation.position, pos.variation.id) if pos.variation is not None else (0, 0)
grp = category_key + item_key + variation_key + (pos.price, (pos.voucher_id or 0), (pos.subevent_id or 0), (pos.seat_id or 0))
subevent_key = (pos.subevent.date_from, str(pos.subevent.name), pos.subevent_id) if pos.subevent_id else (0, "", 0)
grp = subevent_key + category_key + item_key + variation_key + (pos.price, (pos.voucher_id or 0), (pos.seat_id or 0))
if pos.addon_to_id:
if for_sorting:
ii = pos.positionid if isinstance(pos, OrderPosition) else pos.pk
@@ -187,7 +188,7 @@ class CartMixin:
ii = 0
return (
i, addon_penalty, ii,
) + category_key + item_key + variation_key + (pos.price, (pos.voucher_id or 0), (pos.subevent_id or 0), (pos.seat_id or 0))
) + grp
return (
# These are grouped by attributes so we don't put any position ids
0, 0, 0,