From 121fb90dd78df94c8c6429d085dda524970ab8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Wed, 24 Apr 2019 11:51:40 +0200 Subject: [PATCH] Implement additional export type for Google catalog --- .../Classes/Controller/ResellerController.php | 41 ++++++++++++++----- web/typo3conf/realurl_conf.php | 2 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/web/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php b/web/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php index fdb5776f..ea50b557 100644 --- a/web/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php +++ b/web/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php @@ -34,9 +34,25 @@ use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; +use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException; class ResellerController extends ActionController { + /** + * @var array + */ + protected static $imageDimensions = [ + 'facebook' => [ + 'width' => '1080', + 'maxHeight' => '1080', + 'cropVariant' => 'facebook', + ], + 'google' => [ + 'width' => '1200', + 'maxHeight' => '1200', + 'cropVariant' => 'google', + ] + ]; /** * @var ResellerDataService @@ -99,7 +115,7 @@ class ResellerController extends ActionController $serializer = new Serializer($normalizers, $encoders); - $filename = 'export_' . $reseller->getCode() . '_' . date('Y-m-d') . '.xml'; + $filename = sprintf('export_%s_%s.xml', $reseller->getCode(), date('Y-m-d')); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Description: File Transfer'); @@ -115,13 +131,19 @@ class ResellerController extends ActionController /** * @param Reseller $reseller - * @return bool + * @param string $type + * @throws \Doctrine\DBAL\DBALException + * @throws InvalidArgumentValueException */ - public function csvAction(Reseller $reseller) + public function csvAction(Reseller $reseller, $type = 'facebook') { - $data = $this->resellerDataService->preprocessAll($reseller, [ 'width' => '1080', 'maxHeight' => '1080', 'cropVariant' => 'facebook' ]); + if (!array_key_exists($type, static::$imageDimensions)) { + throw new InvalidArgumentValueException(); + } - $filename = 'export_' . $reseller->getCode() . '_' . date('Y-m-d') . '.csv'; + $data = $this->resellerDataService->preprocessAll($reseller, static::$imageDimensions[$type]); + + $filename = sprintf('export_%s_%s.csv', $reseller->getCode(), date('Y-m-d')); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Description: File Transfer'); @@ -144,15 +166,12 @@ class ResellerController extends ActionController 'brand', ]); - foreach ($data['product'] as $product) - { + foreach ($data['product'] as $product) { $minPrice = 0; $available = 0; - foreach ($product['hotels']['hotel'] as $hotel) - { - foreach ($hotel['dates']['date'] as $date) - { + foreach ($product['hotels']['hotel'] as $hotel) { + foreach ($hotel['dates']['date'] as $date) { if ($minPrice === 0 || $date['minprice'] < $minPrice) { $minPrice = $date['minprice']; } diff --git a/web/typo3conf/realurl_conf.php b/web/typo3conf/realurl_conf.php index d297a395..80c9e569 100644 --- a/web/typo3conf/realurl_conf.php +++ b/web/typo3conf/realurl_conf.php @@ -177,7 +177,7 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = [ 'GETvar' => 'tx_epproducts_reseller[action]', ], [ - 'GETvar' => 'tx_epproducts_reseller[product]', + 'GETvar' => 'tx_epproducts_reseller[type]', ], ], 41 => 'searchresult',