get(); $selection = smarty_function_insert_sections_get_selection(); $menuSectionTree->updateSelection($selection); return $menuSectionTree->getTree(); } function smarty_function_insert_sections_get_time_cached() { $menuSectionTree = ServiceContainer::getService(\KupShop\CatalogBundle\Section\SectionTree::class)->get(); return $menuSectionTree->getTimeCached(); } function smarty_function_insert_sections_get_selection($breadcrumbs = null) { $selection = []; $activeCategory = ServiceContainer::getService(\KupShop\CatalogBundle\Util\ActiveCategory::class); $openedTree = $activeCategory->getOpenedTreePath(); if ($breadcrumbs != null) { $selection = array_values(array_filter(array_map(function ($x) { return getVal('ID', $x); }, $breadcrumbs))); } // nastavit rozevreny strom sekci ulozeny v SESSION elseif ($openedTree != null) { $selection = $openedTree; } $id_cat = $activeCategory->getCategoryId(); if ($id_cat > 0 && end($selection) != $id_cat) { $selection[] = $id_cat; } return $selection; } function smarty_function_insert_sections($params, &$smarty) { $default = [ 'level' => 0, 'level_max' => 99, 'template' => 'block.sections.tpl', 'force' => true, 'skip_cache' => false, 'categories' => smarty_function_insert_sections_get_categories(), 'selection' => smarty_function_insert_sections_get_selection(getVal('breadcrumbs', $params)), 'get_data_function' => 'smarty_function_insert_sections_get_data', ]; $params = array_merge($default, $params); if (!empty($params['skip_cache'])) { $params['force'] = false; } $key_id = '0'; if ($params['level'] > 0) { $sectionList = $params['categories']; $sectionSelection = $params['selection']; for ($i = 0; $i < $params['level']; $i++) { if (empty($sectionSelection[$i])) { return; } if (!isset($sectionList[$sectionSelection[$i]])) { break; } $sectionList = $sectionList[$sectionSelection[$i]]['submenu']; $key_id = $sectionSelection[$i]; } $params['categories'] = $sectionList; } if (empty($params['key'])) { $cacheContext = Contexts::get(CacheContext::class); $params['key'] = implode( '-', [ 'sections', $key_id, $params['template'], $cacheContext->getKey([CacheContext::TYPE_TEXT, CacheContext::TYPE_AVAILABILITY, CacheContext::TYPE_PRICE]), ] ); } $params['file'] = $params['template']; $params['categories'] = array_filter($params['categories'] ?? [], function ($x) { return $x->isVisible(); }); // chci nafetchovat slidery do sekci if ($params['sliders'] ?? false) { $sectionUtil = ServiceContainer::getService(SectionUtil::class); $sectionUtil->fetchSlidersIntoSectionsCache(); } if (!empty($params['assign'])) { $smarty->assign($params['assign'], $params); return ''; } $params['last_updated'] = smarty_function_insert_sections_get_time_cached(); $smarty->loadPlugin('Smarty_function_include_cached'); return smarty_function_include_cached($params, $smarty); } function smarty_function_insert_sections_get_data(&$params) { if (findModule(\Modules::RESTRICTIONS)) { $params['categories'] = ServiceContainer::getService(\KupShop\RestrictionsBundle\Utils\RestrictionUtil::class)->restrictSections($params['categories']); } if (!empty($params['IDpv'])) { $qb = sqlQueryBuilder()->select('s.id') ->from('sections', 's') ->join('s', 'products_in_sections', 'ps', 's.id = ps.id_section') ->join('ps', 'products', 'p', 'p.id = ps.id_product') ->join('p', 'parameters_products', 'pap', 'p.id=pap.id_product AND pap.value_list=:value_list') ->setParameter('value_list', $params['IDpv']); $qb->andWhere((new FilterParams())->getSpec()); $sectionIds = sqlFetchAll($qb, 'id'); SectionUtil::recurseDeleteSections($params['categories'], $sectionIds); } }