Implement selectable dates to hide booking button for per product

This commit is contained in:
Björn Fromme
2020-03-03 14:40:53 +01:00
parent 992d8f5ab1
commit 156e39eb68
4 changed files with 70 additions and 6 deletions
@@ -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
@@ -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([
@@ -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',
]
]
],
];
@@ -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'
#