mirror of
https://github.com/pretix/pretix.git
synced 2026-05-13 16:33:59 +00:00
cache potential discount information
relevant if shop has multiple categories with cross_selling_condition=discounts
This commit is contained in:
@@ -164,6 +164,7 @@ class ItemCategory(LoggedModel):
|
||||
match = set(match.pk for match in self.cross_selling_match_products.only('pk')) # TODO prefetch this
|
||||
return (self.items.all(), {}) if any(pos.item.pk in match for pos in cart) else (None, {})
|
||||
if self.cross_selling_condition == 'discounts':
|
||||
if not hasattr(self.event, '_potential_discounts_by_item_for_current_cart'):
|
||||
potential_discounts_by_cartpos = defaultdict(list)
|
||||
|
||||
from ..services.pricing import apply_discounts
|
||||
@@ -194,7 +195,7 @@ class ItemCategory(LoggedModel):
|
||||
next(discount_rule for (item, discount_rule, max_count, i) in infos_for_item)
|
||||
)
|
||||
|
||||
grouped_by_item = [
|
||||
self.event._potential_discounts_by_item_for_current_cart = [
|
||||
discount_info(item, infos_for_item) for item, infos_for_item in
|
||||
groupby(
|
||||
sorted(
|
||||
@@ -211,7 +212,7 @@ class ItemCategory(LoggedModel):
|
||||
my_item_pks = self.items.values_list('pk', flat=True)
|
||||
potential_discount_items = {
|
||||
item.pk: (max_count, discount_rule)
|
||||
for item, max_count, discount_rule in grouped_by_item
|
||||
for item, max_count, discount_rule in self.event._potential_discounts_by_item_for_current_cart
|
||||
if max_count > 0 and item.pk in my_item_pks and item.is_available()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user