Show correct number of currency placed in widget (Z#23241522)

This commit is contained in:
Kara Engelhardt
2026-07-27 12:27:21 +02:00
parent db147280fd
commit 3d31cdaed4
7 changed files with 32 additions and 20 deletions
+1
View File
@@ -795,6 +795,7 @@ class WidgetAPIProductList(EventListMixin, View):
'target_url': eventreverse_absolute(request.event, 'presale:event.index'), 'target_url': eventreverse_absolute(request.event, 'presale:event.index'),
'subevent': self.subevent.pk if self.subevent else None, 'subevent': self.subevent.pk if self.subevent else None,
'currency': request.event.currency, 'currency': request.event.currency,
'currency_places': settings.CURRENCY_PLACES.get(request.event.currency, 2),
'display_net_prices': request.event.settings.display_net_prices, 'display_net_prices': request.event.settings.display_net_prices,
'use_native_spinners': request.event.settings.widget_use_native_spinners, 'use_native_spinners': request.event.settings.widget_use_native_spinners,
'show_variations_expanded': request.event.settings.show_variations_expanded, 'show_variations_expanded': request.event.settings.show_variations_expanded,
@@ -380,16 +380,16 @@ Vue.component('pricebox', {
}, },
display_price: function () { display_price: function () {
if (this.$root.display_net_prices) { if (this.$root.display_net_prices) {
return floatformat(parseFloat(this.price.net), 2); return floatformat(this.price.net, this.$root.currency_places);
} else { } else {
return floatformat(parseFloat(this.price.gross), 2); return floatformat(this.price.gross, this.$root.currency_places);
} }
}, },
display_price_nonlocalized: function () { display_price_nonlocalized: function () {
if (this.$root.display_net_prices) { if (this.$root.display_net_prices) {
return parseFloat(this.price.net).toFixed(2); return parseFloat(this.price.net).toFixed(this.$root.currency_places);
} else { } else {
return parseFloat(this.price.gross).toFixed(2); return parseFloat(this.price.gross).toFixed(this.$root.currency_places);
} }
}, },
suggested_price_nonlocalized: function () { suggested_price_nonlocalized: function () {
@@ -398,9 +398,9 @@ Vue.component('pricebox', {
price = this.price; price = this.price;
} }
if (this.$root.display_net_prices) { if (this.$root.display_net_prices) {
return parseFloat(price.net).toFixed(2); return parseFloat(price.net).toFixed(this.$root.currency_places);
} else { } else {
return parseFloat(price.gross).toFixed(2); return parseFloat(price.gross).toFixed(this.$root.currency_places);
} }
}, },
original_price_aria_label: function () { original_price_aria_label: function () {
@@ -410,7 +410,7 @@ Vue.component('pricebox', {
return django.interpolate(strings.new_price, [this.stripHTML(this.priceline)]); return django.interpolate(strings.new_price, [this.stripHTML(this.priceline)]);
}, },
original_line: function () { original_line: function () {
return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> " + floatformat(parseFloat(this.original_price), 2); return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> " + floatformat(this.original_price, this.$root.currency_places);
}, },
priceline: function () { priceline: function () {
if (this.price.gross === "0.00") { if (this.price.gross === "0.00") {
@@ -645,19 +645,19 @@ Vue.component('item', {
if (this.item.free_price) { if (this.item.free_price) {
return django.interpolate(strings.price_from, { return django.interpolate(strings.price_from, {
'currency': this.$root.currency, 'currency': this.$root.currency,
'price': floatformat(this.item.min_price, 2) 'price': floatformat(this.item.min_price, this.$root.currency_places)
}, true).replace(this.$root.currency, '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + '</span>'); }, true).replace(this.$root.currency, '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + '</span>');
} else if (this.item.min_price !== this.item.max_price) { } else if (this.item.min_price !== this.item.max_price) {
return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> " return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> "
+ floatformat(this.item.min_price, 2) + " " + floatformat(this.item.min_price, this.$root.currency_places) + " "
+ floatformat(this.item.max_price, 2); + floatformat(this.item.max_price, this.$root.currency_places);
} else if (this.item.min_price === "0.00" && this.item.max_price === "0.00") { } else if (this.item.min_price === "0.00" && this.item.max_price === "0.00") {
if (this.item.mandatory_priced_addons) { if (this.item.mandatory_priced_addons) {
return "\xA0"; // nbsp, because an empty string would cause the HTML element to collapse return "\xA0"; // nbsp, because an empty string would cause the HTML element to collapse
} }
return strings.free; return strings.free;
} else { } else {
return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> " + floatformat(this.item.min_price, 2); return '<span class="pretix-widget-pricebox-currency">' + this.$root.currency + "</span> " + floatformat(this.item.min_price, this.$root.currency_places);
} }
}, },
variationsToggleLabel: function () { variationsToggleLabel: function () {
@@ -1949,6 +1949,7 @@ var shared_root_methods = {
root.location = data.location; root.location = data.location;
root.categories = data.items_by_category; root.categories = data.items_by_category;
root.currency = data.currency; root.currency = data.currency;
root.currency_places = data.currency_places;
root.display_net_prices = data.display_net_prices; root.display_net_prices = data.display_net_prices;
root.voucher_explanation_text = data.voucher_explanation_text; root.voucher_explanation_text = data.voucher_explanation_text;
root.error = data.error; root.error = data.error;
@@ -1983,6 +1984,7 @@ var shared_root_methods = {
}, function (error) { }, function (error) {
root.categories = []; root.categories = [];
root.currency = ''; root.currency = '';
root.currency_places = 2;
if (error.status === 429) { if (error.status === 429) {
root.error = strings['loading_error_429']; root.error = strings['loading_error_429'];
root.connection_error = true; root.connection_error = true;
@@ -2339,6 +2341,7 @@ var create_widget = function (element, html_id=null) {
is_button: false, is_button: false,
categories: null, categories: null,
currency: null, currency: null,
currency_places: 2,
name: null, name: null,
date_range: null, date_range: null,
location: null, location: null,
@@ -22,6 +22,7 @@ export interface ProductListResponse {
location?: string location?: string
items_by_category?: Category[] items_by_category?: Category[]
currency?: string currency?: string
currency_places?: number
display_net_prices?: boolean display_net_prices?: boolean
voucher_explanation_text?: string voucher_explanation_text?: string
error?: string error?: string
@@ -72,7 +72,7 @@ const pricerange = computed(() => {
STRINGS.price_from, STRINGS.price_from,
{ {
currency: store.currency, currency: store.currency,
price: floatformat(props.item.min_price || '0', 2), price: floatformat(props.item.min_price || '0', store.currency_places),
}, },
true true
).replace( ).replace(
@@ -80,14 +80,14 @@ const pricerange = computed(() => {
`<span class="pretix-widget-pricebox-currency">${store.currency}</span>` `<span class="pretix-widget-pricebox-currency">${store.currency}</span>`
) )
} else if (props.item.min_price !== props.item.max_price) { } else if (props.item.min_price !== props.item.max_price) {
return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(props.item.min_price || '0', 2)} ${floatformat(props.item.max_price || '0', 2)}` return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(props.item.min_price || '0', store.currency_places)} ${floatformat(props.item.max_price || '0', store.currency_places)}`
} else if (props.item.min_price === '0.00' && props.item.max_price === '0.00') { } else if (props.item.min_price === '0.00' && props.item.max_price === '0.00') {
if (props.item.mandatory_priced_addons) { if (props.item.mandatory_priced_addons) {
return '\xA0' // nbsp, because an empty string would cause the HTML element to collapse return '\xA0' // nbsp, because an empty string would cause the HTML element to collapse
} }
return STRINGS.free return STRINGS.free
} else { } else {
return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(props.item.min_price || '0', 2)}` return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(props.item.min_price || '0', store.currency_places)}`
} }
}) })
@@ -25,9 +25,9 @@ const ariaLabelledby = computed(() => `${store.htmlId}-item-label-${props.itemId
const displayPrice = computed(() => { const displayPrice = computed(() => {
if (store.displayNetPrices) { if (store.displayNetPrices) {
return floatformat(parseFloat(props.price.net), 2) return floatformat(props.price.net, store.currency_places)
} }
return floatformat(parseFloat(props.price.gross), 2) return floatformat(props.price.gross, store.currency_places)
}) })
const displayPriceNonlocalized = computed(() => { const displayPriceNonlocalized = computed(() => {
@@ -40,15 +40,15 @@ const displayPriceNonlocalized = computed(() => {
const suggestedPriceNonlocalized = computed(() => { const suggestedPriceNonlocalized = computed(() => {
const price = props.suggestedPrice ?? props.price const price = props.suggestedPrice ?? props.price
if (store.displayNetPrices) { if (store.displayNetPrices) {
return parseFloat(price.net).toFixed(2) return parseFloat(price.net).toFixed(store.currency_places)
} }
return parseFloat(price.gross).toFixed(2) return parseFloat(price.gross).toFixed(store.currency_places)
}) })
// TODO BAD // TODO BAD
const originalLine = computed(() => { const originalLine = computed(() => {
if (!props.originalPrice) return '' if (!props.originalPrice) return ''
return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(parseFloat(props.originalPrice), 2)}` return `<span class="pretix-widget-pricebox-currency">${store.currency}</span> ${floatformat(props.originalPrice, store.currency_places)}`
}) })
// TODO BAD // TODO BAD
@@ -71,6 +71,7 @@ export function createWidgetStore (config: {
frontpageText: null as string | null, frontpageText: null as string | null,
categories: [] as Category[], categories: [] as Category[],
currency: '', currency: '',
currency_places: 2,
displayNetPrices: false, displayNetPrices: false,
voucherExplanationText: null as string | null, voucherExplanationText: null as string | null,
displayAddToCart: false, displayAddToCart: false,
@@ -299,6 +300,7 @@ export function createWidgetStore (config: {
this.location = data.location ?? null this.location = data.location ?? null
this.categories = data.items_by_category ?? [] this.categories = data.items_by_category ?? []
this.currency = data.currency ?? '' this.currency = data.currency ?? ''
this.currency_places = data.currency_places ?? 2
this.displayNetPrices = data.display_net_prices ?? false this.displayNetPrices = data.display_net_prices ?? false
this.voucherExplanationText = data.voucher_explanation_text ?? null this.voucherExplanationText = data.voucher_explanation_text ?? null
this.error = data.error ?? null this.error = data.error ?? null
@@ -338,6 +340,7 @@ export function createWidgetStore (config: {
} catch (e) { } catch (e) {
this.categories = [] this.categories = []
this.currency = '' this.currency = ''
this.currency_places = 2
if (e instanceof ApiError && e.status === 429) { if (e instanceof ApiError && e.status === 429) {
this.error = STRINGS.loading_error_429 this.error = STRINGS.loading_error_429
} else { } else {
+4
View File
@@ -173,6 +173,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
"currency_places": 2,
"show_variations_expanded": False, "show_variations_expanded": False,
"display_net_prices": False, "display_net_prices": False,
"use_native_spinners": False, "use_native_spinners": False,
@@ -379,6 +380,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
"currency_places": 2,
"show_variations_expanded": False, "show_variations_expanded": False,
"display_net_prices": False, "display_net_prices": False,
"use_native_spinners": False, "use_native_spinners": False,
@@ -439,6 +441,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
"currency_places": 2,
"show_variations_expanded": False, "show_variations_expanded": False,
"display_net_prices": False, "display_net_prices": False,
"use_native_spinners": False, "use_native_spinners": False,
@@ -524,6 +527,7 @@ class WidgetCartTest(CartTestMixin, TestCase):
"frontpage_text": "", "frontpage_text": "",
"location": "", "location": "",
"currency": "EUR", "currency": "EUR",
"currency_places": 2,
'poweredby': '<a href="https://pretix.eu" target="_blank" rel="noopener">ticketing powered by pretix</a>', 'poweredby': '<a href="https://pretix.eu" target="_blank" rel="noopener">ticketing powered by pretix</a>',
"show_variations_expanded": False, "show_variations_expanded": False,
"display_net_prices": False, "display_net_prices": False,