fix: stop truncating imported prices to whole euros

This commit is contained in:
fromme committed 2026-09-30 14:57:20 +02:00
1 parent b510299032
commit 27832d6548
16 files changed
+135 -60

No files matched your search

@@ -0,0 +1,45 @@
<?php
namespace EP\EpTheme\ViewHelpers;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
/**
* Formats a euro amount the way the website always has for whole euros ("229",
* "1234"), and with German decimals where there are cents ("99,90"). Prices are
* stored with cents, and the database hands them over as strings like "229.00".
*
* Keep in sync with formatPrice() in pricetable_controller.js.
*
* Usage: {row.minPrice -> ep:price()} €
*/
class PriceViewHelper extends AbstractViewHelper
{
use CompileWithContentArgumentAndRenderStatic;
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'mixed', 'Amount in euros');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$amount = round((float) $renderChildrenClosure(), 2);
$decimals = floor($amount) === $amount ? 0 : 2;
return number_format($amount, $decimals, ',', '');
}
}
@@ -42,13 +42,13 @@ export default class extends Controller {
modeValueChanged() {
this.priceTargets.forEach(price => {
let room = parseInt(price.dataset.room)
let bus = parseInt(price.dataset.bus)
let discount = parseInt(price.dataset.discount)
price.innerText = `${this.calculatePrice(room, bus, discount)} €`
let room = parseFloat(price.dataset.room)
let bus = parseFloat(price.dataset.bus)
let discount = parseFloat(price.dataset.discount)
price.innerText = `${this.formatPrice(this.calculatePrice(room, bus, discount))} €`
})
this.busIconTargets.forEach(icon => {
let busPrice = parseInt(icon.dataset.busPrice)
let busPrice = parseFloat(icon.dataset.busPrice)
let busIncluded = !!icon.dataset.busIncluded
icon.classList.toggle('hidden', this.isHideBusIcon(busPrice, busIncluded))
})
@@ -87,6 +87,16 @@ export default class extends Controller {
return minPrice
}
// Keep in sync with EP\EpTheme\ViewHelpers\PriceViewHelper: whole euros
// as before ("229"), German decimals where there are cents ("99,90").
formatPrice(amount) {
let cents = Math.round(amount * 100)
if (cents % 100 === 0) {
return String(cents / 100)
}
return (cents / 100).toFixed(2).replace('.', ',')
}
isHideBusIcon(busPrice, busIncluded) {
return (
busPrice && this.modeValue !== 'surcharge' ||
@@ -39,7 +39,7 @@
{hotel.teaser -> f:format.crop(maxCharacters: settings.teaserTextMaxChars) -> f:format.html()}
<f:if condition="{hotel.available} != -1">
<span class="teaserbox__price">
<strong>{f:if(condition: '{hotel.available} > 0', then: 'ab {hotel.minPrice} €', else: 'aktuell nicht buchbar')}</strong>
<strong><f:if condition="{hotel.available} > 0"><f:then>ab {hotel.minPrice -> ep:price()} €</f:then><f:else>aktuell nicht buchbar</f:else></f:if></strong>
</span>
</f:if>
</div>
@@ -53,10 +53,10 @@
<td class="px-2 py-1 border border-zinc-200">
<f:if condition="{row.available}">
<f:then>
{row.minPrice} €
{row.minPrice -> ep:price()} €
</f:then>
<f:else>
<s>{row.minPrice} €</s>
<s>{row.minPrice -> ep:price()} €</s>
</f:else>
</f:if>
</td>
@@ -104,7 +104,7 @@
</ul>
<div class="bg-ep-primary-dark text-white font-bold px-4 py-1 peer-hover:bg-badge-gradient peer-hover:text-white transition-colors">
<div class="lg:inline-block">
ab <span class="product-teaser__price mx-1">{minPrice} €</span>
ab <span class="product-teaser__price mx-1">{minPrice -> ep:price()} €</span>
</div>
<div class="product-teaser__label-price">
p. P.{f:if(condition: '{season} == "w" && {skiPassIncluded}', then: ' / inkl. Skipass')}
@@ -129,9 +129,9 @@
</td>
</f:if>
<td class="border-r border-zinc-200 px-2 py-1 md:p-2 text-center">
<f:if condition="{row.pseudoPrice}">
<f:if condition="{row.pseudoPrice} > 0">
<span class="block text-sm line-through">
{row.pseudoPrice} €
{row.pseudoPrice -> ep:price()} €
</span>
</f:if>
<span class="font-bold normal-case text-sm md:text-base whitespace-nowrap"
@@ -139,7 +139,7 @@
data-room="{row.minPrice}"
data-bus="{row.busPrice}"
data-discount="{row.discount}">
{row.minPrice}
{row.minPrice -> ep:price()}
</span>
</td>
<td class="px-2 py-1 md:p-2 text-center">
@@ -61,14 +61,14 @@
<f:link.typolink
parameter="{row.hotelDetailPageUid}"
class="whitespace-nowrap {ep:themeClasses(classes: '{sbw: \'text-sbw-primary\', snz: \'text-snz-primary\', uch: \'text-uch-primary\'}', key: settings.themekey)}">
{row.rooms.{type}.price}
{row.rooms.{type}.price -> ep:price()}
{f:if(condition: '{row.rooms.{type}.undersubscription}', then: '*')}
</f:link.typolink>
</f:then>
<f:else>
<f:if condition="{row.rooms.{type}.available}">
<f:else>
<span class="line-through text-zinc-500">{row.rooms.{type}.price}</span>
<span class="line-through text-zinc-500">{row.rooms.{type}.price -> ep:price()}</span>
</f:else>
</f:if>
</f:else>
@@ -266,7 +266,7 @@
data-room="{row.minPrice}"
data-bus="{row.busPrice}"
data-discount="{row.discount}">
{row.minPrice}
{row.minPrice -> ep:price()}
</span>
</a>
</f:then>
@@ -279,7 +279,7 @@
data-room="{row.minPrice}"
data-bus="{row.busPrice}"
data-discount="{row.discount}">
{row.minPrice} €
{row.minPrice -> ep:price()} €
</span>
</f:else>
</f:if>
@@ -127,7 +127,7 @@
</tr>
<tr>
<th>Abpreis</th>
<td>{date.minprice} €</td>
<td>{date.minprice -> ep:price()} €</td>
</tr>
<tr>
<th>Bus inkl.</th>
@@ -154,7 +154,7 @@
<tr>
<td>{room.name}</td>
<td>{v:variable.get(name: 'room.@pax')}</td>
<td>{room.price} €</td>
<td>{room.price -> ep:price()} €</td>
<td>{room.available}</td>
</tr>
</f:for>