From ad70bd3aaeef56e844e19964d085eeebab5f5c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Thu, 16 Aug 2018 11:41:22 +0200 Subject: [PATCH] Check availability of alternative product when linked --- .../Classes/Controller/AjaxDateController.php | 32 ++++++++++++++----- .../Classes/Domain/Model/Product.php | 1 - .../Domain/Repository/ProductRepository.php | 21 ++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/web/typo3conf/ext/ep_products/Classes/Controller/AjaxDateController.php b/web/typo3conf/ext/ep_products/Classes/Controller/AjaxDateController.php index 652f199f..2796d69b 100644 --- a/web/typo3conf/ext/ep_products/Classes/Controller/AjaxDateController.php +++ b/web/typo3conf/ext/ep_products/Classes/Controller/AjaxDateController.php @@ -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']; diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php b/web/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php index 88b78285..6b100be9 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php @@ -225,7 +225,6 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements /** * @var \EP\EpProducts\Domain\Model\Product - * @lazy */ protected $altProduct; diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php index 8298b885..d142dd2e 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php @@ -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