Append utm parameter to urls in google business feed

This commit is contained in:
Björn Fromme
2019-06-19 09:26:37 +02:00
parent f4ae74201e
commit f2350b4e56
4 changed files with 61 additions and 13 deletions
@@ -95,7 +95,12 @@ class ResellerController extends ActionController
public function copypasteAction(Reseller $reseller, Product $product) public function copypasteAction(Reseller $reseller, Product $product)
{ {
if (!$reseller->getProducts()->contains($product)) { if (!$reseller->getProducts()->contains($product)) {
$this->redirect('list', null, null, [ 'reseller' => $reseller ]); $this->redirect(
'list',
null,
null,
[ 'reseller' => $reseller ]
);
} }
$productData = $this->resellerDataService->preprocessSingle($product, $reseller); $productData = $this->resellerDataService->preprocessSingle($product, $reseller);
@@ -126,7 +131,11 @@ class ResellerController extends ActionController
header('Expires: 0'); header('Expires: 0');
header('Pragma: public'); header('Pragma: public');
echo $serializer->serialize($data, 'xml', [ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ]); echo $serializer->serialize(
$data,
'xml',
[ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ]
);
exit(); exit();
} }
@@ -143,7 +152,11 @@ class ResellerController extends ActionController
throw new InvalidArgumentValueException(); throw new InvalidArgumentValueException();
} }
$data = $this->resellerDataService->preprocessAll($reseller, static::$imageDimensions[$type]); $data = $this->resellerDataService->preprocessAll(
$reseller,
static::$imageDimensions[$type],
$type
);
$filename = sprintf('export_%s_%s.csv', $reseller->getCode(), date('Y-m-d')); $filename = sprintf('export_%s_%s.csv', $reseller->getCode(), date('Y-m-d'));
@@ -35,12 +35,14 @@ class Product
/** /**
* @param \EP\EpProducts\Domain\Model\Product $entity * @param \EP\EpProducts\Domain\Model\Product $entity
* @param array $imageProcessingInstructions * @param array $imageProcessingInstructions
* @param array $queryData
* @return array * @return array
*/ */
public static function fromEntity public static function fromEntity
( (
\EP\EpProducts\Domain\Model\Product $entity, \EP\EpProducts\Domain\Model\Product $entity,
array $imageProcessingInstructions = null array $imageProcessingInstructions = null,
array $queryData = []
) )
{ {
$product = [ $product = [
@@ -75,7 +77,7 @@ class Product
$product['video'] = $entity->getVideo(); $product['video'] = $entity->getVideo();
$link = $entity->getExternalLink() ?: $entity->getDetailPage(); $link = $entity->getExternalLink() ?: $entity->getDetailPage();
$product['link'] = SerializationUtility::generateLink($link); $product['link'] = SerializationUtility::generateLink($link, $queryData);
$product['region'] = Region::fromEntity($entity->getRegion()); $product['region'] = Region::fromEntity($entity->getRegion());
$product['city'] = City::fromEntity($entity->getCity()); $product['city'] = City::fromEntity($entity->getCity());
@@ -32,6 +32,8 @@ use EP\EpProducts\Domain\Model\Product;
use EP\EpProducts\Domain\Model\Reseller; use EP\EpProducts\Domain\Model\Reseller;
use EP\EpProducts\Domain\Repository\ProductRepository; use EP\EpProducts\Domain\Repository\ProductRepository;
use EP\EpProducts\Domain\Serialization\Date; use EP\EpProducts\Domain\Serialization\Date;
use EP\EpProducts\Domain\Serialization\Hotel as SerializedHotel;
use EP\EpProducts\Domain\Serialization\Product as SerializedProduct;
use EP\EpProducts\Domain\Serialization\Room; use EP\EpProducts\Domain\Serialization\Room;
use EP\EpProducts\Traits\DbConnectionTrait; use EP\EpProducts\Traits\DbConnectionTrait;
use EP\EpProducts\Utility\BookingUrlUtility; use EP\EpProducts\Utility\BookingUrlUtility;
@@ -58,10 +60,11 @@ class ResellerDataService implements SingletonInterface
/** /**
* @param Reseller $reseller * @param Reseller $reseller
* @param array $imageProcessingInstructions * @param array $imageProcessingInstructions
* @param string $type
* @return array * @return array
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*/ */
public function preprocessAll(Reseller $reseller, array $imageProcessingInstructions = null) public function preprocessAll(Reseller $reseller, array $imageProcessingInstructions = null, $type = 'facebook')
{ {
$data = []; $data = [];
$products = $reseller->getProducts(); $products = $reseller->getProducts();
@@ -69,7 +72,12 @@ class ResellerDataService implements SingletonInterface
foreach ($products as $product) foreach ($products as $product)
{ {
/** @var Product $product */ /** @var Product $product */
$data['product'][] = $this->preprocessSingle($product, $reseller, $imageProcessingInstructions); $data['product'][] = $this->preprocessSingle(
$product,
$reseller,
$imageProcessingInstructions,
$type
);
} }
return $data; return $data;
@@ -79,12 +87,28 @@ class ResellerDataService implements SingletonInterface
* @param Product $product * @param Product $product
* @param Reseller $reseller * @param Reseller $reseller
* @param array $imageProcessingInstructions * @param array $imageProcessingInstructions
* @param string $type
* @return array * @return array
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*/ */
public function preprocessSingle(Product $product, Reseller $reseller, array $imageProcessingInstructions = null) public function preprocessSingle(
{ Product $product,
$data = \EP\EpProducts\Domain\Serialization\Product::fromEntity($product, $imageProcessingInstructions); Reseller $reseller,
array $imageProcessingInstructions = null,
$type = 'facebook'
) {
$queryData = $type !== 'google' ? [] : [
'utm_source' => 'google',
'utm_medium' => 'cpc',
'utm_campaign' => 'dynamisches-remarketing',
'utm_content' => $product->getName(),
];
$data = SerializedProduct::fromEntity(
$product,
$imageProcessingInstructions,
$queryData
);
$hotels = $product->getHotels(); $hotels = $product->getHotels();
$paCode = $reseller->getPaCode(); $paCode = $reseller->getPaCode();
@@ -92,7 +116,7 @@ class ResellerDataService implements SingletonInterface
foreach ($hotels as $hotel) foreach ($hotels as $hotel)
{ {
/** @var Hotel $hotel */ /** @var Hotel $hotel */
$hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel); $hotelData = SerializedHotel::fromEntity($hotel);
$dates = $this->productRepository->getDatesForExport($product, $hotel); $dates = $this->productRepository->getDatesForExport($product, $hotel);
$hotelData['dates']['date'] = $this->preprocessDates($dates, $paCode); $hotelData['dates']['date'] = $this->preprocessDates($dates, $paCode);
$data['hotels']['hotel'][] = $hotelData; $data['hotels']['hotel'][] = $hotelData;
@@ -89,16 +89,25 @@ class SerializationUtility
/** /**
* @param string $parameter * @param string $parameter
* @param array $queryData
* @return string * @return string
*/ */
public static function generateLink($parameter) public static function generateLink($parameter, array $queryData = [])
{ {
if (static::$contentObject === null) { if (static::$contentObject === null) {
/** @var ContentObjectRenderer $contentObject */ /** @var ContentObjectRenderer $contentObject */
static::$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); static::$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
} }
return static::$contentObject->typoLink_URL([ 'parameter' => $parameter, 'forceAbsoluteUrl' => true ]); $url = static::$contentObject->typoLink_URL([ 'parameter' => $parameter, 'forceAbsoluteUrl' => true ]);
if ($queryData) {
$query = http_build_query($queryData);
$divider = strpos($url, '?') !== false ? '&' : '?';
$url .= $divider . urlencode($query);
}
return $url;
} }
/** /**