Add partnercode, fix booking urls in xml export

This commit is contained in:
Björn Fromme
2018-07-10 12:57:03 +02:00
parent e1fd3096f5
commit 5abde23ff8
7 changed files with 71 additions and 25 deletions
@@ -88,7 +88,7 @@ class ResellerController extends ActionController
$this->redirect('list', null, null, [ 'reseller' => $reseller ]);
}
$data = $this->resellerService->preprocessSingle($product);
$data = $this->resellerService->preprocessSingle($product, $reseller);
var_dump($data);
return false;
@@ -102,7 +102,7 @@ class ResellerController extends ActionController
{
$products = $reseller->getProducts();
$data = $this->resellerService->preprocessAll($products);
$data = $this->resellerService->preprocessAll($reseller);
$encoders = [new XmlEncoder('products')];
$normalizers = [new ObjectNormalizer()];
@@ -42,6 +42,11 @@ class Reseller extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $code;
/**
* @var string
*/
protected $paCode;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\EP\EpProducts\Domain\Model\Product>
*/
@@ -84,6 +89,22 @@ class Reseller extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
$this->code = $code;
}
/**
* @return string
*/
public function getPaCode()
{
return $this->paCode;
}
/**
* @param string $paCode
*/
public function setPaCode($paCode)
{
$this->paCode = $paCode;
}
/**
* @return ObjectStorage
*/
@@ -29,6 +29,7 @@ namespace EP\EpProducts\Service;
use EP\EpProducts\Domain\Model\Hotel;
use EP\EpProducts\Domain\Model\Product;
use EP\EpProducts\Domain\Model\Reseller;
use EP\EpProducts\Domain\Repository\ProductRepository;
use EP\EpProducts\Domain\Serialization\Date;
use EP\EpProducts\Domain\Serialization\Room;
@@ -52,17 +53,18 @@ class ResellerService implements SingletonInterface
}
/**
* @param ObjectStorage $products
* @param Reseller $reseller
* @return array
*/
public function preprocessAll(ObjectStorage $products)
public function preprocessAll(Reseller $reseller)
{
$data = [];
$products = $reseller->getProducts();
foreach ($products as $product)
{
/** @var Product $product */
$data['product'][] = $this->preprocessSingle($product);
$data['product'][] = $this->preprocessSingle($product, $reseller);
}
return $data;
@@ -70,20 +72,22 @@ class ResellerService implements SingletonInterface
/**
* @param Product $product
* @param Reseller $reseller
* @return \EP\EpProducts\Domain\Serialization\Product
*/
public function preprocessSingle(Product $product)
public function preprocessSingle(Product $product, Reseller $reseller)
{
$data = \EP\EpProducts\Domain\Serialization\Product::fromEntity($product);
$hotels = $product->getHotels();
$paCode = $reseller->getPaCode();
foreach ($hotels as $hotel)
{
/** @var Hotel $hotel */
$hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel);
$dates = $this->productRepository->getDatesForExport($product, $hotel);
$hotelData->dates['date'] = $this->preprocessDates($dates);
$hotelData->dates['date'] = $this->preprocessDates($dates, $paCode);
$data->hotels['hotel'][] = $hotelData;
}
@@ -92,9 +96,10 @@ class ResellerService implements SingletonInterface
/**
* @param array $dates
* @param string $paCode
* @return array
*/
public function preprocessDates(array $dates)
public function preprocessDates(array $dates, $paCode = null)
{
$data = [];
@@ -108,7 +113,9 @@ class ResellerService implements SingletonInterface
$date->bookingurl = BookingUrlUtility::generateUrl(
$row['dateBusProId'],
$row['hotelBusProId'],
$row['dateEnd']
$row['dateEnd'],
'base',
$paCode
);
$date->rooms['room'][] = Room::fromArray($row);
@@ -41,9 +41,10 @@ class BookingUrlUtility
* @param int $hotelId
* @param string $dateEnd
* @param string $template
* @param string $paCode
* @return string
*/
public static function generateUrl($bookingId, $hotelId, $dateEnd, $template = 'base')
public static function generateUrl($bookingId, $hotelId, $dateEnd, $template = 'base', $paCode = null)
{
$query = [
'id' => $bookingId,
@@ -58,20 +59,24 @@ class BookingUrlUtility
$query['templatezusatz'] = '_' . $template;
}
$cookie = $_COOKIE[static::COOKIE_NAME];
if (strpos($cookie, '?') !== false) {
$items = GeneralUtility::trimExplode('?', $cookie);
$cookie = $items[0];
}
$bpnCookie = $_COOKIE[static::COOKIE_NAME_BPN];
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;
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;
}
}
}
@@ -23,10 +23,10 @@ return [
'iconfile' => 'EXT:ep_products/Resources/Public/Icons/tx_epproducts_domain_model_reseller.gif'
],
'interface' => [
'showRecordFieldList' => 'name,code,products',
'showRecordFieldList' => 'name,code,pa_code,products',
],
'types' => [
'1' => ['showitem' => 'name, code, products'],
'1' => ['showitem' => 'name, code, pa_code, products'],
],
'palettes' => [],
'columns' => [
@@ -132,6 +132,15 @@ return [
'eval' => 'trim,required'
],
],
'pa_code' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_products/Resources/Private/Language/locallang.xlf:tx_epproducts_domain_model_reseller.pa_code',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
],
],
'products' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_products/Resources/Private/Language/locallang.xlf:tx_epproducts_domain_model_reseller.products',
@@ -598,6 +598,9 @@
<trans-unit id="tx_epproducts_domain_model_reseller.code">
<source>Code</source>
</trans-unit>
<trans-unit id="tx_epproducts_domain_model_reseller.pa_code">
<source>PA-Code</source>
</trans-unit>
<trans-unit id="tx_epproducts_domain_model_reseller.products">
<source>Produkte</source>
</trans-unit>
@@ -1075,6 +1075,7 @@ CREATE TABLE tx_epproducts_domain_model_reseller (
name varchar(255) DEFAULT '' NOT NULL,
code varchar(255) DEFAULT '' NOT NULL,
pa_code varchar(255) DEFAULT '' NOT NULL,
products int(11) unsigned DEFAULT '0' NOT NULL,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,