function content_55ccf2ea85b705_19170918($_smarty_tpl) { if (!is_callable('smarty_function_set_id')) { include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.set_id.php'; } if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] == "Y" && @constant('AREA') == "C") { $_smarty_tpl->_capture_stack[0][] = array("template_content", null, null); ob_start(); ?> <li class="ty-product-filters__group"> <?php if (!$_smarty_tpl->tpl_vars['range']->value['checked']) { ?> <?php $_smarty_tpl->tpl_vars["filter_query_elm"] = new Smarty_variable(fn_add_range_to_url_hash($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); ?> <?php } else { ?> <?php $_smarty_tpl->tpl_vars["filter_query_elm"] = new Smarty_variable(fn_delete_range_from_url($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); ?> <?php } ?> <?php if ($_REQUEST['features_hash']) { ?> <?php $_smarty_tpl->tpl_vars["cur_features_hash"] = new Smarty_variable("&features_hash=" . (string) $_REQUEST['features_hash'], null, 0); ?> <?php } ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] == "E" && (!$_smarty_tpl->tpl_vars['filter']->value['simple_link'] || $_smarty_tpl->tpl_vars['filter']->value['selected_ranges'] && $_smarty_tpl->tpl_vars['controller']->value == "product_features")) { ?> <?php $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url("product_features.view?variant_id=" . (string) $_smarty_tpl->tpl_vars['range']->value['range_id'] . (string) $_smarty_tpl->tpl_vars['cur_features_hash']->value), null, 0); ?> <?php } else { ?> <?php $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url(fn_link_attach($_smarty_tpl->tpl_vars['filter_qstring']->value, "features_hash=" . (string) $_smarty_tpl->tpl_vars['filter_query_elm']->value)), null, 0); ?> <?php } ?> <?php $_smarty_tpl->tpl_vars["use_ajax"] = new Smarty_variable(fn_compare_dispatch($_smarty_tpl->tpl_vars['href']->value, $_smarty_tpl->tpl_vars['config']->value['current_url']), null, 0); ?> <a <?php if (!$_smarty_tpl->tpl_vars['range']->value['disabled'] || $_smarty_tpl->tpl_vars['range']->value['checked']) { ?> href="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['href']->value, ENT_QUOTES, 'UTF-8'); ?> "<?php } ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] != "E") { ?> rel="nofollow"<?php } ?> class="ty-product-filters__item<?php if ($_smarty_tpl->tpl_vars['range']->value['checked']) { ?> checked<?php } if ($_smarty_tpl->tpl_vars['range']->value['disabled']) { ?> disabled<?php } elseif ($_smarty_tpl->tpl_vars['allow_ajax']->value && $_smarty_tpl->tpl_vars['use_ajax']->value) { ?> cm-history<?php } ?> " data-ca-scroll=".cm-pagination-container" data-ca-target-id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['ajax_div_ids']->value, ENT_QUOTES, 'UTF-8'); ?> "><span class="ty-filter-icon"><i class="ty-icon-ok ty-filter-icon__check"></i><i class="ty-icon-cancel ty-filter-icon__delete"></i></span><?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['prefix'], ENT_QUOTES, 'UTF-8'); echo htmlspecialchars(fn_text_placeholders($_smarty_tpl->tpl_vars['range']->value['range_name']), ENT_QUOTES, 'UTF-8'); echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['suffix'], ENT_QUOTES, 'UTF-8'); ?> <?php if (!$_smarty_tpl->tpl_vars['range']->value['disabled']) { ?> <span class="ty-product-filters__count"> (<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['range']->value['products'], ENT_QUOTES, 'UTF-8'); ?> )</span><?php } ?> </a> </li> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } if (trim(Smarty::$_smarty_vars['capture']['template_content'])) { if ($_smarty_tpl->tpl_vars['auth']->value['area'] == "A") { ?> <span class="cm-template-box template-box" data-ca-te-template="blocks/product_filters/components/variant_item.tpl" id="<?php echo smarty_function_set_id(array('name' => "blocks/product_filters/components/variant_item.tpl"), $_smarty_tpl); ?> "><div class="cm-template-icon icon-edit ty-icon-edit hidden"></div><?php echo Smarty::$_smarty_vars['capture']['template_content']; ?> <!--[/tpl_id]--></span><?php } else { echo Smarty::$_smarty_vars['capture']['template_content']; } } } else { ?> <li class="ty-product-filters__group"> <?php if (!$_smarty_tpl->tpl_vars['range']->value['checked']) { ?> <?php $_smarty_tpl->tpl_vars["filter_query_elm"] = new Smarty_variable(fn_add_range_to_url_hash($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); ?> <?php } else { ?> <?php $_smarty_tpl->tpl_vars["filter_query_elm"] = new Smarty_variable(fn_delete_range_from_url($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); ?> <?php } ?> <?php if ($_REQUEST['features_hash']) { ?> <?php $_smarty_tpl->tpl_vars["cur_features_hash"] = new Smarty_variable("&features_hash=" . (string) $_REQUEST['features_hash'], null, 0); ?> <?php } ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] == "E" && (!$_smarty_tpl->tpl_vars['filter']->value['simple_link'] || $_smarty_tpl->tpl_vars['filter']->value['selected_ranges'] && $_smarty_tpl->tpl_vars['controller']->value == "product_features")) { ?> <?php $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url("product_features.view?variant_id=" . (string) $_smarty_tpl->tpl_vars['range']->value['range_id'] . (string) $_smarty_tpl->tpl_vars['cur_features_hash']->value), null, 0); ?> <?php } else { ?> <?php $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url(fn_link_attach($_smarty_tpl->tpl_vars['filter_qstring']->value, "features_hash=" . (string) $_smarty_tpl->tpl_vars['filter_query_elm']->value)), null, 0); ?> <?php } ?> <?php $_smarty_tpl->tpl_vars["use_ajax"] = new Smarty_variable(fn_compare_dispatch($_smarty_tpl->tpl_vars['href']->value, $_smarty_tpl->tpl_vars['config']->value['current_url']), null, 0); ?> <a <?php if (!$_smarty_tpl->tpl_vars['range']->value['disabled'] || $_smarty_tpl->tpl_vars['range']->value['checked']) { ?> href="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['href']->value, ENT_QUOTES, 'UTF-8'); ?> "<?php } ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] != "E") { ?> rel="nofollow"<?php } ?> class="ty-product-filters__item<?php if ($_smarty_tpl->tpl_vars['range']->value['checked']) { ?> checked<?php } if ($_smarty_tpl->tpl_vars['range']->value['disabled']) { ?> disabled<?php } elseif ($_smarty_tpl->tpl_vars['allow_ajax']->value && $_smarty_tpl->tpl_vars['use_ajax']->value) { ?> cm-history<?php } ?> " data-ca-scroll=".cm-pagination-container" data-ca-target-id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['ajax_div_ids']->value, ENT_QUOTES, 'UTF-8'); ?> "><span class="ty-filter-icon"><i class="ty-icon-ok ty-filter-icon__check"></i><i class="ty-icon-cancel ty-filter-icon__delete"></i></span><?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['prefix'], ENT_QUOTES, 'UTF-8'); echo htmlspecialchars(fn_text_placeholders($_smarty_tpl->tpl_vars['range']->value['range_name']), ENT_QUOTES, 'UTF-8'); echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['suffix'], ENT_QUOTES, 'UTF-8'); ?> <?php if (!$_smarty_tpl->tpl_vars['range']->value['disabled']) { ?> <span class="ty-product-filters__count"> (<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['range']->value['products'], ENT_QUOTES, 'UTF-8'); ?> )</span><?php } ?> </a> </li> <?php } }
function fn_get_filters_products_count($params = array()) { $key = 'pfilters_' . md5(serialize($params)); Registry::register_cache($key, array('products', 'product_features', 'product_filters', 'product_features_values'), CACHE_LEVEL_USER); if (Registry::is_exist($key) == false) { if (!empty($params['check_location'])) { // FIXME: this is bad style, should be refactored $valid_locations = array('index.index', 'products.search', 'categories.view', 'product_features.view'); if (!in_array($params['dispatch'], $valid_locations)) { return array(); } if ($params['dispatch'] == 'categories.view') { $params['simple_link'] = true; // this parameter means that extended filters on this page should be displayed as simple $params['filter_custom_advanced'] = true; // this parameter means that extended filtering should be stayed on the same page } else { if ($params['dispatch'] == 'product_features.view') { $params['simple_link'] = true; $params['features_hash'] = (!empty($params['features_hash']) ? $params['features_hash'] . '.' : '') . 'V' . $params['variant_id']; //$params['exclude_feature_id'] = db_get_field("SELECT feature_id FROM ?:product_features_values WHERE variant_id = ?i", $params['variant_id']); } $params['get_for_home'] = 'Y'; } } if (!empty($params['skip_if_advanced']) && !empty($params['advanced_filter']) && $params['advanced_filter'] == 'Y') { return array(); } // Base fields for the SELECT queries $values_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_features_values.variant_id as range_id', '?:product_feature_variant_descriptions.variant as range_name', '?:product_features.feature_type', '?:product_filters.filter_id'); $ranges_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_filter_ranges.range_id', '?:product_filter_ranges_descriptions.range_name', '?:product_filter_ranges.filter_id', '?:product_features.feature_type'); $condition = $where = $join = $filter_vq = $filter_rq = ''; $variants_ids = $ranges_ids = $field_filters = $feature_ids = $field_ranges_ids = $field_ranges_counts = array(); if (!empty($params['features_hash'])) { list($variants_ids, $ranges_ids, $_field_ranges_ids) = fn_parse_features_hash($params['features_hash']); $field_ranges_ids = array_flip($_field_ranges_ids); } if (!empty($params['category_id'])) { $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $params['category_id']); $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE id_path LIKE ?l", $id_path . '/%'); $category_ids[] = $params['category_id']; $condition .= db_quote(" AND (categories_path = '' OR FIND_IN_SET(?i, categories_path))", $params['category_id']); $where .= db_quote(" AND ?:products_categories.category_id IN (?n)", $category_ids); } elseif (empty($params['get_for_home']) && empty($params['get_custom'])) { $condition .= " AND categories_path = ''"; } if (!empty($params['filter_id'])) { $condition .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']); } if (!empty($params['get_for_home'])) { $condition .= db_quote(" AND ?:product_filters.show_on_home_page = ?s", $params['get_for_home']); } if (!empty($params['exclude_feature_id'])) { $condition .= db_quote(" AND ?:product_filters.feature_id NOT IN (?n)", $params['exclude_feature_id']); } $filters = db_get_hash_array("SELECT ?:product_filters.feature_id, ?:product_filters.filter_id, ?:product_filters.field_type, ?:product_filter_descriptions.filter, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix FROM ?:product_filters LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id AND ?:product_filter_descriptions.lang_code = ?s LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s WHERE ?:product_filters.status = 'A' ?p ORDER by position", 'filter_id', CART_LANGUAGE, CART_LANGUAGE, $condition); $fields = fn_get_product_filter_fields(); if (empty($filters) && empty($params['advanced_filter'])) { return array(array(), false); } else { foreach ($filters as $k => $v) { if (!empty($v['feature_id'])) { // Feature filters $feature_ids[] = $v['feature_id']; } else { // Product field filters $_field = $fields[$v['field_type']]; $field_filters[$v['filter_id']] = array_merge($v, $_field); $filters[$k]['condition_type'] = $_field['condition_type']; } } } // Variants if (!empty($variants_ids)) { $join .= " LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS simple_variants FROM ?:product_features_values WHERE lang_code = '" . CART_LANGUAGE . "' GROUP BY product_id) AS pfv_simple ON pfv_simple.product_id = ?:products.product_id"; $where_condtions = array(); foreach ($variants_ids as $k => $variant_id) { $where_condtions[] = db_quote(" FIND_IN_SET('?i', simple_variants)", $variant_id); } $where .= ' AND ' . implode(' AND ', $where_condtions); } // Ranges if (!empty($ranges_ids)) { $range_conditions = db_get_array("SELECT `from`, `to`, feature_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", $ranges_ids); foreach ($range_conditions as $k => $condition) { $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = ?:products.product_id AND var_val_{$k}.lang_code = ?s", CART_LANGUAGE); $where .= db_quote(" AND (var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $condition['from'], $condition['to'], $condition['feature_id']); } } if (!empty($params['filter_id']) && empty($params['view_all'])) { $filter_vq .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']); $filter_rq .= db_quote(" AND ?:product_filter_ranges.filter_id = ?i", $params['filter_id']); } if (!empty($params['view_all'])) { $values_fields[] = "UPPER(SUBSTRING(?:product_feature_variant_descriptions.variant, 1, 1)) AS `index`"; } $_join = $join; // Build condition for the standart fields if (!empty($_field_ranges_ids)) { foreach ($_field_ranges_ids as $rid => $field_type) { $structure = $fields[$field_type]; if ($structure['table'] !== 'products' && strpos($join, 'JOIN ?:' . $structure['table']) === false) { $join .= " LEFT JOIN ?:{$structure['table']} ON ?:{$structure['table']}.product_id = ?:products.product_id"; } if ($structure['condition_type'] == 'D') { $range_condition = db_get_row("SELECT `from`, `to` FROM ?:product_filter_ranges WHERE range_id = ?i", $rid); if (!empty($range_condition)) { $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} >= ?i AND ?:{$structure['table']}.{$structure['db_field']} <= ?i", $range_condition['from'], $range_condition['to']); } } elseif ($structure['condition_type'] == 'F') { $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?i", $rid); } elseif ($structure['condition_type'] == 'C') { $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?s", $rid == 1 ? 'Y' : 'N'); } if (!empty($structure['join_params'])) { foreach ($structure['join_params'] as $field => $param) { $join .= db_quote(" AND ?:{$structure['table']}.{$field} = ?s ", $param); } } } } // Product availability conditions $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:categories.usergroup_ids', true) . ')'; $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:products.usergroup_ids', true) . ')'; $where .= db_quote(" AND ?:categories.status IN (?a) AND ?:products.status IN (?a)", array('A', 'H'), array('A')); $_j = " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id"; if (Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') { $_j .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id"; $where .= " AND IF(?:products.tracking = 'O', inventory.amount > 0, ?:products.amount > 0)"; } $_join .= $_j; $join .= $_j; // Localization $where .= fn_get_localizations_condition('?:products.localization', true); $where .= fn_get_localizations_condition('?:categories.localization', true); $variants_counts = db_get_hash_multi_array("SELECT " . implode(', ', $values_fields) . " FROM ?:product_features_values LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filters ON ?:product_filters.feature_id = ?:product_features_values.feature_id LEFT JOIN ?:product_feature_variants ON ?:product_feature_variants.variant_id = ?:product_features_values.variant_id LEFT JOIN ?:product_feature_variant_descriptions ON ?:product_feature_variant_descriptions.variant_id = ?:product_feature_variants.variant_id AND ?:product_feature_variant_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s AND ?:product_features_values.variant_id ?p ?p AND ?:product_features.feature_type IN ('S', 'M', 'E') GROUP BY ?:product_features_values.variant_id ORDER BY ?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant", array('filter_id', 'range_id'), CART_LANGUAGE, $join, $feature_ids, CART_LANGUAGE, $where, $filter_vq); $ranges_counts = db_get_hash_multi_array("SELECT " . implode(', ', $ranges_fields) . " FROM ?:product_filter_ranges LEFT JOIN ?:product_features_values ON ?:product_features_values.feature_id = ?:product_filter_ranges.feature_id AND ?:product_features_values.value_int >= ?:product_filter_ranges.from AND ?:product_features_values.value_int <= ?:product_filter_ranges.to LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filter_ranges.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s ?p ?p GROUP BY ?:product_filter_ranges.range_id ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", array('filter_id', 'range_id'), CART_LANGUAGE, $join, $feature_ids, CART_LANGUAGE, $where, $filter_rq); if (!empty($field_filters)) { // Field ranges foreach ($field_filters as $filter_id => $field) { $fields_join = $fields_where = ''; // Dinamic ranges (price, amount etc) if ($field['condition_type'] == 'D') { $fields_join = " LEFT JOIN ?:{$field['table']} ON ?:{$field['table']}.{$field['db_field']} >= ?:product_filter_ranges.from AND ?:{$field['table']}.{$field['db_field']} <= ?:product_filter_ranges.to "; if (strpos($fields_join . $_join, 'JOIN ?:products ') === false) { $fields_join .= db_quote(" LEFT JOIN ?:products ON ?:products.product_id = ?:product_prices.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids'])); } elseif (strpos($fields_join . $_join, 'JOIN ?:product_prices ') === false) { $fields_join .= " LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id"; } if ($field['table'] == 'product_prices') { $fields_join .= db_quote(" LEFT JOIN ?:product_prices as prices_2 ON ?:product_prices.product_id = prices_2.product_id AND ?:product_prices.price > prices_2.price AND prices_2.lower_limit = 1 AND prices_2.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids'])); $fields_where .= " AND prices_2.price IS NULL"; } $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:product_filter_ranges.range_id, ?:product_filter_ranges_descriptions.range_name, ?:product_filter_ranges.filter_id FROM ?:product_filter_ranges LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s ?p WHERE ?:products.status IN ('A') AND ?:product_filter_ranges.filter_id = ?i ?p GROUP BY ?:product_filter_ranges.range_id HAVING products != 0 ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", 'range_id', CART_LANGUAGE, $fields_join . $_join, $filter_id, $where . $fields_where); // Char values (free shipping etc) } elseif ($field['condition_type'] == 'C') { $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['table']}.{$field['db_field']} as range_name FROM ?:{$field['table']} ?p WHERE ?:products.status = 'A' ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_name', $join, $where); if (!empty($field_ranges_counts[$filter_id])) { foreach ($field_ranges_counts[$filter_id] as $range_key => $range) { $field_ranges_counts[$filter_id][$range_key]['range_name'] = $field['variant_descriptions'][$range['range_name']]; $field_ranges_counts[$filter_id][$range_key]['range_id'] = $range['range_name'] == 'Y' ? 1 : 0; } } // Fixed values (supplier etc) } elseif ($field['condition_type'] == 'F') { $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['foreign_table']}.{$field['range_name']} as range_name, ?:{$field['foreign_table']}.{$field['foreign_index']} as range_id FROM ?:{$field['table']} LEFT JOIN ?:{$field['foreign_table']} ON ?:{$field['foreign_table']}.{$field['foreign_index']} = ?:{$field['table']}.{$field['db_field']} ?p WHERE ?:products.status IN ('A') ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_id', $join, $where); } } } $merged = fn_array_merge($variants_counts, $ranges_counts, $field_ranges_counts); $view_all = array(); foreach ($filters as $filter_id => $filter) { if (!empty($merged[$filter_id]) && empty($params['view_all']) || !empty($params['filter_id']) && $params['filter_id'] != $filter_id) { // Check if filter range was selected if (empty($filters[$filter_id]['feature_id'])) { $intersect = array_intersect(array_keys($merged[$filter_id]), $field_ranges_ids); } else { $intersect = array_intersect(array_keys($merged[$filter_id]), $variants_ids); } if (!empty($intersect)) { foreach ($merged[$filter_id] as $k => $v) { if (!in_array($v['range_id'], $intersect)) { // Unset unselected ranges unset($merged[$filter_id][$k]); } } } // Calculate number of ranges and compare with constant $count = count($merged[$filter_id]); if ($count > FILTERS_RANGES_MORE_COUNT && empty($params['get_all'])) { $merged[$filter_id] = array_slice($merged[$filter_id], 0, FILTERS_RANGES_MORE_COUNT, true); $filters[$filter_id]['more_cut'] = true; } $filters[$filter_id]['ranges'] =& $merged[$filter_id]; // Add feature type to the filter $_first = reset($merged[$filter_id]); if (!empty($_first['feature_type'])) { $filters[$filter_id]['feature_type'] = $_first['feature_type']; } if (!empty($params['simple_link']) && $filters[$filter_id]['feature_type'] == 'E') { $filters[$filter_id]['simple_link'] = true; } if (empty($params['skip_other_variants'])) { foreach ($filters[$filter_id]['ranges'] as $_k => $r) { if (!fn_check_selected_filter($r['range_id'], !empty($r['feature_type']) ? $r['feature_type'] : '', $params, $filters[$filter_id]['field_type'])) { // selected variant $filters[$filter_id]['ranges'] = array($_k => $r); $filters[$filter_id]['ranges'][$_k]['selected'] = true; // mark selected variant // Get other variants $_params = $params; $_params['filter_id'] = $filter_id; $_params['req_range_id'] = $r['range_id']; $_params['features_hash'] = fn_delete_range_from_url($params['features_hash'], $r, $filters[$filter_id]['field_type']); $_params['skip_other_variants'] = true; unset($_params['variant_id'], $_params['check_location']); list($_f) = fn_get_filters_products_count($_params); if (!empty($_f)) { $_f = reset($_f); // delete current range foreach ($_f['ranges'] as $_rid => $_rv) { if ($_rv['range_id'] == $r['range_id']) { unset($_f['ranges'][$_rid]); break; } } $filters[$filter_id]['other_variants'] = $_f['ranges']; } break; } } } else { if (!empty($params['variant_id']) && !empty($filters[$filter_id]['ranges'][$params['variant_id']])) { $filters[$filter_id]['ranges'][$params['variant_id']]['selected'] = true; // mark selected variant } } continue; // If its "view all" page, return all ranges } elseif (!empty($params['filter_id']) && $params['filter_id'] == $filter_id && !empty($merged[$filter_id])) { foreach ($merged[$filter_id] as $range) { if (!empty($range['index'])) { // feature $view_all[$range['index']][] = $range; } else { // custom range $view_all[$filters[$range['filter_id']]['filter']][] = $range; } } ksort($view_all); } // Unset filter if he is empty unset($filters[$filter_id]); } if (!empty($params['advanced_filter'])) { $_params = array('feature_types' => array('C', 'T'), 'plain' => true, 'category_ids' => array(empty($params['category_id']) ? 0 : $params['category_id'])); list($features) = fn_get_product_features($_params); if (!empty($features)) { $filters = array_merge($filters, $features); } } Registry::set($key, array($filters, $view_all)); } else { list($filters, $view_all) = Registry::get($key); } return array($filters, $view_all); }
function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAGE) { /** * Changes params for selecting products * * @param array $params Product search params * @param int $items_per_page Items per page * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_products_pre', $params, $items_per_page, $lang_code); // Init filter $params = LastView::instance()->update('products', $params); // Set default values to input params $default_params = array('area' => AREA, 'extend' => array('product_name', 'prices', 'categories'), 'custom_extend' => array(), 'pname' => '', 'pshort' => '', 'pfull' => '', 'pkeywords' => '', 'feature' => array(), 'type' => 'simple', 'page' => 1, 'action' => '', 'variants' => array(), 'ranges' => array(), 'custom_range' => array(), 'field_range' => array(), 'features_hash' => '', 'limit' => 0, 'bid' => 0, 'match' => '', 'tracking' => array(), 'get_frontend_urls' => false, 'items_per_page' => $items_per_page); if (empty($params['custom_extend'])) { $params['extend'] = !empty($params['extend']) ? array_merge($default_params['extend'], $params['extend']) : $default_params['extend']; } else { $params['extend'] = $params['custom_extend']; } $params = array_merge($default_params, $params); if ((empty($params['pname']) || $params['pname'] != 'Y') && (empty($params['pshort']) || $params['pshort'] != 'Y') && (empty($params['pfull']) || $params['pfull'] != 'Y') && (empty($params['pkeywords']) || $params['pkeywords'] != 'Y') && (empty($params['feature']) || $params['feature'] != 'Y') && !empty($params['q'])) { $params['pname'] = 'Y'; } $auth =& $_SESSION['auth']; // Define fields that should be retrieved if (empty($params['only_short_fields'])) { $fields = array('products.*'); } else { $fields = array('product_id' => 'products.product_id', 'product_code' => 'products.product_code', 'product_type' => 'products.product_type', 'status' => 'products.status', 'company_id' => 'products.company_id', 'list_price' => 'products.list_price', 'amount' => 'products.amount', 'weight' => 'products.weight', 'tracking' => 'products.tracking', 'is_edp' => 'products.is_edp', 'return_period' => 'products.return_period'); } //AS started_price $fields['subtitle'] = 'descr1.subtitle'; $fields['top_title'] = 'descr1.top_title'; $fields['started_price'] = 'prices.price AS started_price'; // Define sort fields $sortings = array('code' => 'products.product_code', 'status' => 'products.status', 'product' => 'product', 'position' => 'products_categories.position', 'price' => 'price', 'list_price' => 'products.list_price', 'weight' => 'products.weight', 'amount' => 'products.amount', 'timestamp' => 'products.timestamp', 'updated_timestamp' => 'products.updated_timestamp', 'popularity' => 'popularity.total', 'company' => 'company_name', 'null' => 'NULL'); if (!empty($params['get_subscribers'])) { $sortings['num_subscr'] = 'num_subscr'; $fields['num_subscr'] = 'COUNT(DISTINCT product_subscriptions.subscription_id) as num_subscr'; } if (!empty($params['order_ids'])) { $sortings['p_qty'] = 'purchased_qty'; $sortings['p_subtotal'] = 'purchased_subtotal'; $fields['purchased_qty'] = "SUM(?:order_details.amount) as purchased_qty"; $fields['purchased_subtotal'] = "SUM(?:order_details.price * ?:order_details.amount) as purchased_subtotal"; } if (isset($params['compact']) && $params['compact'] == 'Y') { $union_condition = ' OR '; } else { $union_condition = ' AND '; } $join = $condition = $u_condition = $inventory_condition = ''; $having = array(); $extraCondition = array(); // Search string condition for SQL query if (isset($params['q']) && fn_string_not_empty($params['q'])) { $params['q'] = trim($params['q']); if ($params['match'] == 'any') { $pieces = fn_explode(' ', $params['q']); $search_type = ' OR '; } elseif ($params['match'] == 'all') { $pieces = fn_explode(' ', $params['q']); $search_type = ' AND '; } else { $pieces = array($params['q']); $search_type = ''; } $_condition = array(); foreach ($pieces as $piece) { if (strlen($piece) == 0) { continue; } $tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%'); // check search words if ($params['pname'] == 'Y') { $tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%'); } if ($params['pshort'] == 'Y') { $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . $piece . '%'); $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%'); } if ($params['pfull'] == 'Y') { $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . $piece . '%'); $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%'); } if ($params['pkeywords'] == 'Y') { $tmp .= db_quote(" OR (descr1.meta_keywords LIKE ?l OR descr1.meta_description LIKE ?l)", '%' . $piece . '%', '%' . $piece . '%'); } if (!empty($params['feature']) && $params['action'] != 'feature_search') { $tmp .= db_quote(" OR ?:product_features_values.value LIKE ?l", '%' . $piece . '%'); } fn_set_hook('additional_fields_in_search', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $tmp, $piece, $having); $_condition[] = '(' . $tmp . ')'; } $_cond = implode($search_type, $_condition); if (!empty($_condition)) { $condition .= ' AND (' . $_cond . ') '; } if (!empty($params['feature']) && $params['action'] != 'feature_search') { $join .= " LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id"; $condition .= db_quote(" AND (?:product_features_values.feature_id IN (?n) OR ?:product_features_values.feature_id IS NULL)", array_values($params['feature'])); } //if perform search we also get additional fields if ($params['pname'] == 'Y') { $params['extend'][] = 'product_name'; } if ($params['pshort'] == 'Y' || $params['pfull'] == 'Y' || $params['pkeywords'] == 'Y') { $params['extend'][] = 'description'; } unset($_condition); } // // [Advanced and feature filters] // if (!empty($params['apply_limit']) && $params['apply_limit'] && !empty($params['pid'])) { $pids = array(); foreach ($params['pid'] as $pid) { if ($pid != $params['exclude_pid']) { if (count($pids) == $params['limit']) { break; } else { $pids[] = $pid; } } } $params['pid'] = $pids; } if (!empty($params['features_hash']) || !fn_is_empty($params['variants']) || !empty($params['feature_code'])) { $join .= db_quote(" LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id AND ?:product_features_values.lang_code = ?s", $lang_code); } if (!empty($params['variants'])) { $params['features_hash'] .= implode('.', $params['variants']); } // Feature code if (!empty($params['feature_code'])) { $join .= db_quote(" LEFT JOIN ?:product_features ON ?:product_features_values.feature_id = ?:product_features.feature_id"); $condition .= db_quote(" AND ?:product_features.feature_code = ?s", $params['feature_code']); } $advanced_variant_ids = $simple_variant_ids = $ranges_ids = $fields_ids = $fields_ids_revert = $slider_vals = array(); if (!empty($params['features_hash'])) { list($av_ids, $ranges_ids, $fields_ids, $slider_vals, $fields_ids_revert) = fn_parse_features_hash($params['features_hash']); $advanced_variant_ids = db_get_hash_multi_array("SELECT feature_id, variant_id FROM ?:product_feature_variants WHERE variant_id IN (?n)", array('feature_id', 'variant_id'), $av_ids); } if (!empty($params['multiple_variants'])) { $simple_variant_ids = $params['multiple_variants']; } if (!empty($advanced_variant_ids)) { $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS advanced_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_advanced ON pfv_advanced.product_id = products.product_id", $lang_code); $where_and_conditions = array(); foreach ($advanced_variant_ids as $k => $variant_ids) { $where_or_conditions = array(); foreach ($variant_ids as $variant_id => $v) { $where_or_conditions[] = db_quote(" FIND_IN_SET('?i', advanced_variants)", $variant_id); } $where_and_conditions[] = '(' . implode(' OR ', $where_or_conditions) . ')'; } $condition .= ' AND ' . implode(' AND ', $where_and_conditions); } if (!empty($simple_variant_ids)) { $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS simple_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_simple ON pfv_simple.product_id = products.product_id", $lang_code); $where_conditions = array(); foreach ($simple_variant_ids as $k => $variant_id) { $where_conditions[] = db_quote(" FIND_IN_SET('?i', simple_variants)", $variant_id); } $condition .= ' AND ' . implode(' AND ', $where_conditions); } // // Ranges from text inputs // // Feature ranges if (!empty($params['custom_range'])) { foreach ($params['custom_range'] as $k => $v) { $k = intval($k); if (isset($v['from']) && fn_string_not_empty($v['from']) || isset($v['to']) && fn_string_not_empty($v['to'])) { if (!empty($v['type'])) { if ($v['type'] == 'D') { $v['from'] = fn_parse_date($v['from']); $v['to'] = fn_parse_date($v['to']); } } $join .= db_quote(" LEFT JOIN ?:product_features_values as custom_range_{$k} ON custom_range_{$k}.product_id = products.product_id AND custom_range_{$k}.lang_code = ?s", $lang_code); if (fn_string_not_empty($v['from']) && fn_string_not_empty($v['to'])) { $condition .= db_quote(" AND (custom_range_{$k}.value_int >= ?i AND custom_range_{$k}.value_int <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i) ", $v['from'], $v['to'], $k); } else { $condition .= " AND custom_range_{$k}.value_int" . (fn_string_not_empty($v['from']) ? db_quote(' >= ?i', $v['from']) : db_quote(" <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i ", $v['to'], $k)); } } } } // Product field ranges $filter_fields = fn_get_product_filter_fields(); if (!empty($params['field_range'])) { foreach ($params['field_range'] as $field_type => $v) { $structure = $filter_fields[$field_type]; if (!empty($structure) && (!empty($v['from']) || !empty($v['to']))) { if ($field_type == 'P') { // price $v['cur'] = !empty($v['cur']) ? $v['cur'] : CART_SECONDARY_CURRENCY; if (empty($v['orig_cur'])) { // saving the first user-entered values // will be always search by it $v['orig_from'] = $v['from']; $v['orig_to'] = $v['to']; $v['orig_cur'] = $v['cur']; $params['field_range'][$field_type] = $v; } if ($v['orig_cur'] != CART_PRIMARY_CURRENCY) { // calc price in primary currency $cur_prim_coef = Registry::get('currencies.' . $v['orig_cur'] . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $search_from = round($v['orig_from'] * floatval($cur_prim_coef), $decimals); $search_to = round($v['orig_to'] * floatval($cur_prim_coef), $decimals); } else { $search_from = $v['orig_from']; $search_to = $v['orig_to']; } // if user switch the currency, calc new values for displaying in filter if ($v['cur'] != CART_SECONDARY_CURRENCY) { if (CART_SECONDARY_CURRENCY == $v['orig_cur']) { $v['from'] = $v['orig_from']; $v['to'] = $v['orig_to']; } else { $prev_coef = Registry::get('currencies.' . $v['cur'] . '.coefficient'); $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $v['from'] = floor(floatval($v['from']) * floatval($prev_coef) / floatval($cur_coef)); $v['to'] = ceil(floatval($v['to']) * floatval($prev_coef) / floatval($cur_coef)); } $v['cur'] = CART_SECONDARY_CURRENCY; $params['field_range'][$field_type] = $v; } } $params["{$structure['db_field']}_from"] = trim(isset($search_from) ? $search_from : $v['from']); $params["{$structure['db_field']}_to"] = trim(isset($search_to) ? $search_to : $v['to']); } } } // Ranges from database if (!empty($ranges_ids)) { $filter_conditions = db_get_hash_multi_array("SELECT `from`, `to`, feature_id, filter_id, range_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", array('filter_id', 'range_id'), $ranges_ids); $where_conditions = array(); foreach ($filter_conditions as $fid => $range_conditions) { foreach ($range_conditions as $k => $range_condition) { $k = $fid . "_" . $k; $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = products.product_id AND var_val_{$k}.lang_code = ?s", $lang_code); $where_conditions[] = db_quote("(var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $range_condition['from'], $range_condition['to'], $range_condition['feature_id']); } $condition .= db_quote(" AND (?p)", implode(" OR ", $where_conditions)); $where_conditions = array(); } } // Field ranges //$fields_ids = empty($params['fields_ids']) ? $fields_ids : $params['fields_ids']; if (!empty($params['fields_ids'])) { foreach ($fields_ids as $rid => $field_type) { if (!empty($filter_fields[$field_type])) { $structure = $filter_fields[$field_type]; if ($structure['condition_type'] == 'D' && empty($structure['slider'])) { $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid); if (!empty($range_condition)) { $params["{$structure['db_field']}_from"] = $range_condition['from']; $params["{$structure['db_field']}_to"] = $range_condition['to']; } } elseif ($structure['condition_type'] == 'F') { $params['filter_params'][$structure['db_field']][] = $rid; } elseif ($structure['condition_type'] == 'C') { $params['filter_params'][$structure['db_field']][] = $rid == 1 ? 'Y' : 'N'; } } } } elseif (!empty($fields_ids_revert)) { foreach ($fields_ids_revert as $field_type => $rids) { if (!empty($filter_fields[$field_type])) { $structure = $filter_fields[$field_type]; if ($structure['condition_type'] == 'D' && empty($structure['slider'])) { foreach ($rids as $rid) { $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid); if (!empty($range_condition)) { $params["{$structure['db_field']}_from"] = $range_condition['from']; $params["{$structure['db_field']}_to"] = $range_condition['to']; } } } elseif ($structure['condition_type'] == 'F') { $params['filter_params'][$structure['db_field']] = $rids; } elseif ($structure['condition_type'] == 'C') { if (count($rids) > 1) { foreach ($rids as $rid) { if ($fields_ids[$rid] == $field_type) { unset($fields_ids[$rid]); } $params['features_hash'] = fn_delete_range_from_url($params['features_hash'], array('range_id' => $rid), $field_type); } } else { $params['filter_params'][$structure['db_field']][] = $rids[0] == 1 ? 'Y' : 'N'; } } } } } // Slider ranges $slider_vals = empty($params['slider_vals']) ? $slider_vals : $params['slider_vals']; if (!empty($slider_vals)) { foreach ($slider_vals as $field_type => $vals) { if (!empty($filter_fields[$field_type])) { if ($field_type == 'P') { $currency = !empty($vals[2]) ? $vals[2] : CART_PRIMARY_CURRENCY; if ($currency != CART_PRIMARY_CURRENCY) { $coef = Registry::get('currencies.' . $currency . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $vals[0] = round(floatval($vals[0]) * floatval($coef), $decimals); $vals[1] = round(floatval($vals[1]) * floatval($coef), $decimals); } } $structure = $filter_fields[$field_type]; $params["{$structure['db_field']}_from"] = $vals[0]; $params["{$structure['db_field']}_to"] = $vals[1]; } } } // Checkbox features if (!empty($params['ch_filters']) && !fn_is_empty($params['ch_filters'])) { foreach ($params['ch_filters'] as $k => $v) { // Product field filter if (is_string($k) == true && !empty($v) && ($structure = $filter_fields[$k])) { $condition .= db_quote(" AND {$structure['table']}.{$structure['db_field']} IN (?a)", $v == 'A' ? array('Y', 'N') : $v); // Feature filter } elseif (!empty($v)) { $fid = intval($k); $join .= db_quote(" LEFT JOIN ?:product_features_values as ch_features_{$fid} ON ch_features_{$fid}.product_id = products.product_id AND ch_features_{$fid}.lang_code = ?s", $lang_code); $condition .= db_quote(" AND ch_features_{$fid}.feature_id = ?i AND ch_features_{$fid}.value IN (?a)", $fid, $v == 'A' ? array('Y', 'N') : $v); } } } // Text features if (!empty($params['tx_features'])) { foreach ($params['tx_features'] as $k => $v) { if (fn_string_not_empty($v)) { $fid = intval($k); $join .= " LEFT JOIN ?:product_features_values as tx_features_{$fid} ON tx_features_{$fid}.product_id = products.product_id"; $condition .= db_quote(" AND tx_features_{$fid}.value LIKE ?l AND tx_features_{$fid}.lang_code = ?s", "%" . trim($v) . "%", $lang_code); } } } $total = 0; fn_set_hook('get_products_before_select', $params, $join, $condition, $u_condition, $inventory_condition, $sortings, $total, $items_per_page, $lang_code, $having); // // [/Advanced filters] // $feature_search_condition = ''; if (!empty($params['feature'])) { // Extended search by product fields $_cond = array(); $total_hits = 0; foreach ($params['feature'] as $f_id) { if (!empty($f_val)) { $total_hits++; $_cond[] = db_quote("(?:product_features_values.feature_id = ?i)", $f_id); } } $params['extend'][] = 'categories'; if (!empty($_cond)) { $cache_feature_search = db_get_fields("SELECT product_id, COUNT(product_id) as cnt FROM ?:product_features_values WHERE (" . implode(' OR ', $_cond) . ") GROUP BY product_id HAVING cnt = {$total_hits}"); $feature_search_condition .= db_quote(" AND products_categories.product_id IN (?n)", $cache_feature_search); } } // Category search condition for SQL query if (!empty($params['cid'])) { $cids = is_array($params['cid']) ? $params['cid'] : explode(',', $params['cid']); if (!empty($params['subcats']) && $params['subcats'] == 'Y') { $_ids = db_get_fields("SELECT a.category_id FROM ?:categories as a LEFT JOIN ?:categories as b ON b.category_id IN (?n) WHERE a.id_path LIKE CONCAT(b.id_path, '/%')", $cids); $cids = fn_array_merge($cids, $_ids, false); } $params['extend'][] = 'categories'; $condition .= db_quote(" AND ?:categories.category_id IN (?n)", $cids); } // If we need to get the products by IDs and no IDs passed, don't search anything if (!empty($params['force_get_by_ids']) && empty($params['pid']) && empty($params['product_id'])) { return array(array(), $params, 0); } // Product ID search condition for SQL query if (!empty($params['pid'])) { $u_condition .= db_quote($union_condition . ' products.product_id IN (?n)', $params['pid']); } // Exclude products from search results if (!empty($params['exclude_pid'])) { $condition .= db_quote(' AND products.product_id NOT IN (?n)', $params['exclude_pid']); } // Search by feature comparison flag if (!empty($params['feature_comparison'])) { $condition .= db_quote(' AND products.feature_comparison = ?s', $params['feature_comparison']); } // Search products by localization $condition .= fn_get_localizations_condition('products.localization', true); $company_condition = ''; if (fn_allowed_for('MULTIVENDOR')) { if ($params['area'] == 'C') { $company_condition .= " AND companies.status = 'A' "; $params['extend'][] = 'companies'; } else { $company_condition .= fn_get_company_condition('products.company_id'); } } else { $cat_company_condition = ''; if (Registry::get('runtime.company_id')) { $params['extend'][] = 'categories'; $cat_company_condition .= fn_get_company_condition('?:categories.company_id'); } elseif (!empty($params['company_ids'])) { $params['extend'][] = 'categories'; $cat_company_condition .= db_quote(' AND ?:categories.company_id IN (?a)', explode(',', $params['company_ids'])); } $company_condition .= $cat_company_condition; } $condition .= $company_condition; if (!fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && isset($params['company_id'])) { $params['company_id'] = Registry::get('runtime.company_id'); } if (isset($params['company_id']) && $params['company_id'] != '') { $condition .= db_quote(' AND products.company_id = ?i ', $params['company_id']); } if (!empty($params['filter_params'])) { foreach ($params['filter_params'] as $field => $f_vals) { $condition .= db_quote(' AND products.' . $field . ' IN (?a) ', $f_vals); } } if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) { $having['price_from'] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from']))); $extraCondition["price_from"] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from']))); //$condition .= db_quote(' AND prices.price >= ?d', fn_convert_price(trim($params['price_from']))); $params['extend'][] = 'prices2'; } if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) { $having['price_to'] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to']))); $extraCondition["price_to"] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to']))); //$condition .= db_quote(' AND prices.price <= ?d', fn_convert_price(trim($params['price_to']))); $params['extend'][] = 'prices2'; } if (isset($params['weight_from']) && fn_is_numeric($params['weight_from'])) { $condition .= db_quote(' AND products.weight >= ?d', fn_convert_weight(trim($params['weight_from']))); } if (isset($params['weight_to']) && fn_is_numeric($params['weight_to'])) { $condition .= db_quote(' AND products.weight <= ?d', fn_convert_weight(trim($params['weight_to']))); } // search specific inventory status if (!empty($params['tracking'])) { $condition .= db_quote(' AND products.tracking IN(?a)', $params['tracking']); } if (isset($params['amount_from']) && fn_is_numeric($params['amount_from'])) { $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount >= ?i, products.amount >= ?i)", $params['amount_from'], $params['amount_from']); $inventory_condition .= db_quote(' AND inventory.amount >= ?i', $params['amount_from']); } if (isset($params['amount_to']) && fn_is_numeric($params['amount_to'])) { $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount <= ?i, products.amount <= ?i)", $params['amount_to'], $params['amount_to']); $inventory_condition .= db_quote(' AND inventory.amount <= ?i', $params['amount_to']); } if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') { // FIXME? Registry in model $condition .= " AND IF(products.tracking = 'O', inventory.amount > 0, products.amount > 0)"; } if (!empty($params['status'])) { $condition .= db_quote(' AND products.status IN (?a)', $params['status']); } if (!empty($params['shipping_freight_from'])) { $condition .= db_quote(' AND products.shipping_freight >= ?d', $params['shipping_freight_from']); } if (!empty($params['shipping_freight_to'])) { $condition .= db_quote(' AND products.shipping_freight <= ?d', $params['shipping_freight_to']); } if (!empty($params['free_shipping'])) { $condition .= db_quote(' AND products.free_shipping = ?s', $params['free_shipping']); } if (!empty($params['downloadable'])) { $condition .= db_quote(' AND products.is_edp = ?s', $params['downloadable']); } if (isset($params['pcode']) && fn_string_not_empty($params['pcode'])) { $pcode = trim($params['pcode']); $fields['combination'] = 'inventory.combination'; $u_condition .= db_quote(" {$union_condition} (inventory.product_code LIKE ?l OR products.product_code LIKE ?l)", "%{$pcode}%", "%{$pcode}%"); $inventory_condition .= db_quote(" AND inventory.product_code LIKE ?l", "%{$pcode}%"); } if (isset($params['amount_to']) && fn_is_numeric($params['amount_to']) || isset($params['amount_from']) && fn_is_numeric($params['amount_from']) || !empty($params['pcode']) || Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') { $join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = products.product_id {$inventory_condition}"; } if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $condition .= db_quote(" AND (products.timestamp >= ?i AND products.timestamp <= ?i)", $params['time_from'], $params['time_to']); } if (!empty($params['item_ids'])) { $condition .= db_quote(" AND products.product_id IN (?n)", explode(',', $params['item_ids'])); } if (isset($params['popularity_from']) && fn_is_numeric($params['popularity_from'])) { $params['extend'][] = 'popularity'; $condition .= db_quote(' AND popularity.total >= ?i', $params['popularity_from']); } if (isset($params['popularity_to']) && fn_is_numeric($params['popularity_to'])) { $params['extend'][] = 'popularity'; $condition .= db_quote(' AND popularity.total <= ?i', $params['popularity_to']); } if (!empty($params['order_ids'])) { $arr = strpos($params['order_ids'], ',') !== false || !is_array($params['order_ids']) ? explode(',', $params['order_ids']) : $params['order_ids']; $condition .= db_quote(" AND ?:order_details.order_id IN (?n)", $arr); $join .= " LEFT JOIN ?:order_details ON ?:order_details.product_id = products.product_id"; } $limit = ''; $group_by = 'products.product_id'; // Show enabled products $_p_statuses = array('A'); if ($params['p_status']) { $_p_statuses = array('A', 'H'); } $condition .= $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], 'products.usergroup_ids', true) . ')' . db_quote(' AND products.status IN (?a)', $_p_statuses) : ''; // -- JOINS -- if (in_array('product_name', $params['extend'])) { $fields['product'] = 'descr1.product as product'; $join .= db_quote(" LEFT JOIN ?:product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ?s ", $lang_code); } // get prices $price_condition = ''; if (in_array('prices', $params['extend'])) { // //$fields['price'] = 'MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price'; $join .= " LEFT JOIN ?:product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1"; $price_condition = db_quote(' AND prices.usergroup_id IN (?n)', $params['area'] == 'A' ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids'])); $condition .= $price_condition; //$price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); $extraConditionString = ""; if (count($extraCondition) > 0) { $extraConditionString = "WHERE " . implode(" AND ", $extraCondition); } $fields['price'] = 'case when p2.min_price > 0 then p2.min_price else p3.price2 end'; $join .= " LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices " . $extraConditionString . " GROUP BY product_id) AS p2 ON p2.product_id = products.product_id\n LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2 FROM ?:product_prices WHERE lower_limit = 1 GROUP by product_id) AS p3 ON p3.product_id=products.product_id "; } /* // get prices for search by price if (in_array('prices2', $params['extend'])) { $price_usergroup_cond_2 = db_quote(' AND prices_2.usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); $join .= " LEFT JOIN ?:product_prices as prices_2 ON prices.product_id = prices_2.product_id AND prices_2.lower_limit = 1 AND prices_2.price < prices.price " . $price_usergroup_cond_2; $condition .= ' AND prices_2.price IS NULL'; $price_condition .= ' AND prices_2.price IS NULL'; } */ // if (in_array('prices2', $params['extend'])) { // $price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); // $fields['price'] = 'case // when p2.min_price > 0 then p2.min_price // else p3.price2 // end'; // $join .= " LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices GROUP BY product_id) AS p2 ON p2.product_id = products.product_id // LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2 FROM ?:product_prices WHERE lower_limit = 1 ".$price_usergroup_cond_2." GROUP by product_id) AS p3 ON p3.product_id=products.product_id "; // } // get short & full description if (in_array('search_words', $params['extend'])) { $fields['search_words'] = 'descr1.search_words'; } // get short & full description if (in_array('description', $params['extend'])) { $fields['short_description'] = 'descr1.short_description'; if (in_array('full_description', $params['extend'])) { $fields['full_description'] = "descr1.full_description"; } else { $fields['full_description'] = "IF(descr1.short_description = '', descr1.full_description, '') as full_description"; } } // get companies $companies_join = db_quote(" LEFT JOIN ?:companies AS companies ON companies.company_id = products.company_id "); if (in_array('companies', $params['extend'])) { $fields['company_name'] = 'companies.company as company_name'; $join .= $companies_join; } // for compatibility if (in_array('category_ids', $params['extend'])) { $params['extend'][] = 'categories'; } // get categories $_c_statuses = array('A', 'H'); // Show enabled categories $skip_checking_usergroup_permissions = fn_is_preview_action($auth, $params); if ($skip_checking_usergroup_permissions) { $category_avail_cond = ''; } else { $category_avail_cond = $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ')' : ''; } $category_avail_cond .= $params['area'] == 'C' ? db_quote(" AND ?:categories.status IN (?a) ", $_c_statuses) : ''; $categories_join = " INNER JOIN ?:products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN ?:categories ON ?:categories.category_id = products_categories.category_id {$category_avail_cond} {$feature_search_condition}"; if (!empty($params['order_ids'])) { // Avoid duplicating by sub-categories $condition .= db_quote(' AND products_categories.link_type = ?s', 'M'); } if (in_array('categories', $params['extend'])) { $fields['category_ids'] = "GROUP_CONCAT(IF(products_categories.link_type = 'M', CONCAT(products_categories.category_id, 'M'), products_categories.category_id)) as category_ids"; $fields['categories_position'] = 'products_categories.position'; $join .= $categories_join; $condition .= fn_get_localizations_condition('?:categories.localization', true); } // get popularity $popularity_join = db_quote(" LEFT JOIN ?:product_popularity as popularity ON popularity.product_id = products.product_id"); if (in_array('popularity', $params['extend'])) { $fields['popularity'] = 'popularity.total as popularity'; $join .= $popularity_join; } if (!empty($params['get_subscribers'])) { $join .= " LEFT JOIN ?:product_subscriptions as product_subscriptions ON product_subscriptions.product_id = products.product_id"; } // -- \JOINs -- if (!empty($u_condition)) { $condition .= " {$union_condition} ((" . ($union_condition == ' OR ' ? '0 ' : '1 ') . $u_condition . ')' . $company_condition . $price_condition . ')'; } /** * Changes additional params for selecting products * * @param array $params Product search params * @param array $fields List of fields for retrieving * @param array $sortings Sorting fields * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $sorting String containing the SQL-query ORDER BY clause * @param string $group_by String containing the SQL-query GROUP BY field * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) * @param array $having HAVING condition */ fn_set_hook('get_products', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $lang_code, $having); // -- SORTINGS -- if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) { $params = array_merge($params, fn_get_default_products_sorting()); if (empty($sortings[$params['sort_by']])) { $_products_sortings = fn_get_products_sorting(); $params['sort_by'] = key($_products_sortings); } } $default_sorting = fn_get_products_sorting(); if ($params['sort_by'] == 'popularity' && !in_array('popularity', $params['extend'])) { $join .= $popularity_join; } if ($params['sort_by'] == 'company' && !in_array('companies', $params['extend'])) { $join .= $companies_join; } if (empty($params['sort_order'])) { if (!empty($default_sorting[$params['sort_by']]['default_order'])) { $params['sort_order'] = $default_sorting[$params['sort_by']]['default_order']; } else { $params['sort_order'] = 'asc'; } } $sorting = db_sort($params, $sortings); if (fn_allowed_for('ULTIMATE')) { if (in_array('sharing', $params['extend'])) { $fields['is_shared_product'] = "IF(COUNT(IF(?:categories.company_id = products.company_id, NULL, ?:categories.company_id)), 'Y', 'N') as is_shared_product"; if (strpos($join, $categories_join) === false) { $join .= $categories_join; } } } // -- \SORTINGS -- // Used for View cascading if (!empty($params['get_query'])) { return "SELECT products.product_id FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY products.product_id"; } // Used for Extended search if (!empty($params['get_conditions'])) { return array($fields, $join, $condition); } if (!empty($params['limit'])) { $limit = db_quote(" LIMIT 0, ?i", $params['limit']); } elseif (!empty($params['items_per_page'])) { $limit = db_paginate($params['page'], $params['items_per_page']); } $calc_found_rows = ''; if (empty($total)) { $calc_found_rows = 'SQL_CALC_FOUND_ROWS'; } if (!empty($having)) { $having = ' HAVING ' . implode(' AND ', $having); } else { $having = ''; } $products = db_get_array("SELECT {$calc_found_rows} " . implode(', ', $fields) . " FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$having} {$sorting} {$limit}"); if (!empty($params['items_per_page'])) { $params['total_items'] = !empty($total) ? $total : db_get_found_rows(); } else { $params['total_items'] = count($products); } // Post processing if (in_array('categories', $params['extend'])) { foreach ($products as $k => $v) { list($products[$k]['category_ids'], $products[$k]['main_category']) = fn_convert_categories($v['category_ids']); } } if (!empty($params['get_frontend_urls'])) { foreach ($products as &$product) { $product['url'] = fn_url('products.view?product_id=' . $product['product_id'], 'C'); } } if (!empty($params['item_ids'])) { $products = fn_sort_by_ids($products, explode(',', $params['item_ids'])); } if (!empty($params['pid']) && !empty($params['apply_limit']) && $params['apply_limit']) { $products = fn_sort_by_ids($products, $params['pid']); } foreach ($products as $keyProduct => $productItem) { $checkInventoryPrices = array(); $inventory_product = array(); $checkInventoryPrices = db_get_row("SELECT b.price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i ", $productItem['product_id']); if ($checkInventoryPrices && count($checkInventoryPrices) > 0) { $conditionExt = ""; if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) { $conditionExt .= db_quote(' AND b.price >= ?d', fn_convert_price(trim($params['price_from']))); } if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) { $conditionExt .= db_quote(' AND b.price <= ?d', fn_convert_price(trim($params['price_to']))); } $inventory_product = db_get_row("SELECT MIN(b.price ) AS min_price, MAX(b.price ) AS max_price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i " . $conditionExt . " GROUP BY a.product_id", $productItem['product_id']); if (!$inventory_product || count($inventory_product) < 1) { unset($products[$keyProduct]); } elseif ($inventory_product && count($inventory_product) > 0) { $products[$keyProduct]['price_range'] = $inventory_product; } } //fn_promotion_apply('catalog', $productItem, $auth); } /** * Changes selected products * * @param array $products Array of products * @param array $params Product search params * @param string $lang_code Language code */ fn_set_hook('get_products_post', $products, $params, $lang_code); LastView::instance()->processResults('products', $products, $params); return array($products, $params); }
function content_55ccf2ea7e3e06_11166307($_smarty_tpl) { if (!is_callable('smarty_function_set_id')) { include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.set_id.php'; } fn_preload_lang_vars(array('view_all', 'more', 'less', 'view_all', 'more', 'less')); if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] == "Y" && @constant('AREA') == "C") { $_smarty_tpl->_capture_stack[0][] = array("template_content", null, null); ob_start(); ?> <ul class="ty-product-filters <?php if ($_smarty_tpl->tpl_vars['collapse']->value) { ?> hidden<?php } ?> cm-popup-box ty-dropdown-box__content" id="content_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["selected_range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["selected_range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['selected_ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["selected_range"]->key => $_smarty_tpl->tpl_vars["selected_range"]->value) { $_smarty_tpl->tpl_vars["selected_range"]->_loop = true; ?> <?php $_smarty_tpl->_capture_stack[0][] = array("has_selected", null, null); ob_start(); ?> Y<?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <li class="ty-product-filters__group"> <?php $_smarty_tpl->tpl_vars["fh"] = new Smarty_variable(fn_delete_range_from_url($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['selected_range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); if ($_smarty_tpl->tpl_vars['fh']->value) { $_smarty_tpl->tpl_vars["attach_query"] = new Smarty_variable("features_hash=" . (string) $_smarty_tpl->tpl_vars['fh']->value, null, 0); } if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] == "E" && $_smarty_tpl->tpl_vars['selected_range']->value['range_id'] == $_REQUEST['variant_id']) { $_smarty_tpl->tpl_vars["reset_lnk"] = new Smarty_variable($_smarty_tpl->tpl_vars['reset_qstring']->value, null, 0); } else { $_smarty_tpl->tpl_vars["reset_lnk"] = new Smarty_variable($_smarty_tpl->tpl_vars['filter_qstring']->value, null, 0); } if ($_smarty_tpl->tpl_vars['fh']->value) { $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url(fn_link_attach($_smarty_tpl->tpl_vars['reset_lnk']->value, $_smarty_tpl->tpl_vars['attach_query']->value)), null, 0); } else { $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url($_smarty_tpl->tpl_vars['reset_lnk']->value), null, 0); } $_smarty_tpl->tpl_vars["use_ajax"] = new Smarty_variable(fn_compare_dispatch($_smarty_tpl->tpl_vars['href']->value, $_smarty_tpl->tpl_vars['config']->value['current_url']), null, 0); ?> <a href="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['href']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__item checked cm-history" data-ca-scroll=".cm-pagination-container" data-ca-target-id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['ajax_div_ids']->value, ENT_QUOTES, 'UTF-8'); ?> " rel="nofollow"><span class="ty-filter-icon"><i class="ty-icon-ok ty-filter-icon__check"></i><i class="ty-icon-cancel ty-filter-icon__delete"></i></span><?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['prefix'], ENT_QUOTES, 'UTF-8'); echo htmlspecialchars(fn_text_placeholders($_smarty_tpl->tpl_vars['selected_range']->value['range_name']), ENT_QUOTES, 'UTF-8'); echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['suffix'], ENT_QUOTES, 'UTF-8'); ?> </a> </li> <?php } ?> <?php if (fn_is_not_empty($_smarty_tpl->tpl_vars['filter']->value['ranges'])) { ?> <li class="ty-product-filters__item-more"> <ul id="ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["range"]->key => $_smarty_tpl->tpl_vars["range"]->value) { $_smarty_tpl->tpl_vars["range"]->_loop = true; ?> <?php echo $_smarty_tpl->getSubTemplate("blocks/product_filters/components/variant_item.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('range' => $_smarty_tpl->tpl_vars['range']->value, 'filter' => $_smarty_tpl->tpl_vars['filter']->value, 'ajax_div_ids' => $_smarty_tpl->tpl_vars['ajax_div_ids']->value, 'filter_qstring' => $_smarty_tpl->tpl_vars['filter_qstring']->value, 'reset_qstring' => $_smarty_tpl->tpl_vars['reset_qstring']->value, 'allow_ajax' => $_smarty_tpl->tpl_vars['allow_ajax']->value), 0); ?> <?php } ?> </ul> </li> <?php } ?> <?php $_smarty_tpl->_capture_stack[0][] = array("view_all", null, null); ob_start(); ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['more_cut']) { ?> <?php $_smarty_tpl->_capture_stack[0][] = array("q", null, null); ob_start(); echo $_smarty_tpl->tpl_vars['filter_qstring']->value; ?> &filter_id=<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['filter_id'], ENT_QUOTES, 'UTF-8'); ?> &<?php if ($_REQUEST['features_hash']) { ?> &features_hash=<?php echo htmlspecialchars($_REQUEST['features_hash'], ENT_QUOTES, 'UTF-8'); } list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <li class="ty-product-filters__group" id="view_all_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["capture_q"] = new Smarty_variable(rawurlencode(Smarty::$_smarty_vars['capture']['q']), null, 0); ?> <a href="<?php echo htmlspecialchars(fn_url("product_features.view_all?q=" . (string) $_smarty_tpl->tpl_vars['capture_q']->value), ENT_QUOTES, 'UTF-8'); ?> " rel="nofollow" class="ty-product-filters__extra-link ty-extra-link"><?php echo $_smarty_tpl->__("view_all"); ?> </a> </li> <?php } ?> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <?php if (fn_is_not_empty($_smarty_tpl->tpl_vars['filter']->value['more_ranges'])) { ?> <?php $_smarty_tpl->tpl_vars["cookie_name_show_more"] = new Smarty_variable("more_ranges_" . (string) $_smarty_tpl->tpl_vars['filter_uid']->value, null, 0); ?> <?php $_smarty_tpl->tpl_vars["more_collapse"] = new Smarty_variable(true, null, 0); ?> <?php if ($_COOKIE[$_smarty_tpl->tpl_vars['cookie_name_show_more']->value]) { ?> <?php $_smarty_tpl->tpl_vars["more_collapse"] = new Smarty_variable(false, null, 0); ?> <?php } ?> <li> <ul id="more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " <?php if ($_smarty_tpl->tpl_vars['more_collapse']->value) { ?> class="hidden"<?php } ?> > <?php $_smarty_tpl->tpl_vars["range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['more_ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["range"]->key => $_smarty_tpl->tpl_vars["range"]->value) { $_smarty_tpl->tpl_vars["range"]->_loop = true; ?> <?php echo $_smarty_tpl->getSubTemplate("blocks/product_filters/components/variant_item.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('range' => $_smarty_tpl->tpl_vars['range']->value, 'filter' => $_smarty_tpl->tpl_vars['filter']->value, 'ajax_div_ids' => $_smarty_tpl->tpl_vars['ajax_div_ids']->value, 'filter_qstring' => $_smarty_tpl->tpl_vars['filter_qstring']->value, 'reset_qstring' => $_smarty_tpl->tpl_vars['reset_qstring']->value, 'allow_ajax' => $_smarty_tpl->tpl_vars['allow_ajax']->value), 0); ?> <?php } ?> <?php echo Smarty::$_smarty_vars['capture']['view_all']; ?> </ul> </li> <li class="ty-product-filters__extra-block"> <a id="on_more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__extra-link ty-extra-link cm-save-state cm-combination-more_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); if (!$_smarty_tpl->tpl_vars['more_collapse']->value) { ?> hidden<?php } ?> "><?php echo $_smarty_tpl->__("more"); ?> </a> <a id="off_more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__extra-link ty-extra-link cm-save-state cm-combination-more_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); if ($_smarty_tpl->tpl_vars['more_collapse']->value) { ?> hidden<?php } ?> "><?php echo $_smarty_tpl->__("less"); ?> </a> </li> <?php } else { ?> <?php echo Smarty::$_smarty_vars['capture']['view_all']; ?> <?php } ?> </ul><?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } if (trim(Smarty::$_smarty_vars['capture']['template_content'])) { if ($_smarty_tpl->tpl_vars['auth']->value['area'] == "A") { ?> <span class="cm-template-box template-box" data-ca-te-template="blocks/product_filters/components/product_filter_variants.tpl" id="<?php echo smarty_function_set_id(array('name' => "blocks/product_filters/components/product_filter_variants.tpl"), $_smarty_tpl); ?> "><div class="cm-template-icon icon-edit ty-icon-edit hidden"></div><?php echo Smarty::$_smarty_vars['capture']['template_content']; ?> <!--[/tpl_id]--></span><?php } else { echo Smarty::$_smarty_vars['capture']['template_content']; } } } else { ?> <ul class="ty-product-filters <?php if ($_smarty_tpl->tpl_vars['collapse']->value) { ?> hidden<?php } ?> cm-popup-box ty-dropdown-box__content" id="content_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["selected_range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["selected_range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['selected_ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["selected_range"]->key => $_smarty_tpl->tpl_vars["selected_range"]->value) { $_smarty_tpl->tpl_vars["selected_range"]->_loop = true; ?> <?php $_smarty_tpl->_capture_stack[0][] = array("has_selected", null, null); ob_start(); ?> Y<?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <li class="ty-product-filters__group"> <?php $_smarty_tpl->tpl_vars["fh"] = new Smarty_variable(fn_delete_range_from_url($_REQUEST['features_hash'], $_smarty_tpl->tpl_vars['selected_range']->value, $_smarty_tpl->tpl_vars['filter']->value['field_type']), null, 0); if ($_smarty_tpl->tpl_vars['fh']->value) { $_smarty_tpl->tpl_vars["attach_query"] = new Smarty_variable("features_hash=" . (string) $_smarty_tpl->tpl_vars['fh']->value, null, 0); } if ($_smarty_tpl->tpl_vars['filter']->value['feature_type'] == "E" && $_smarty_tpl->tpl_vars['selected_range']->value['range_id'] == $_REQUEST['variant_id']) { $_smarty_tpl->tpl_vars["reset_lnk"] = new Smarty_variable($_smarty_tpl->tpl_vars['reset_qstring']->value, null, 0); } else { $_smarty_tpl->tpl_vars["reset_lnk"] = new Smarty_variable($_smarty_tpl->tpl_vars['filter_qstring']->value, null, 0); } if ($_smarty_tpl->tpl_vars['fh']->value) { $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url(fn_link_attach($_smarty_tpl->tpl_vars['reset_lnk']->value, $_smarty_tpl->tpl_vars['attach_query']->value)), null, 0); } else { $_smarty_tpl->tpl_vars["href"] = new Smarty_variable(fn_url($_smarty_tpl->tpl_vars['reset_lnk']->value), null, 0); } $_smarty_tpl->tpl_vars["use_ajax"] = new Smarty_variable(fn_compare_dispatch($_smarty_tpl->tpl_vars['href']->value, $_smarty_tpl->tpl_vars['config']->value['current_url']), null, 0); ?> <a href="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['href']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__item checked cm-history" data-ca-scroll=".cm-pagination-container" data-ca-target-id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['ajax_div_ids']->value, ENT_QUOTES, 'UTF-8'); ?> " rel="nofollow"><span class="ty-filter-icon"><i class="ty-icon-ok ty-filter-icon__check"></i><i class="ty-icon-cancel ty-filter-icon__delete"></i></span><?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['prefix'], ENT_QUOTES, 'UTF-8'); echo htmlspecialchars(fn_text_placeholders($_smarty_tpl->tpl_vars['selected_range']->value['range_name']), ENT_QUOTES, 'UTF-8'); echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['suffix'], ENT_QUOTES, 'UTF-8'); ?> </a> </li> <?php } ?> <?php if (fn_is_not_empty($_smarty_tpl->tpl_vars['filter']->value['ranges'])) { ?> <li class="ty-product-filters__item-more"> <ul id="ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["range"]->key => $_smarty_tpl->tpl_vars["range"]->value) { $_smarty_tpl->tpl_vars["range"]->_loop = true; ?> <?php echo $_smarty_tpl->getSubTemplate("blocks/product_filters/components/variant_item.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('range' => $_smarty_tpl->tpl_vars['range']->value, 'filter' => $_smarty_tpl->tpl_vars['filter']->value, 'ajax_div_ids' => $_smarty_tpl->tpl_vars['ajax_div_ids']->value, 'filter_qstring' => $_smarty_tpl->tpl_vars['filter_qstring']->value, 'reset_qstring' => $_smarty_tpl->tpl_vars['reset_qstring']->value, 'allow_ajax' => $_smarty_tpl->tpl_vars['allow_ajax']->value), 0); ?> <?php } ?> </ul> </li> <?php } ?> <?php $_smarty_tpl->_capture_stack[0][] = array("view_all", null, null); ob_start(); ?> <?php if ($_smarty_tpl->tpl_vars['filter']->value['more_cut']) { ?> <?php $_smarty_tpl->_capture_stack[0][] = array("q", null, null); ob_start(); echo $_smarty_tpl->tpl_vars['filter_qstring']->value; ?> &filter_id=<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter']->value['filter_id'], ENT_QUOTES, 'UTF-8'); ?> &<?php if ($_REQUEST['features_hash']) { ?> &features_hash=<?php echo htmlspecialchars($_REQUEST['features_hash'], ENT_QUOTES, 'UTF-8'); } list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <li class="ty-product-filters__group" id="view_all_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> "> <?php $_smarty_tpl->tpl_vars["capture_q"] = new Smarty_variable(rawurlencode(Smarty::$_smarty_vars['capture']['q']), null, 0); ?> <a href="<?php echo htmlspecialchars(fn_url("product_features.view_all?q=" . (string) $_smarty_tpl->tpl_vars['capture_q']->value), ENT_QUOTES, 'UTF-8'); ?> " rel="nofollow" class="ty-product-filters__extra-link ty-extra-link"><?php echo $_smarty_tpl->__("view_all"); ?> </a> </li> <?php } ?> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]); if (!empty($_capture_buffer)) { if (isset($_capture_assign)) { $_smarty_tpl->assign($_capture_assign, ob_get_contents()); } if (isset($_capture_append)) { $_smarty_tpl->append($_capture_append, ob_get_contents()); } Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean(); } else { $_smarty_tpl->capture_error(); } ?> <?php if (fn_is_not_empty($_smarty_tpl->tpl_vars['filter']->value['more_ranges'])) { ?> <?php $_smarty_tpl->tpl_vars["cookie_name_show_more"] = new Smarty_variable("more_ranges_" . (string) $_smarty_tpl->tpl_vars['filter_uid']->value, null, 0); ?> <?php $_smarty_tpl->tpl_vars["more_collapse"] = new Smarty_variable(true, null, 0); ?> <?php if ($_COOKIE[$_smarty_tpl->tpl_vars['cookie_name_show_more']->value]) { ?> <?php $_smarty_tpl->tpl_vars["more_collapse"] = new Smarty_variable(false, null, 0); ?> <?php } ?> <li> <ul id="more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " <?php if ($_smarty_tpl->tpl_vars['more_collapse']->value) { ?> class="hidden"<?php } ?> > <?php $_smarty_tpl->tpl_vars["range"] = new Smarty_Variable(); $_smarty_tpl->tpl_vars["range"]->_loop = false; $_from = $_smarty_tpl->tpl_vars['filter']->value['more_ranges']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars["range"]->key => $_smarty_tpl->tpl_vars["range"]->value) { $_smarty_tpl->tpl_vars["range"]->_loop = true; ?> <?php echo $_smarty_tpl->getSubTemplate("blocks/product_filters/components/variant_item.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('range' => $_smarty_tpl->tpl_vars['range']->value, 'filter' => $_smarty_tpl->tpl_vars['filter']->value, 'ajax_div_ids' => $_smarty_tpl->tpl_vars['ajax_div_ids']->value, 'filter_qstring' => $_smarty_tpl->tpl_vars['filter_qstring']->value, 'reset_qstring' => $_smarty_tpl->tpl_vars['reset_qstring']->value, 'allow_ajax' => $_smarty_tpl->tpl_vars['allow_ajax']->value), 0); ?> <?php } ?> <?php echo Smarty::$_smarty_vars['capture']['view_all']; ?> </ul> </li> <li class="ty-product-filters__extra-block"> <a id="on_more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__extra-link ty-extra-link cm-save-state cm-combination-more_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); if (!$_smarty_tpl->tpl_vars['more_collapse']->value) { ?> hidden<?php } ?> "><?php echo $_smarty_tpl->__("more"); ?> </a> <a id="off_more_ranges_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); ?> " class="ty-product-filters__extra-link ty-extra-link cm-save-state cm-combination-more_<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['filter_uid']->value, ENT_QUOTES, 'UTF-8'); if ($_smarty_tpl->tpl_vars['more_collapse']->value) { ?> hidden<?php } ?> "><?php echo $_smarty_tpl->__("less"); ?> </a> </li> <?php } else { ?> <?php echo Smarty::$_smarty_vars['capture']['view_all']; ?> <?php } ?> </ul><?php } }