mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
filter non-buyable items from list
This commit is contained in:
@@ -161,7 +161,6 @@ class ItemCategory(LoggedModel):
|
|||||||
if self.cross_selling_condition == 'always':
|
if self.cross_selling_condition == 'always':
|
||||||
return self.items.all(), {}
|
return self.items.all(), {}
|
||||||
if self.cross_selling_condition == 'products':
|
if self.cross_selling_condition == 'products':
|
||||||
# TODO set max_count for products with max_per_order
|
|
||||||
match = set(match.pk for match in self.cross_selling_match_products.only('pk')) # TODO prefetch this
|
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, {})
|
return (self.items.all(), {}) if any(pos.item.pk in match for pos in cart) else (None, {})
|
||||||
if self.cross_selling_condition == 'discounts':
|
if self.cross_selling_condition == 'discounts':
|
||||||
|
|||||||
@@ -686,18 +686,15 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
|
|||||||
if self.request.customer else None
|
if self.request.customer else None
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
new_items = list()
|
||||||
for item in items:
|
for item in items:
|
||||||
|
max_count = inf
|
||||||
if item.pk in discount_info:
|
if item.pk in discount_info:
|
||||||
(max_count, discount_rule) = discount_info[item.pk]
|
(max_count, discount_rule) = discount_info[item.pk]
|
||||||
|
|
||||||
# set item.order_max for benefit_only_apply_to_cheapest_n_matches discounted items
|
# only benefit_only_apply_to_cheapest_n_matches discounted items have a max_count, all others get 'inf'
|
||||||
if not max_count:
|
if not max_count:
|
||||||
max_count = inf
|
max_count = inf
|
||||||
item.order_max = min(
|
|
||||||
item.order_max - sum(1 for pos in self.positions if pos.item_id == item.pk),
|
|
||||||
max_count
|
|
||||||
)
|
|
||||||
|
|
||||||
# calculate discounted price
|
# calculate discounted price
|
||||||
if discount_rule:
|
if discount_rule:
|
||||||
@@ -708,7 +705,15 @@ class AddOnsStep(CartMixin, AsyncAction, TemplateFlowStep):
|
|||||||
)
|
)
|
||||||
item.display_price = new_price
|
item.display_price = new_price
|
||||||
|
|
||||||
return items
|
# reduce order_max by number of items already in cart (prevent recommending a product the user can't add anyway)
|
||||||
|
item.order_max = min(
|
||||||
|
item.order_max - sum(1 for pos in self.positions if pos.item_id == item.pk),
|
||||||
|
max_count
|
||||||
|
)
|
||||||
|
if item.order_max > 0:
|
||||||
|
new_items.append(item)
|
||||||
|
|
||||||
|
return new_items
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user