From 156e39eb6873fc1ae9515c446d11df32bf87fee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Tue, 3 Mar 2020 14:40:53 +0100 Subject: [PATCH] Implement selectable dates to hide booking button for per product --- .../Domain/Repository/ProductRepository.php | 25 +++++++++++++++++++ .../Classes/Service/DateService.php | 19 +++++++++++--- .../tx_epproducts_domain_model_product.php | 16 ++++++++++-- .../typo3conf/ext/ep_products/ext_tables.sql | 16 +++++++++++- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php index b3c7b967..b6737861 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php @@ -247,6 +247,31 @@ class ProductRepository extends AbstractRepository return $query->execute()->fetchAll(); } + /** + * Returns uids of date records that are selected to be non bookable + * via backend + * + * @param Product $product + * @return array + */ + public function getNonBookableDateUids(Product $product) + { + $qb = $this->getDbConnection()->createQueryBuilder(); + + $result = $qb + ->select('uid_foreign as uid') + ->from('tx_epproducts_product_date_mm') + ->where('uid_local = :product') + ->setParameter('product', $product->getUid()) + ->execute() + ->fetchAll() + ; + + return array_map(function ($row) { + return $row['uid']; + }, $result); + } + /** * @param Product $product * @param Hotel $hotel diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php index 2691e65f..739cdb1c 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php @@ -144,12 +144,22 @@ class DateService implements SingletonInterface if ($filterSettings === null) { $filterSettings = $this->filterService->getDefaultFilterSettings(); } + + $nonBookableDateUids = $this->productRepository->getNonBookableDateUids($product); + + $dateTableData = $this->productRepository->getAvailableDates( + $product, + $hotel, + $filterSettings + ); + return $this->preprocessDateTable([ - 'dateTableData' => $this->productRepository->getAvailableDates($product, $hotel, $filterSettings), + 'dateTableData' => $dateTableData, 'template' => $template, 'paCode' => $paCode, 'isDayTrip' => $product->isDaytrip(), 'isHideBookingButton' => $product->getHideBookingButton(), + 'nonBookableDateUids' => $nonBookableDateUids, ]); } @@ -317,10 +327,11 @@ class DateService implements SingletonInterface public function preprocessDateTable(array $options) { $resolver = new OptionsResolver(); - $resolver->setDefined(['paCode', 'isDayTrip', 'isHideBookingButton']); + $resolver->setDefined(['paCode', 'isDayTrip', 'isHideBookingButton', 'nonBookableDateUids']); $resolver->setRequired(['dateTableData', 'template']); $resolver->setDefault('isDayTrip', false); $resolver->setDefault('isHideBookingButton', false); + $resolver->setDefault('nonBookableDateUids', []); $resolvedOptions = $resolver->resolve($options); $dateTable = []; @@ -329,10 +340,12 @@ class DateService implements SingletonInterface $template = $resolvedOptions['template']; $paCode = $resolvedOptions['paCode']; $isDayTrip = $resolvedOptions['isDayTrip']; - $isHideBookingButton = $resolvedOptions['isHideBookingButton']; + $nonBookableDateUids = $resolvedOptions['nonBookableDateUids']; foreach ($dateTableData as $row) { + $isHideBookingButton = $resolvedOptions['isHideBookingButton'] || in_array($row['dateUid'], $nonBookableDateUids, false); + $dateStart = new \DateTime($row['dateStart']); $dateEnd = new \DateTime($row['dateEnd']); $bookingUrl = BookingUrlUtility::generateUrl([ diff --git a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php index f3c4766d..eacfe56d 100644 --- a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php +++ b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php @@ -29,7 +29,7 @@ return [ rating_average, rating_votes_count, teaser_images, header_images, images, concept, country, region, city, journey, facts, officetip, hotels, calendar_hotel, faqs,header_title,header_subtitle, alt_product, alt_label, video, banner, additional_regions, badge, daytrip, testimonials, external_link, path_segment, - hide_booking_button', + hide_booking_button,non_bookable_dates', ], 'types' => [ '1' => [ @@ -40,7 +40,8 @@ return [ --div--;Verknüpfungen, journey, --palette--;;concept, hotels, facts, faqs, officetip, additional_regions, badge, --div--;Bilder/Dateien, teaser_images, header_images, images, reseller_images, banner, video, - --div--;Bewertung, --palette--;;rating, testimonials', + --div--;Bewertung, --palette--;;rating, testimonials, + --div--;Buchbarkeit, non_bookable_dates', ], ], 'palettes' => [ @@ -831,5 +832,16 @@ return [ 'eval' => 'uniqueInSite', ], ], + 'non_bookable_dates' => [ + 'exclude' => 0, + 'label' => 'Nicht buchbare Termine', + 'config' => [ + 'type' => 'select', + 'renderType' => 'selectSingleBox', + 'foreign_table' => 'tx_epproducts_domain_model_date', + 'foreign_table_where' => 'AND tx_epproducts_domain_model_date.product=###THIS_UID### ORDER BY tx_epproducts_domain_model_date.date_start', + 'MM' => 'tx_epproducts_product_date_mm', + ] + ] ], ]; diff --git a/public/typo3conf/ext/ep_products/ext_tables.sql b/public/typo3conf/ext/ep_products/ext_tables.sql index 3be2bec4..f806b43f 100644 --- a/public/typo3conf/ext/ep_products/ext_tables.sql +++ b/public/typo3conf/ext/ep_products/ext_tables.sql @@ -59,7 +59,7 @@ CREATE TABLE tx_epproducts_domain_model_product video varchar(255) DEFAULT '' NOT NULL, banner int(11) unsigned NOT NULL default '0', badge int(11) unsigned NOT NULL default '0', - + non_bookable_dates int(11) unsigned NOT NULL default '0', tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, cruser_id int(11) unsigned DEFAULT '0' NOT NULL, @@ -1329,6 +1329,20 @@ CREATE TABLE tx_epproducts_product_region_mm KEY uid_foreign (uid_foreign) ); +# +# Table structure for table 'tx_epproducts_product_date_mm' +# +CREATE TABLE tx_epproducts_product_date_mm +( + uid_local int(11) unsigned DEFAULT '0' NOT NULL, + uid_foreign int(11) unsigned DEFAULT '0' NOT NULL, + sorting int(11) unsigned DEFAULT '0' NOT NULL, + sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL, + + KEY uid_local (uid_local), + KEY uid_foreign (uid_foreign) +); + # # Table structure for table 'tx_epproducts_hotel_teammember_mm' #