@@ -4,8 +4,25 @@
|
||||
final class RsvFormCalculatedValues {
|
||||
/** @return array<string, mixed> */
|
||||
public function for(RsvFormDefinition $definition, RsvFormData $data): array {
|
||||
$calculator = new RsvFormPriceCalculator();
|
||||
global $rsv_form_price_registry;
|
||||
|
||||
$price_before_discount = 0.0;
|
||||
foreach ($definition->getElements() as $element) {
|
||||
$element_calculator = $rsv_form_price_registry->get($element->getType());
|
||||
if ($element_calculator === null) {
|
||||
continue;
|
||||
}
|
||||
$price_before_discount += (float) $element_calculator($element, $data->getValue($element->getName()));
|
||||
}
|
||||
|
||||
$discount_pct = (new RsvMembershipService())->discount_for($definition, $data);
|
||||
$final_price = $calculator->calculate($definition, $data);
|
||||
|
||||
return [
|
||||
'price' => (new RsvFormPriceCalculator())->calculate($definition, $data),
|
||||
'price' => $final_price,
|
||||
'price_before_discount' => $price_before_discount,
|
||||
'discount_percent' => $discount_pct,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -14,6 +31,6 @@ final class RsvFormCalculatedValues {
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function names(): array {
|
||||
return ['price'];
|
||||
return ['price', 'price_before_discount', 'discount_percent'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user