From 08afc5061fcc4e71ead4cd7a6f121e5068236de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Thu, 12 Jul 2018 16:03:16 +0200 Subject: [PATCH] Proper treatment of partner codes in booking urls for resellers --- .../Classes/Service/ResellerService.php | 3 +- .../Classes/Utility/BookingUrlUtility.php | 82 +++++++++++++------ 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php b/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php index 4eedc224..3caf893b 100644 --- a/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php +++ b/web/typo3conf/ext/ep_products/Classes/Service/ResellerService.php @@ -110,11 +110,10 @@ class ResellerService implements SingletonInterface $data[$row['dateStart']] = $date; } - $date->bookingurl = BookingUrlUtility::generateUrl( + $date->bookingurl = BookingUrlUtility::generateResellerUrl( $row['dateBusProId'], $row['hotelBusProId'], $row['dateEnd'], - 'base', $paCode ); diff --git a/web/typo3conf/ext/ep_products/Classes/Utility/BookingUrlUtility.php b/web/typo3conf/ext/ep_products/Classes/Utility/BookingUrlUtility.php index d195262a..ecdf940f 100644 --- a/web/typo3conf/ext/ep_products/Classes/Utility/BookingUrlUtility.php +++ b/web/typo3conf/ext/ep_products/Classes/Utility/BookingUrlUtility.php @@ -44,7 +44,56 @@ class BookingUrlUtility * @param string $paCode * @return string */ - public static function generateUrl($bookingId, $hotelId, $dateEnd, $template = 'base', $paCode = null) + public static function generateUrl($bookingId, $hotelId, $dateEnd, $template = 'base') + { + $query = static::buildQuery($bookingId, $hotelId, $dateEnd, $template); + + $cookie = $_COOKIE[static::COOKIE_NAME]; + if (strpos($cookie, '?') !== false) { + $items = GeneralUtility::trimExplode('?', $cookie); + $cookie = $items[0]; + } + $bpnCookie = $_COOKIE[static::COOKIE_NAME_BPN]; + + if (!empty($bpnCookie)) { + $query['agenturcode'] = $bpnCookie; + } elseif (!empty($cookie)) { + if (preg_match('/^P[a-zA-Z0-9]*/', $cookie)) { + $query['agenturcode'] = $cookie; + } else { + $query['crminfo'] = $cookie; + } + } + + return static::buildUrl($query); + } + + /** + * @param string $bookingId + * @param string $hotelId + * @param string $dateEnd + * @param string $paCode + * @return string + */ + public static function generateResellerUrl($bookingId, $hotelId, $dateEnd, $paCode = null) + { + $query = static::buildQuery($bookingId, $hotelId, $dateEnd); + + if (!empty($paCode)) { + $query['agenturcode'] = $paCode; + } + + return static::buildUrl($query); + } + + /** + * @param string $bookingId + * @param string $hotelId + * @param string $dateEnd + * @param string $template + * @return array + */ + protected static function buildQuery($bookingId, $hotelId, $dateEnd, $template = 'base') { $query = [ 'id' => $bookingId, @@ -59,28 +108,15 @@ class BookingUrlUtility $query['templatezusatz'] = '_' . $template; } - if ($paCode !== null) { - $query['agenturcode'] = $paCode; - } else { - $cookie = $_COOKIE[static::COOKIE_NAME]; - if (strpos($cookie, '?') !== false) { - $items = GeneralUtility::trimExplode('?', $cookie); - $cookie = $items[0]; - } - $bpnCookie = $_COOKIE[static::COOKIE_NAME_BPN]; - - if (!empty($bpnCookie)) { - $query['agenturcode'] = $bpnCookie; - } elseif (!empty($cookie)) { - if (preg_match('/^P[a-zA-Z0-9]*/', $cookie)) { - $query['agenturcode'] = $cookie; - } else { - $query['crminfo'] = $cookie; - } - } - } - - return static::URL_BASE . '?' . http_build_query($query, '', '&'); + return $query; } + /** + * @param array $query + * @return string + */ + protected static function buildUrl(array $query) + { + return static::URL_BASE . '?' . http_build_query($query, '', '&'); + } }