106 lines
3.6 KiB
PHP
106 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace KupShop\WatchdogBundle\View;
|
|
|
|
use KupShop\CatalogBundle\ProductList\ProductCollection;
|
|
use KupShop\CatalogBundle\ProductList\ProductList;
|
|
use KupShop\CatalogBundle\Util\ActiveCategory;
|
|
use KupShop\CatalogBundle\View\CategoryView;
|
|
use KupShop\ComponentsBundle\View\ComponentsViewInterface;
|
|
use KupShop\ComponentsBundle\View\ComponentsViewTrait;
|
|
use KupShop\KupShopBundle\Context\UserContext;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use KupShop\KupShopBundle\Views\Traits\SecurityTrait;
|
|
use Query\QueryBuilder;
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class WatchdogView extends CategoryView implements ComponentsViewInterface
|
|
{
|
|
use SecurityTrait;
|
|
use ComponentsViewTrait;
|
|
|
|
protected string $smartyFallback = 'account';
|
|
protected $template = 'category.watchdog.tpl';
|
|
protected string $entrypoint = 'account';
|
|
|
|
public function __construct(EventDispatcherInterface $dispatcher, ProductList $productList, ActiveCategory $activeCategory)
|
|
{
|
|
parent::__construct($dispatcher, $productList, $activeCategory);
|
|
$this->proxyCacheEnabled = false;
|
|
$this->requirements = ['logged_user' => true];
|
|
}
|
|
|
|
public function getResponse(?Request $request = null)
|
|
{
|
|
$this->checkRequirements();
|
|
|
|
return parent::getResponse($request);
|
|
}
|
|
|
|
public function getBreadcrumbs()
|
|
{
|
|
return getReturnNavigation(-1, 'USER', [translate('title', 'category')['watchdog']]);
|
|
}
|
|
|
|
public function getBodyVariables()
|
|
{
|
|
return array_merge_recursive(
|
|
parent::getBodyVariables(),
|
|
['category' => ['is_watchdog' => true]]
|
|
);
|
|
}
|
|
|
|
public function getTitleParams()
|
|
{
|
|
return [translate('title', 'category')['watchdog']];
|
|
}
|
|
|
|
public function getMetaTitle()
|
|
{
|
|
return translate('title', 'category')['watchdog'];
|
|
}
|
|
|
|
protected function createProductList()
|
|
{
|
|
return $this->doCreateProductList(true);
|
|
}
|
|
|
|
protected function prepareFilterParams()
|
|
{
|
|
$this->filterParams = $this->productList->applyDefaultFilterParams();
|
|
$this->filterParams->setResultEntity(\FilterParams::ENTITY_VARIATION);
|
|
$this->filterParams->setInStore(null);
|
|
$this->filterParams->andSpec(function (QueryBuilder $qb) {
|
|
$qb->joinVariationsOnProducts();
|
|
|
|
$qb->addSelect('pw.availability as watchdog_availability, pw.price as watchdog_price')
|
|
->join('pv', 'products_watchdog', 'pw',
|
|
'p.id = pw.id_product
|
|
AND (pv.id <=> pw.id_variation OR pw.id_variation is null)
|
|
AND (pw.id_user = :id_user)'
|
|
);
|
|
$qb->groupBy('pw.id_product, pw.id_variation');
|
|
|
|
$qb->setParameter('id_user', Contexts::get(UserContext::class)->getActiveId());
|
|
});
|
|
|
|
$this->productList->addResultModifiers(function (ProductCollection $products, array $data) {
|
|
foreach ($products as $productId => $product) {
|
|
// do sablony poslu informace o hlidani produktu - jestli ma hlidanou dostupnost nebo cenu
|
|
$products[$productId]->watchdogPrice = !empty($data[$productId]['watchdog_price']) ? toDecimal($data[$productId]['watchdog_price']) : null;
|
|
$products[$productId]->watchdogAvailability = $data[$productId]['watchdog_availability'] ?? 1;
|
|
}
|
|
});
|
|
}
|
|
|
|
public function getTemplate()
|
|
{
|
|
if (findModule(\Modules::COMPONENTS)) {
|
|
return 'view/watchdogView.html.twig';
|
|
}
|
|
|
|
return parent::getTemplate();
|
|
}
|
|
}
|