diff --git a/assets/i18n/en/main.ftl b/assets/i18n/en/main.ftl index 7320745..d297d03 100644 --- a/assets/i18n/en/main.ftl +++ b/assets/i18n/en/main.ftl @@ -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 diff --git a/assets/i18n/sk/main.ftl b/assets/i18n/sk/main.ftl index 1f15ca0..a33c626 100644 --- a/assets/i18n/sk/main.ftl +++ b/assets/i18n/sk/main.ftl @@ -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 diff --git a/assets/views/shop/show.html b/assets/views/shop/show.html index 9284ac5..46fb00b 100644 --- a/assets/views/shop/show.html +++ b/assets/views/shop/show.html @@ -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 @@
+ {{ t(key="price-for-quantity", lang=lang | default(value='sk')) }} + {{ currency_symbol }} + ( × {{ currency_symbol }}) +
+{{ t(key="in-stock", lang=lang | default(value='sk')) }}: diff --git a/src/views/shop.rs b/src/views/shop.rs index 04ae0f2..e6d7243 100644 --- a/src/views/shop.rs +++ b/src/views/shop.rs @@ -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,