Implement additional export type for Google catalog

This commit is contained in:
Björn Fromme
2019-04-24 11:51:40 +02:00
parent f6a8d89a31
commit 121fb90dd7
2 changed files with 31 additions and 12 deletions
@@ -34,9 +34,25 @@ use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Serializer;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException;
class ResellerController extends ActionController 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 * @var ResellerDataService
@@ -99,7 +115,7 @@ class ResellerController extends ActionController
$serializer = new Serializer($normalizers, $encoders); $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('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
@@ -115,13 +131,19 @@ class ResellerController extends ActionController
/** /**
* @param Reseller $reseller * @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('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
@@ -144,15 +166,12 @@ class ResellerController extends ActionController
'brand', 'brand',
]); ]);
foreach ($data['product'] as $product) foreach ($data['product'] as $product) {
{
$minPrice = 0; $minPrice = 0;
$available = 0; $available = 0;
foreach ($product['hotels']['hotel'] as $hotel) foreach ($product['hotels']['hotel'] as $hotel) {
{ foreach ($hotel['dates']['date'] as $date) {
foreach ($hotel['dates']['date'] as $date)
{
if ($minPrice === 0 || $date['minprice'] < $minPrice) { if ($minPrice === 0 || $date['minprice'] < $minPrice) {
$minPrice = $date['minprice']; $minPrice = $date['minprice'];
} }
+1 -1
View File
@@ -177,7 +177,7 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = [
'GETvar' => 'tx_epproducts_reseller[action]', 'GETvar' => 'tx_epproducts_reseller[action]',
], ],
[ [
'GETvar' => 'tx_epproducts_reseller[product]', 'GETvar' => 'tx_epproducts_reseller[type]',
], ],
], ],
41 => 'searchresult', 41 => 'searchresult',