diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/AjaxTableController.php b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxTableController.php index 30008cb9..8b3cdc1f 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/AjaxTableController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxTableController.php @@ -176,6 +176,7 @@ class AjaxTableController extends ActionController $bookableDates = array_filter($allDates, function (array $date) { return $date['available'] > 0; }); + $includedServices = $this->dateService->groupIncludedServices($bookableDates); $altProductLink = null; $altLabel = null; @@ -205,6 +206,8 @@ class AjaxTableController extends ActionController $this->view->assignMultiple([ 'allDates' => $allDates, 'bookableDates' => $bookableDates, + 'includedServicesAllDates' => $includedServices['allDates'], + 'includedServicesSomeDates' => $includedServices['someDates'], 'bookable' => $product->getBookable(), 'unavailable' => 0 === count($allDates), 'product' => $product, diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php index 7cc74854..a13ce9ce 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php @@ -442,6 +442,70 @@ class DateService implements SingletonInterface return false; } + /** + * Group included services across bookable dates. + * + * Returns services that appear in every supplied date and services that + * appear in at least one supplied date but not all of them. + * + * @param array $dates + * @return array{allDates: array, someDates: array} + */ + public function groupIncludedServices(array $dates): array + { + $serviceCounts = []; + $serviceOrder = []; + $dateCount = count($dates); + + foreach ($dates as $date) { + $dateServices = $date['servicesIncluded'] ?? []; + if (!is_array($dateServices)) { + continue; + } + + $seenInDate = []; + foreach ($dateServices as $service) { + if (!is_string($service) || '' === trim($service)) { + continue; + } + + if (isset($seenInDate[$service])) { + continue; + } + $seenInDate[$service] = true; + + if (!array_key_exists($service, $serviceCounts)) { + $serviceCounts[$service] = 0; + $serviceOrder[] = $service; + } + + $serviceCounts[$service]++; + } + } + + $groupedServices = [ + 'allDates' => [], + 'someDates' => [], + ]; + + if (0 === $dateCount) { + return $groupedServices; + } + + foreach ($serviceOrder as $service) { + $count = $serviceCounts[$service] ?? 0; + if ($dateCount === $count) { + $groupedServices['allDates'][] = $service; + } elseif ($count > 0) { + $groupedServices['someDates'][] = $service; + } + } + + sort($groupedServices['someDates'], SORT_NATURAL | SORT_FLAG_CASE); + + return $groupedServices; + } + public function checkSurcharcheOrDiscount(array $tableData): array { $data = [ diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/AjaxTable/Datestable.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/AjaxTable/Datestable.html index 11075b31..1ed9239d 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/AjaxTable/Datestable.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/AjaxTable/Datestable.html @@ -176,69 +176,110 @@ -