feat: replace cookie to store tracking code with native php session
This commit is contained in:
@@ -281,13 +281,6 @@ class AjaxTableController extends ActionController
|
||||
*/
|
||||
public function pricetableHtmlAction(Product $product, Hotel $hotel, string $bpnBookingUrlTemplateCode = null): void
|
||||
{
|
||||
// Disabled, not working anyways, reseller subdomains are not registered since TYPO3 10.*
|
||||
// if ($reseller = $this->resellerDataService->getResellerForCurrentDomain()) {
|
||||
// $paCode = $reseller['paCode'];
|
||||
// } else {
|
||||
// $paCode = null;
|
||||
// }
|
||||
|
||||
$nonBookableInfo = $this->getNonBookableInfobox($product);
|
||||
|
||||
$priceTable = $this->dateService->getPriceTable([
|
||||
|
||||
@@ -57,22 +57,17 @@ class BookingUrlUtility
|
||||
|
||||
$query = static::buildQuery($bookingId, $hotelId, $dateEnd, $template, $isDayTrip);
|
||||
|
||||
$epCookie = CookieUtility::getPaCookie();
|
||||
|
||||
if (isset($_COOKIE[static::COOKIE_NAME])) {
|
||||
if (!preg_match('/^([a-z]{4}|PA)\d{3,4}$/', $_COOKIE[static::COOKIE_NAME])) {
|
||||
setcookie(static::COOKIE_NAME, '', time() - 3600);
|
||||
unset($_COOKIE[static::COOKIE_NAME]);
|
||||
} else {
|
||||
$epCookie = $_COOKIE[static::COOKIE_NAME];
|
||||
}
|
||||
if ('' === session_id()) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$trackingCode = $_SESSION['ep_trk'] ?? null;
|
||||
|
||||
if (null !== $paCode) {
|
||||
$query['agenturcode'] = $paCode;
|
||||
} elseif ($epCookie) {
|
||||
$queryParameter = CookieUtility::getQueryParameter($epCookie);
|
||||
$query[$queryParameter] = $epCookie;
|
||||
} elseif (null !== $trackingCode) {
|
||||
$queryParameter = static::getQueryParameter($trackingCode);
|
||||
$query[$queryParameter] = $trackingCode;
|
||||
}
|
||||
|
||||
return static::buildUrl($query);
|
||||
@@ -139,4 +134,13 @@ class BookingUrlUtility
|
||||
|
||||
return $site->getBase() . '/buchung/maske_buchung.php?' . http_build_query($query);
|
||||
}
|
||||
|
||||
protected static function getQueryParameter($code)
|
||||
{
|
||||
if (!preg_match('/^PA\d{3,4}$/', $code)) {
|
||||
return 'crminfo';
|
||||
}
|
||||
|
||||
return 'agenturcode';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace EP\EpProducts\Utility;
|
||||
|
||||
class CookieUtility
|
||||
{
|
||||
const COOKIENAME_TRK = 'ep_trk';
|
||||
const COOKIETTL_TRK = 30;
|
||||
const PATTERN = '/^PA\d{3,4}$/';
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getPaCookie()
|
||||
{
|
||||
if (!isset($_COOKIE[static::COOKIENAME_TRK])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cookieValue = $_COOKIE[static::COOKIENAME_TRK];
|
||||
|
||||
if (!preg_match(static::PATTERN, $cookieValue)) {
|
||||
setcookie(static::COOKIENAME_TRK, '', time() - 3600);
|
||||
unset($_COOKIE[static::COOKIENAME_TRK]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $cookieValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return string
|
||||
*/
|
||||
public static function getQueryParameter($code)
|
||||
{
|
||||
if (!preg_match(static::PATTERN, $code)) {
|
||||
return 'crminfo';
|
||||
}
|
||||
|
||||
return 'agenturcode';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setPaCookie($code)
|
||||
{
|
||||
$expiratonDate = new \DateTime('now');
|
||||
$expiratonDate->add(new \DateInterval('P' . static::COOKIETTL_TRK . 'D'));
|
||||
setcookie(
|
||||
static::COOKIENAME_TRK,
|
||||
strtoupper($code),
|
||||
$expiratonDate->getTimestamp(),
|
||||
'/'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,6 @@ class ContextProcessor implements DataProcessorInterface
|
||||
}
|
||||
if ($data['tx_eptheme_context_pacode']) {
|
||||
$processedData['context']['paCode'] = $data['tx_eptheme_context_pacode'];
|
||||
// Disabled, not working anyways, reseller subdomains are not registered since TYPO3 10.*
|
||||
// } elseif ($resellerData = $this->getResellerData()) {
|
||||
// $processedData['context']['paCode'] = $resellerData['paCode'];
|
||||
} elseif ($paCode = $this->getPaCodeFromRequest()) {
|
||||
$processedData['context']['paCode'] = $paCode;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace EP\EpTrack\Middleware;
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||
use EP\EpProducts\Utility\CookieUtility;
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@@ -102,7 +101,7 @@ class TrackingMiddleware implements MiddlewareInterface
|
||||
$trackingCode = $redirect['tracking_code'];
|
||||
|
||||
if (!empty($trackingCode)) {
|
||||
CookieUtility::setPaCookie($trackingCode);
|
||||
$this->saveTrackingCodeToSession($trackingCode);
|
||||
}
|
||||
|
||||
$targetPage = $redirect['target_page_uid'];
|
||||
@@ -159,7 +158,7 @@ class TrackingMiddleware implements MiddlewareInterface
|
||||
|
||||
$urlItems = GeneralUtility::trimExplode('/', $path, true);
|
||||
$code = array_pop($urlItems);
|
||||
CookieUtility::setPaCookie($code);
|
||||
$this->saveTrackingCodeToSession($code);
|
||||
$uri = '/';
|
||||
if (count($urlItems) > 0) {
|
||||
$uri = '/' . implode('/', $urlItems) . '/';
|
||||
@@ -170,4 +169,13 @@ class TrackingMiddleware implements MiddlewareInterface
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
private function saveTrackingCodeToSession(string $trackingCode)
|
||||
{
|
||||
if ('' === session_id()) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$_SESSION['ep_trk'] = $trackingCode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user