Check availability of alternative product when linked

This commit is contained in:
Björn Fromme
2018-08-16 11:41:22 +02:00
parent 004de7cf9d
commit ad70bd3aae
3 changed files with 45 additions and 9 deletions
@@ -30,6 +30,7 @@ namespace EP\EpProducts\Controller;
use EP\EpProducts\Domain\Model\FilterSettings;
use EP\EpProducts\Domain\Model\Hotel;
use EP\EpProducts\Domain\Model\Product;
use EP\EpProducts\Domain\Repository\ProductRepository;
use EP\EpProducts\Service\DateService;
use EP\EpProducts\Service\FilterService;
use EP\EpProducts\Service\ResellerService;
@@ -56,17 +57,30 @@ class AjaxDateController extends ActionController
*/
protected $resellerService;
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @param FilterService $filterService
* @param DateService $dateService
* @param ResellerService $resellerService
* @param ProductRepository $productRepository
*/
public function __construct(FilterService $filterService, DateService $dateService, ResellerService $resellerService)
public function __construct
(
FilterService $filterService,
DateService $dateService,
ResellerService $resellerService,
ProductRepository $productRepository
)
{
parent::__construct();
$this->filterService = $filterService;
$this->dateService = $dateService;
$this->resellerService = $resellerService;
$this->productRepository = $productRepository;
}
public function initializeAction()
@@ -100,13 +114,15 @@ class AjaxDateController extends ActionController
$altLabel = null;
if ($product->getAltProduct()) {
$altProduct = $product->getAltProduct();
$altProductLink = $this->uriBuilder
->reset()
->setTargetPageUid($altProduct->getDetailPage())
->setCreateAbsoluteUri(true)
->build()
;
$altLabel = $product->getAltLabel();
if ($this->productRepository->hasDates($altProduct)) {
$altProductLink = $this->uriBuilder
->reset()
->setTargetPageUid($altProduct->getDetailPage())
->setCreateAbsoluteUri(true)
->build()
;
$altLabel = $product->getAltLabel();
}
}
if ($reseller = $this->resellerService->getResellerForCurrentDomain()) {
$paCode = $reseller['paCode'];
@@ -225,7 +225,6 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements
/**
* @var \EP\EpProducts\Domain\Model\Product
* @lazy
*/
protected $altProduct;
@@ -241,6 +241,27 @@ class ProductRepository extends AbstractRepository
return $query->execute()->fetchAll();
}
/**
* @param Product $product
* @return bool
*/
public function hasDates(Product $product)
{
$qb = DbUtility::getDbConnection()->createQueryBuilder();
$query = $qb
->select('date.uid')
->from('tx_epproducts_domain_model_date', 'date')
->where('date.product = :product')
->setParameter('product', $product->getUid())
->setMaxResults(1)
->execute()
->fetchColumn()
;
return $query !== false;
}
/**
* @param Product $product
* @param Hotel $hotel