Proper treatment of partner codes in booking urls for resellers

This commit is contained in:
Björn Fromme
2018-07-12 16:03:16 +02:00
parent 42e3e00c7e
commit 08afc5061f
2 changed files with 60 additions and 25 deletions
@@ -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
);
@@ -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, '', '&');
}
}