cena on multiple choice
This commit is contained in:
@@ -304,6 +304,7 @@ quantity = Quantity
|
|||||||
add-to-cart = To cart
|
add-to-cart = To cart
|
||||||
cart-added = Added to cart
|
cart-added = Added to cart
|
||||||
in-stock = In stock
|
in-stock = In stock
|
||||||
|
price-for-quantity = Total for this quantity:
|
||||||
out-of-stock = Out of stock
|
out-of-stock = Out of stock
|
||||||
gallery-prev = Previous image
|
gallery-prev = Previous image
|
||||||
gallery-next = Next image
|
gallery-next = Next image
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ quantity = Množstvo
|
|||||||
add-to-cart = Do košíka
|
add-to-cart = Do košíka
|
||||||
cart-added = Pridané do košíka
|
cart-added = Pridané do košíka
|
||||||
in-stock = Na sklade
|
in-stock = Na sklade
|
||||||
|
price-for-quantity = Cena za zvolené množstvo:
|
||||||
out-of-stock = Vypredané
|
out-of-stock = Vypredané
|
||||||
gallery-prev = Predchádzajúci obrázok
|
gallery-prev = Predchádzajúci obrázok
|
||||||
gallery-next = Ďalší obrázok
|
gallery-next = Ďalší obrázok
|
||||||
|
|||||||
@@ -78,7 +78,15 @@
|
|||||||
x-data="{
|
x-data="{
|
||||||
variants: JSON.parse(document.getElementById('variant-data').textContent) || [],
|
variants: JSON.parse(document.getElementById('variant-data').textContent) || [],
|
||||||
sel: 0,
|
sel: 0,
|
||||||
|
qty: 1,
|
||||||
get current() { return this.variants[this.sel] || null },
|
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() {
|
init() {
|
||||||
const firstInStock = this.variants.findIndex(v => v.in_stock);
|
const firstInStock = this.variants.findIndex(v => v.in_stock);
|
||||||
this.sel = Math.max(0, firstInStock);
|
this.sel = Math.max(0, firstInStock);
|
||||||
@@ -139,10 +147,20 @@
|
|||||||
<input type="hidden" name="variant_id" :value="current.id">
|
<input type="hidden" name="variant_id" :value="current.id">
|
||||||
<div class="space-y-1.5">
|
<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>
|
<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>
|
</div>
|
||||||
<button type="submit" class="{{ btn }}">{{ t(key="add-to-cart", lang=lang | default(value='sk')) }}</button>
|
<button type="submit" class="{{ btn }}">{{ t(key="add-to-cart", lang=lang | default(value='sk')) }}</button>
|
||||||
</form>
|
</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">
|
<p class="text-sm text-on-surface/60 dark:text-on-surface-dark/60">
|
||||||
<template x-if="current.tracked">
|
<template x-if="current.tracked">
|
||||||
<span>{{ t(key="in-stock", lang=lang | default(value='sk')) }}: <span x-text="current.stock"></span></span>
|
<span>{{ t(key="in-stock", lang=lang | default(value='sk')) }}: <span x-text="current.stock"></span></span>
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ pub fn variant_option(
|
|||||||
"tracked": variant.tracked(),
|
"tracked": variant.tracked(),
|
||||||
"in_stock": variant.in_stock(),
|
"in_stock": variant.in_stock(),
|
||||||
"price": cur.format(priced.price_cents),
|
"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(),
|
"on_sale": priced.is_reduced(),
|
||||||
"regular_price": cur.format(priced.regular_cents),
|
"regular_price": cur.format(priced.regular_cents),
|
||||||
"is_business": priced.is_business,
|
"is_business": priced.is_business,
|
||||||
|
|||||||
Reference in New Issue
Block a user