Product list: Show number of items currently in cart (Z#23212546) (#5599)

* Product list: Show number of items currently in cart

* Apply suggestions from code review

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Add display property

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2025-11-11 08:05:40 +01:00
committed by GitHub
parent d1ae579a6f
commit e99eecb8be
3 changed files with 38 additions and 4 deletions

View File

@@ -3,6 +3,8 @@
{% load eventurl %}
{% load money %}
{% load thumb %}
{% load icon %}
{% load getitem %}
{% load eventsignal %}
{% load rich_text %}
{% for tup in items_by_category %}{% with category=tup.0 items=tup.1 form_prefix=tup.2 %}
@@ -43,7 +45,9 @@
</a>
{% endif %}
<div class="product-description {% if item.picture %}with-picture{% endif %}">
<h{{ headline_level|default:3|add:1 }} class="h4" id="{{ form_prefix }}item-{{ item.pk }}-legend">{{ item.name }}</h{{ headline_level|default:3|add:1 }}>
<h{{ headline_level|default:3|add:1 }} class="h4" id="{{ form_prefix }}item-{{ item.pk }}-legend">
{{ item.name }}
</h{{ headline_level|default:3|add:1 }}>
{% if item.description %}
<div id="{{ form_prefix }}item-{{ item.pk }}-description" class="product-description">
{{ item.description|localize|rich_text }}
@@ -119,7 +123,19 @@
data-price="{% if event.settings.display_net_prices %}{{ var.display_price.net|unlocalize }}{% else %}{{ var.display_price.gross|unlocalize }}{% endif %}"
{% endif %}>
<div class="col-md-8 col-sm-6 col-xs-12">
<h{{ headline_level|default:3|add:2 }} class="h5" id="{{ form_prefix }}item-{{ item.pk }}-{{ var.pk }}-legend">{{ var }}</h{{ headline_level|default:3|add:2 }}>
<h{{ headline_level|default:3|add:2 }} class="h5" id="{{ form_prefix }}item-{{ item.pk }}-{{ var.pk }}-legend">
{{ var }}
{% if cart.itemvarsums|getitem:var %}
<span class="textbubble-success">
{% icon "shopping-cart" %}
{% blocktrans trimmed count amount=cart.itemvarsums|getitem:var %}
{{ amount }}× in your cart
{% plural %}
{{ amount }}× in your cart
{% endblocktrans %}
</span>
{% endif %}
</h{{ headline_level|default:3|add:2 }}>
{% if var.description %}
<div id="{{ form_prefix }}item-{{ item.pk }}-{{ var.pk }}-description" class="variation-description">
{{ var.description|localize|rich_text }}
@@ -264,7 +280,19 @@
</a>
{% endif %}
<div class="product-description {% if item.picture %}with-picture{% endif %}">
<h{{ headline_level|default:3|add:1 }} class="h4" id="{{ form_prefix }}item-{{ item.pk }}-legend">{{ item.name }}</h{{ headline_level|default:3|add:1 }}>
<h{{ headline_level|default:3|add:1 }} class="h4" id="{{ form_prefix }}item-{{ item.pk }}-legend">
{{ item.name }}
{% if cart.itemvarsums|getitem:item %}
<span class="textbubble-success">
{% icon "shopping-cart" %}
{% blocktrans trimmed count amount=cart.itemvarsums|getitem:item %}
{{ amount }}× in your cart
{% plural %}
{{ amount }}× in your cart
{% endblocktrans %}
</span>
{% endif %}
</h{{ headline_level|default:3|add:1 }}>
{% if item.description %}
<div id="{{ form_prefix }}item-{{ item.pk }}-description" class="product-description">
{{ item.description|localize|rich_text }}

View File

@@ -33,7 +33,7 @@
# License for the specific language governing permissions and limitations under the License.
import copy
import warnings
from collections import defaultdict
from collections import Counter, defaultdict
from datetime import datetime, timedelta
from decimal import Decimal
from functools import wraps
@@ -242,6 +242,10 @@ class CartMixin:
minutes_left = None
seconds_left = None
itemvarsums = Counter()
for p in cartpos:
itemvarsums[p.variation or p.item] += 1
return {
'positions': positions,
'invoice_address': self.invoice_address,
@@ -258,6 +262,7 @@ class CartMixin:
'max_expiry_extend': max_expiry_extend,
'is_ordered': bool(order),
'itemcount': sum(c.count for c in positions if not c.addon_to),
'itemvarsums': itemvarsums,
'current_selected_payments': [
p for p in self.current_selected_payments(positions, fees, self.invoice_address)
if p.get('multi_use_supported')

View File

@@ -574,6 +574,7 @@ h2 .label {
.textbubble-success, .textbubble-success-warning, .textbubble-info, .textbubble-warning, .textbubble-danger {
display: inline-block;
padding: 0 .4em;
border-radius: $border-radius-base;
font-weight: bold;