feat: refine price formatting and enable dynamic color updates in cart
All checks were successful
Build and Push Docker Image / build (push) Successful in 25s

- Updated price slider and backend formatting to round values instead of showing decimals
- Enhanced product detail page with active color selection display and automatic cart updates
- Adjusted swatch behavior to dynamically update the selected color in the cart via AJAX
- Improved consistency in slider steps and price formatting throughout templates and views
This commit is contained in:
2026-05-26 12:18:53 +02:00
parent bc14f3d429
commit d4fa91ac7f
4 changed files with 37 additions and 9 deletions

View File

@@ -61,13 +61,14 @@
<div class="product-summary__swatches" aria-label="Цвета товара">
{% for color in colors %}
<span
class="product-summary__swatch"
class="product-summary__swatch{% if color.id == cart_color_id %} product-summary__swatch--active{% endif %}"
style="background: {{ color.hex_code }};"
title="{{ color.name }}"
data-color-id="{{ color.id }}"
></span>
{% endfor %}
</div>
<p class="product-summary__color-name" data-color-name>{% for color in colors %}{% if color.id == cart_color_id %}Цвет: {{ color.name }}{% endif %}{% endfor %}</p>
{% endif %}
{% endwith %}
@@ -77,6 +78,12 @@
<div class="product-summary__actions">
{% if item.id in cart_item_ids %}
<form method="post" action="{% url 'orders:add' %}" class="product-summary__cart-form" id="update-color-form" style="display:none;">
{% csrf_token %}
<input type="hidden" name="item_id" value="{{ item.id }}">
<input type="hidden" name="next" value="{{ request.get_full_path }}">
<input type="hidden" name="color_id" id="selected-color-id" value="">
</form>
<a class="product-summary__button product-summary__button--primary product-summary__button--link" href="{% url 'orders:cart' %}">
Перейти в корзину
</a>
@@ -115,18 +122,29 @@
(function () {
var swatches = document.querySelectorAll('.product-summary__swatch[data-color-id]');
var colorInput = document.getElementById('selected-color-id');
var colorNameEl = document.querySelector('[data-color-name]');
var updateForm = document.getElementById('update-color-form');
var cartBtn = document.querySelector('.product-summary__button--primary[type="submit"]');
if (!swatches.length || !colorInput) { return; }
if (cartBtn) { cartBtn.disabled = true; }
if (!updateForm && cartBtn) { cartBtn.disabled = true; }
swatches.forEach(function (swatch) {
swatch.addEventListener('click', function () {
swatches.forEach(function (s) { s.classList.remove('product-summary__swatch--active'); });
this.classList.add('product-summary__swatch--active');
colorInput.value = this.dataset.colorId || '';
if (cartBtn) { cartBtn.disabled = false; }
if (colorNameEl) {
colorNameEl.textContent = 'Цвет: ' + this.title;
}
if (updateForm) {
updateForm.submit();
} else if (cartBtn) {
cartBtn.disabled = false;
}
});
});
}());