cena on multiple choice
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user