|
|
|
@ -8,19 +8,28 @@ |
|
|
|
<form method="post" action="{% url 'shop:add_to_cart' product.id %}" class="add-to-cart-form"> |
|
|
|
<form method="post" action="{% url 'shop:add_to_cart' product.id %}" class="add-to-cart-form"> |
|
|
|
{% csrf_token %} |
|
|
|
{% csrf_token %} |
|
|
|
<div class="options-container"> |
|
|
|
<div class="options-container"> |
|
|
|
<div class="option-element product-title">{{ product.title }}</div> |
|
|
|
<div class="option-element product-title"> |
|
|
|
|
|
|
|
{{ product.title }} |
|
|
|
|
|
|
|
<div class="color-label"><span id="selected-color-name-{{ product.id }}">{{ product.colors.all.0.name }}</span></div> |
|
|
|
|
|
|
|
</div> |
|
|
|
<div class="option-element product-price">{{ product.price }} €</div> |
|
|
|
<div class="option-element product-price">{{ product.price }} €</div> |
|
|
|
<div class="option-element form-group"> |
|
|
|
<div class="option-element form-group"> |
|
|
|
{% if product.colors.exists %} |
|
|
|
{% if product.colors.exists %} |
|
|
|
<select name="color" id="color-{{ product.id }}" class="form-control" required> |
|
|
|
<input type="hidden" name="color" id="color-{{ product.id }}" value="{{ product.colors.all.0.id }}" required> |
|
|
|
<option value="" disabled selected>Couleur</option> |
|
|
|
<div class="color-samples"> |
|
|
|
{% for color in product.colors.all %} |
|
|
|
{% for color in product.colors.all %} |
|
|
|
<option value="{{ color.id }}" {% if forloop.first %}selected{% endif %}>{{ color.name }}</option> |
|
|
|
<div class="color-sample {% if forloop.first %}selected{% endif %}" |
|
|
|
|
|
|
|
style="background-color: {{ color.colorHex }}" |
|
|
|
|
|
|
|
title="{{ color.name }}" |
|
|
|
|
|
|
|
data-color-id="{{ color.id }}" |
|
|
|
|
|
|
|
data-color-name="{{ color.name }}" |
|
|
|
|
|
|
|
onclick="selectColor('{{ product.id }}', '{{ color.id }}', '{{ color.name }}', this)"></div> |
|
|
|
{% endfor %} |
|
|
|
{% endfor %} |
|
|
|
</select> |
|
|
|
</div> |
|
|
|
{% endif %} |
|
|
|
{% endif %} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="option-element form-group"> |
|
|
|
<div class="option-element form-group"> |
|
|
|
{% if product.sizes.exists %} |
|
|
|
{% if product.sizes.exists %} |
|
|
|
<select name="size" id="size-{{ product.id }}" class="form-control" required> |
|
|
|
<select name="size" id="size-{{ product.id }}" class="form-control" required> |
|
|
|
@ -53,4 +62,20 @@ function updateTotal(productId, price) { |
|
|
|
|
|
|
|
|
|
|
|
totalPriceElement.textContent = totalPrice; |
|
|
|
totalPriceElement.textContent = totalPrice; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function selectColor(productId, colorId, colorName, element) { |
|
|
|
|
|
|
|
// Update hidden input value |
|
|
|
|
|
|
|
document.getElementById(`color-${productId}`).value = colorId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update displayed color name |
|
|
|
|
|
|
|
document.getElementById(`selected-color-name-${productId}`).textContent = colorName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove selected class from all colors |
|
|
|
|
|
|
|
const colorSamples = element.parentElement.querySelectorAll('.color-sample'); |
|
|
|
|
|
|
|
colorSamples.forEach(sample => sample.classList.remove('selected')); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add selected class to clicked color |
|
|
|
|
|
|
|
element.classList.add('selected'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|