toggleText = $this->translator->trans('recommender.show', [], 'products'); } #[PostMount] public function postMount(): void { $this->defaultLimit = $this->limit; } public function __invoke(Request $request): ?Response { $data = json_decode($this->getRecommender()['data'] ?? '', true); $cache = intval($data['cache'] ?? 3600); if ($cache > 0) { return $this->createResponse($request, $cache); } return null; } #[PreMount] public function preMount(array $data): array { if ($id_product = ($data['id_product'] ?? null)) { $data['data']['product'] = $id_product; unset($data['id_product']); } if ($id_category = ($data['id_category'] ?? null)) { $data['data']['section'] = (array) $id_category; unset($data['id_category']); } return $data; } public function getRecommender(): array { if (!isset($this->recommender)) { $this->recommender = $this->recommendersUtil->getRecommenderByLabel($this->label) ?: []; } return $this->recommender; } public function getDataRecommender() { return json_encode([ 'label' => $this->label, 'data' => $this->data, ]); } public function getCount(): ?int { if ($this->lazy) { return null; } return $this->getProductList()->count(); } public function getProductList(): ?ProductCollection { if ($this->lazy) { return null; } if (!isset($this->productList)) { $data = ['label' => $this->label, 'data' => $this->data, 'count' => $this->limit]; $this->productList = $this->recommendersUtil->getRecommendersProducts($data); } return $this->productList; } #[LiveListener('recommenderLoad')] public function load() { $this->lazy = false; } public function initMicrodata(): array { // Aby to mělo svůj scope return [MicrodataProvider::RECOMMENDER => []]; } #[LiveAction] public function toggleAction(): void { if ($this->isHidden) { $this->toggleText = $this->translator->trans('recommender.hide', [], 'products'); $this->isHidden = false; $this->limit = 100; } else { $this->toggleText = $this->translator->trans('recommender.show', [], 'products'); $this->isHidden = true; $this->limit = $this->defaultLimit; } } public function getGTMPlaceholders(): array { return ['item_list_name' => 'recommender', 'item_list_id' => $this->getRecommender()['id'] ?? '']; } public function getTrackingData(): string { if ($this->getProductList()) { return htmlentities(json_encode($this->gtmClass->getPushData($this))); } return ''; } public static function getSelectValues(): array { return sqlQueryBuilder() ->select('position, label') ->from('recommenders') ->execute() ->fetchAllKeyValue(); } }