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
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:
@@ -8,6 +8,7 @@ from django.shortcuts import redirect, render
|
||||
|
||||
from favorites.services import get_user_favorite_item_ids
|
||||
from items.models import Category, Color, Item, Subcategory
|
||||
from orders.models import CartItem
|
||||
from orders.services import get_user_cart_item_ids
|
||||
|
||||
|
||||
@@ -90,7 +91,7 @@ def _resolve_catalog_scope(scope_value: str | None) -> tuple[str | None, str | N
|
||||
|
||||
|
||||
def _format_price_value(value: Decimal) -> str:
|
||||
return format(value, "f")
|
||||
return str(int(value))
|
||||
|
||||
|
||||
def index(request: HttpRequest, category: str | None = None) -> HttpResponse:
|
||||
@@ -322,11 +323,20 @@ def detail(request: HttpRequest, category: str, slug: str) -> HttpResponse:
|
||||
|
||||
images = list(item.images.all())
|
||||
|
||||
cart_color_id = None
|
||||
if request.user.is_authenticated:
|
||||
cart_item = CartItem.objects.filter(
|
||||
cart__user=request.user, item=item
|
||||
).select_related('selected_color').first()
|
||||
if cart_item and cart_item.selected_color_id:
|
||||
cart_color_id = cart_item.selected_color_id
|
||||
|
||||
return render(request, 'catalog/detail.html', {
|
||||
'categories': Category.objects.order_by('name'),
|
||||
'item': item,
|
||||
'images': images,
|
||||
'primary_image': images[0] if images else None,
|
||||
'cart_item_ids': get_user_cart_item_ids(request.user),
|
||||
'cart_color_id': cart_color_id,
|
||||
'favorite_item_ids': get_user_favorite_item_ids(request.user),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user