#18 - membership

This commit was merged in pull request #23.
This commit is contained in:
Martin Slachta
2026-06-17 11:15:09 +02:00
parent df5f9b1df4
commit c754e18a82
25 changed files with 885 additions and 35 deletions
@@ -1,6 +1,6 @@
<?php
/** Computes a form's total price as the sum of its elements' prices. */
/** Computes a form's total price as the sum of its elements' prices, reduced by membership discount. */
class RsvFormPriceCalculator {
public function calculate(RsvFormDefinition $definition, RsvFormData $data): float {
global $rsv_form_price_registry;
@@ -16,6 +16,7 @@ class RsvFormPriceCalculator {
$total += (float) $calculator($element, $data->getValue($element->getName()));
}
return $total;
$pct = (new RsvMembershipService())->discount_for($definition, $data);
return $total * (1.0 - max(0.0, min(100.0, $pct)) / 100.0);
}
}