cena on multiple choice
Some checks failed
CI / Check Style (push) Has been cancelled
CI / Run Clippy (push) Has been cancelled
CI / Run Tests (push) Has been cancelled

This commit is contained in:
Priec
2026-07-29 22:54:45 +02:00
parent f0d7d5b906
commit 49d64d397e
4 changed files with 24 additions and 1 deletions

View File

@@ -304,6 +304,7 @@ quantity = Quantity
add-to-cart = To cart
cart-added = Added to cart
in-stock = In stock
price-for-quantity = Total for this quantity:
out-of-stock = Out of stock
gallery-prev = Previous image
gallery-next = Next image

View File

@@ -304,6 +304,7 @@ quantity = Množstvo
add-to-cart = Do košíka
cart-added = Pridané do košíka
in-stock = Na sklade
price-for-quantity = Cena za zvolené množstvo:
out-of-stock = Vypredané
gallery-prev = Predchádzajúci obrázok
gallery-next = Ďalší obrázok

View File

@@ -78,7 +78,15 @@
x-data="{
variants: JSON.parse(document.getElementById('variant-data').textContent) || [],
sel: 0,
qty: 1,
get current() { return this.variants[this.sel] || null },
/* Informational line total for the typed quantity. Mirrors the server's
format_price (minor units -> '12.34'); the currency symbol is appended
in the markup, as everywhere else. */
get lineTotal() {
const cents = (this.current ? this.current.price_cents : 0) * Math.max(1, this.qty || 1);
return Math.floor(cents / 100) + '.' + String(cents % 100).padStart(2, '0');
},
init() {
const firstInStock = this.variants.findIndex(v => v.in_stock);
this.sel = Math.max(0, firstInStock);
@@ -139,10 +147,20 @@
<input type="hidden" name="variant_id" :value="current.id">
<div class="space-y-1.5">
<label for="quantity" class="text-sm font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="quantity", lang=lang | default(value='sk')) }}</label>
<input type="number" id="quantity" name="quantity" value="1" min="1" :max="current.stock" class="{{ fld }} w-24">
<input type="number" id="quantity" name="quantity" x-model.number="qty" value="1" min="1" :max="current.stock" class="{{ fld }} w-24">
</div>
<button type="submit" class="{{ btn }}">{{ t(key="add-to-cart", lang=lang | default(value='sk')) }}</button>
</form>
{# Informational only — what the typed quantity costs in total; the
cart recomputes it server-side. Hidden at qty 1, where it would
just repeat the unit price. #}
<template x-if="qty > 1">
<p class="text-sm text-on-surface/80 dark:text-on-surface-dark/80">
{{ t(key="price-for-quantity", lang=lang | default(value='sk')) }}
<span class="font-semibold text-on-surface-strong dark:text-on-surface-dark-strong"><span x-text="lineTotal"></span> {{ currency_symbol }}</span>
<span class="text-on-surface/60 dark:text-on-surface-dark/60">(<span x-text="qty"></span> × <span x-text="current.price"></span> {{ currency_symbol }})</span>
</p>
</template>
<p class="text-sm text-on-surface/60 dark:text-on-surface-dark/60">
<template x-if="current.tracked">
<span>{{ t(key="in-stock", lang=lang | default(value='sk')) }}: <span x-text="current.stock"></span></span>

View File

@@ -68,6 +68,9 @@ pub fn variant_option(
"tracked": variant.tracked(),
"in_stock": variant.in_stock(),
"price": cur.format(priced.price_cents),
// The same unit price in the display currency's minor units, so the
// detail page can multiply it by the typed quantity client-side.
"price_cents": cur.convert_cents(priced.price_cents),
"on_sale": priced.is_reduced(),
"regular_price": cur.format(priced.regular_cents),
"is_business": priced.is_business,