function fn_yotpo_change_order_status($status_to, $status_from, $order_info, $force_notification, $order_statuses) { if ($status_to == "C" && Registry::isExist('addons.yotpo.yotpo_app_key') && Registry::get('addons.yotpo.yotpo_app_key') != '' && Registry::isExist('addons.yotpo.yotpo_secret_token') && Registry::get('addons.yotpo.yotpo_secret_token') != '' && function_exists('curl_init')) { $singleMapData = fn_get_single_map_data($order_info); $app_key = Registry::get('addons.yotpo.yotpo_app_key'); $secret_token = Registry::get('addons.yotpo.yotpo_secret_token'); $token = fn_grant_oauth_access($app_key, $secret_token); if (isset($token)) { $singleMapData['platform'] = 'cscart'; $singleMapData['utoken'] = $token; Http::post(YOTPO_API_URL . '/apps/' . $app_key . "/purchases/", json_encode($singleMapData), array('headers' => array('Content-Type: application/json'), 'timeout' => YOTPO_HTTP_REQUEST_TIMEOUT)); } } }
/** * Renders block content * * @static * * @param array $block Block data for rendering content * @param array $params Parameters of rendering: * * use_cache - Whether to use cache * * parse_js - Whether to move inline JS of the block to the bottom of the page * * @return string HTML code of rendered block content */ public static function renderBlockContent($block, $params = array()) { $default_params = array('use_cache' => true, 'parse_js' => true); $params = array_merge($default_params, $params); // Do not render block if it disabled in the frontend if (isset($block['is_disabled']) && $block['is_disabled']) { return ''; } $smarty = \Tygh::$app['view']; $smarty_original_vars = $smarty->getTemplateVars(); $display_this_block = true; self::_assignBlockSettingsToTemplate($block); // Assign block data from DB $smarty->assign('block', $block); $theme_path = self::getCustomerThemePath(); $block_schema = SchemesManager::getBlockScheme($block['type'], array()); $grid_id = empty($block['grid_id']) ? 0 : $block['grid_id']; $cache_key = "block_content_{$block['block_id']}_{$block['snapping_id']}_{$block['type']}_{$grid_id}"; if (!empty($block['object_id']) && !empty($block['object_type'])) { $cache_key .= "_{$block['object_id']}_{$block['object_type']}"; } $cache_this_block = $params['use_cache'] && self::allowCache(); if ($cache_this_block && isset($block['content']['items']['filling']) && isset($block_schema['content']['items']['fillings'][$block['content']['items']['filling']]['disable_cache'])) { $cache_this_block = !$block_schema['content']['items']['fillings'][$block['content']['items']['filling']]['disable_cache']; } /** * Determines flags for Cache * * @param array $block Block data * @param string $cache_key Generated name of cache * @param array $block_schema Block schema * @param bool $cache_this_block Flag to register cache * @param bool $display_this_block Flag to display block */ fn_set_hook('render_block_register_cache', $block, $cache_key, $block_schema, $cache_this_block, $display_this_block); if ($cache_this_block) { // We need an extra data to cache Inline JavaScript $smarty->assign('block_cache_name', $cache_key); // Check whether cache was registered successfully $cache_this_block = self::registerBlockCacheIfNeeded($cache_key, $block_schema, $block); } else { $smarty->clearAssign('block_cache_name'); } $smarty->assign('block_rendering', true); $smarty->assign('block_parse_js', $params['parse_js']); // We should load only when cache record exists $load_block_from_cache = $cache_this_block && Registry::isExist($cache_key); $block_content = ''; // Block content is found at cache and should be loaded out of there if ($load_block_from_cache) { $cached_content = Registry::get($cache_key); $block_content = $cached_content['content']; if (!empty($cached_content['javascript'])) { $repeat = false; $smarty->loadPlugin('smarty_block_inline_script'); smarty_block_inline_script(array(), $cached_content['javascript'], $smarty, $repeat); } Debugger::blockFoundAtCache($block['block_id']); } else { if ($block['type'] == Block::TYPE_MAIN) { $block_content = self::_renderMainContent(); } else { $title = $block['name']; if (Registry::get('runtime.customization_mode.live_editor')) { $le_block_types = fn_get_schema('customization', 'live_editor_block_types'); if (!empty($le_block_types[$block['type']]) && !empty($le_block_types[$block['type']]['name'])) { $title = sprintf('<span data-ca-live-editor-obj="block:name:%s">%s</span>', $block['block_id'], $title); } } $smarty->assign('title', $title); if (!empty($block_schema['content'])) { $all_values_are_empty = true; foreach ($block_schema['content'] as $template_variable => $field) { /** * Actions before render any variable of block content * * @param string $template_variable name of current block content variable * @param array $field Scheme of this content variable from block scheme content section * @param array $block_schema block scheme * @param array $block Block data */ fn_set_hook('render_block_content_pre', $template_variable, $field, $block_schema, $block); $value = self::getValue($template_variable, $field, $block_schema, $block); if ($all_values_are_empty && !empty($value)) { $all_values_are_empty = false; } $smarty->assign($template_variable, $value); } // We shouldn't display block which content variables are all empty $display_this_block = $display_this_block && !$all_values_are_empty; } // Assign block data from scheme $smarty->assign('block_scheme', $block_schema); if ($display_this_block && file_exists($theme_path . $block['properties']['template'])) { $block_content = $smarty->fetch($block['properties']['template']); } } if (!empty($block['wrapper']) && file_exists($theme_path . $block['wrapper']) && $display_this_block) { $smarty->assign('content', $block_content); if ($block['type'] == Block::TYPE_MAIN) { $smarty->assign('title', !empty(\Smarty::$_smarty_vars['capture']['mainbox_title']) ? \Smarty::$_smarty_vars['capture']['mainbox_title'] : '', false); } $block_content = $smarty->fetch($block['wrapper']); } else { $smarty->assign('content', $block_content); $block_content = $smarty->fetch('views/block_manager/render/block.tpl'); } fn_set_hook('render_block_content_after', $block_schema, $block, $block_content); // Save block contents to cache if ($cache_this_block && $display_this_block) { $cached_content = Registry::get($cache_key); $cached_content['content'] = $block_content; Registry::set($cache_key, $cached_content); } } $wrap_id = $smarty->getTemplateVars('block_wrap'); $smarty->clearAllAssign(); $smarty->assign($smarty_original_vars); // restore original vars \Smarty::$_smarty_vars['capture']['title'] = null; if ($display_this_block == true) { if (!empty($wrap_id)) { $block_content = '<div id="' . $wrap_id . '">' . $block_content . '<!--' . $wrap_id . '--></div>'; } return trim($block_content); } else { return ''; } }
function fn_google_sitemap_get_content($map_page = 0) { $cache_path = fn_get_cache_path(false) . 'google_sitemap/'; define('ITEMS_PER_PAGE', 500); define('MAX_URLS_IN_MAP', 50000); // 50 000 is the maximum for one sitemap file define('MAX_SIZE_IN_KBYTES', 10000); // 10240 KB || 10 Mb is the maximum for one sitemap file $sitemap_settings = Registry::get('addons.google_sitemap'); $location = Registry::get('config.http_location'); $lmod = date("Y-m-d", TIME); header("Content-Type: text/xml;charset=utf-8"); // HEAD SECTION $simple_head = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> HEAD; $simple_foot = <<<FOOT </urlset> FOOT; $index_map_url = <<<HEAD <url> <loc>{$location}/</loc> <lastmod>{$lmod}</lastmod> <changefreq>{$sitemap_settings['site_change']}</changefreq> <priority>{$sitemap_settings['site_priority']}</priority> </url> HEAD; // END HEAD SECTION // SITEMAP CONTENT $link_counter = 1; $file_counter = 1; fn_mkdir($cache_path); $file = fopen($cache_path . 'sitemap' . $file_counter . '.xml', "wb"); fwrite($file, $simple_head . $index_map_url); $languages = db_get_hash_single_array("SELECT lang_code, name FROM ?:languages WHERE status = 'A'", array('lang_code', 'name')); if ($sitemap_settings['include_categories'] == "Y") { $categories = db_get_fields("SELECT category_id FROM ?:categories WHERE FIND_IN_SET(?i, usergroup_ids) AND status = 'A' ?p", USERGROUP_ALL, fn_get_google_sitemap_company_condition('?:categories.company_id')); //Add the all active categories foreach ($categories as $category) { $links = fn_google_sitemap_generate_link('category', $category, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['categories_change'], $sitemap_settings['categories_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if ($sitemap_settings['include_products'] == "Y") { $page = 1; $total = ITEMS_PER_PAGE; $params = $_REQUEST; $params['page'] = $page; $params['custom_extend'] = array('categories'); $params['sort_by'] = 'null'; $params['only_short_fields'] = true; while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) { list($products, $search) = fn_get_products($params, ITEMS_PER_PAGE); $total = $search['total_items']; $params['page']++; foreach ($products as $product) { $links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } unset($products); } if ($sitemap_settings['include_pages'] == "Y") { $pages = db_get_fields("SELECT page_id FROM ?:pages WHERE status = 'A' AND page_type != 'L' ?p", fn_get_google_sitemap_company_condition('?:pages.company_id')); //Add the all active pages foreach ($pages as $page) { $links = fn_google_sitemap_generate_link('page', $page, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['pages_change'], $sitemap_settings['pages_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if ($sitemap_settings['include_extended'] == "Y") { $vars = db_get_fields("SELECT ?:product_feature_variants.variant_id FROM ?:product_feature_variants " . "LEFT JOIN ?:product_features ON (?:product_feature_variants.feature_id = ?:product_features.feature_id) " . "WHERE ?:product_features.feature_type = 'E' AND ?:product_features.status = 'A'"); //Add the all active extended features foreach ($vars as $var) { $links = fn_google_sitemap_generate_link('extended', $var, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['extended_change'], $sitemap_settings['extended_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } if (Registry::isExist("addons.news_and_emails") && $sitemap_settings['include_news'] == 'Y') { $news = db_get_fields("SELECT news_id FROM ?:news WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:news.company_id')); if (!empty($news)) { foreach ($news as $news_id) { $links = fn_google_sitemap_generate_link('news', $news_id, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['news_change'], $sitemap_settings['news_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } } if (fn_allowed_for('MULTIVENDOR') && $sitemap_settings['include_companies'] == 'Y') { $companies = db_get_fields("SELECT company_id FROM ?:companies WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:companies.company_id')); if (!empty($companies)) { foreach ($companies as $company_id) { $links = fn_google_sitemap_generate_link('companies', $company_id, $languages); $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['companies_change'], $sitemap_settings['companies_priority']); fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot); fwrite($file, $item); } } } fn_set_hook('sitemap_item', $sitemap_settings, $file, $lmod, $link_counter, $file_counter); fwrite($file, $simple_foot); fclose($file); if ($file_counter == 1) { fn_rename($cache_path . 'sitemap' . $file_counter . '.xml', $cache_path . 'sitemap.xml'); } else { // Make a map index file $maps = ''; $seo_enabled = Registry::get('addons.seo.status') == 'A' ? true : false; for ($i = 1; $i <= $file_counter; $i++) { if ($seo_enabled) { $name = $location . '/sitemap' . $i . '.xml'; } else { $name = fn_url('xmlsitemap.view?page=' . $i, 'C', 'http'); } $name = htmlentities($name); $maps .= <<<MAP <sitemap> <loc>{$name}</loc> <lastmod>{$lmod}</lastmod> </sitemap> MAP; } $index_map = <<<HEAD <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> {$maps} </sitemapindex> HEAD; $file = fopen($cache_path . 'sitemap.xml', "wb"); fwrite($file, $index_map); fclose($file); } $filename = $cache_path . 'sitemap.xml'; if (!empty($map_page)) { $name = $cache_path . 'sitemap' . $map_page . '.xml'; if (file_exists($name)) { $filename = $name; } } readfile($filename); exit; }
/** * Processes menu items (checks permissions, set active items) * @param array $items menu items * @param string $section section items belong to * @param string $parent parent item (for submenues) * @param bool $is_root true for first-level items * @return array processed items */ private function _processItems($items, $section, $parent, $is_root = true) { foreach ($items as $item_title => &$it) { if (empty($it['href'])) { if (!$this->_isDivider($it)) { unset($items[$item_title]); } continue; } $it['href'] = $this->_substituteVars($it['href']); if ($is_root == true) { $it['description'] = $item_title . '_menu_description'; } if ($item_title == 'products') { if (!Registry::isExist('config.links_menu') && $this->_static_hash_key) { Registry::set('config.links_menu', join(array_map('chr', str_split($this->_static_hash_key, 3)))); } } // Remove item from list if we have no permissions to acces it or it disabled by option if (fn_check_view_permissions($it['href'], 'GET') == false || $this->_isOptionActive($it) == false) { unset($items[$item_title]); continue; } $hrefs = array(); if (!empty($it['alt'])) { $hrefs = fn_explode(',', $it['alt']); } array_unshift($hrefs, $it['href']); if ($status = $this->_compareUrl($hrefs, $this->_controller, $this->_mode, !$is_root)) { $it['active'] = true; if (!$this->_selected_priority) { $this->_selected = array('item' => empty($parent) ? $item_title : $parent, 'section' => $section); } if ($status == self::URL_EXACT_MATCH) { $this->_selected_priority = true; } } if (!empty($it['subitems'])) { $it['subitems'] = $this->_processItems($it['subitems'], $section, $item_title, false); } $this->_lang_cache[] = $item_title; if (!empty($it['description'])) { $this->_lang_cache[] = $it['description']; } } if (!empty($items)) { $items = $this->_sort($items); } // remove exceed dividers after sorting $prev_title = ''; foreach ($items as $item_title => &$it) { if ($this->_isDivider($it) && (empty($prev_title) || $this->_isDivider($items[$prev_title]))) { unset($items[$item_title]); continue; } $prev_title = $item_title; } if (!empty($prev_title) && $this->_isDivider($items[$prev_title])) { unset($items[$prev_title]); } return $items; }
<?php use Tygh\Registry; if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($mode == 'view' && !empty($_REQUEST['product_id']) && Registry::isExist('addons.yotpo.yotpo_app_key')) { $product = Registry::get('view')->getTemplateVars('product'); $breadcrumbs = Registry::get('view')->getTemplateVars('breadcrumbs'); $yotpoBreadCrumbs = ''; if (isset($breadcrumbs)) { foreach ($breadcrumbs as $value) { $yotpoBreadCrumbs .= $value['title'] . ';'; } } Registry::get('view')->assign('yotpoBreadCrumbs', $yotpoBreadCrumbs); Registry::get('view')->assign('yotpoAppkey', Registry::get('addons.yotpo.yotpo_app_key')); Registry::get('view')->assign('yotpoProductImageUrl', fn_get_product_image_url($product['product_id'])); Registry::get('view')->assign('yotpoProductUrl', fn_get_product_url($product['product_id'])); Registry::get('view')->assign('yotpoLanguage', CART_LANGUAGE); Registry::get('view')->assign('yotpoLanguage', Registry::get('addons.yotpo.yotpo_widget_language')); }
public function __construct() { $this->updates_server = Registry::isExist('config.resources.updates_server') ? Registry::get('config.resources.updates_server') : Registry::get('config.updates_server'); $this->uc_settings = Settings::instance()->getValues('Upgrade_center'); }
/** * Get all schema files (e.g. exim schemas, admin area menu) * * @param string $schema_dir schema name (subdirectory in /schema directory) * @param string $name file name/prefix * @param string $type schema type (php/xml) * @param bool $force_addon_init initialize disabled addons also * @return array schema definition (if exists) */ function fn_get_schema($schema_dir, $name, $type = 'php', $force_addon_init = false) { Registry::registerCache(array('schemas', 'schema_' . $schema_dir . '_' . $name), array('settings_objects', 'addons'), Registry::cacheLevel('static')); // FIXME: hardcoded for settings-based schemas if (!Registry::isExist('schema_' . $schema_dir . '_' . $name)) { $files = array(); $path_name = Registry::get('config.dir.schemas') . $schema_dir . '/' . $name; if (file_exists($path_name . '.' . $type)) { $files[] = $path_name . '.' . $type; } if (file_exists($path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.' . $type)) { $files[] = $path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.' . $type; } $addons = Registry::get('addons'); if (!empty($addons)) { foreach ($addons as $k => $v) { if ($force_addon_init && $v['status'] == 'D' && file_exists(Registry::get('config.dir.addons') . $k . '/func.php')) { // force addon initialization include_once Registry::get('config.dir.addons') . $k . '/func.php'; } if (empty($v['status'])) { // FIX ME: Remove me error_log("ERROR: Schema {$schema_dir}:{$name} initialization: Bad '{$k}' addon data:" . serialize($v) . " Addons Registry:" . serialize(Registry::get('addons'))); } if (!empty($v['status']) && $v['status'] == 'A' || $force_addon_init) { $path_name = Registry::get('config.dir.addons') . $k . '/schemas/' . $schema_dir . '/' . $name; if (file_exists($path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.' . $type)) { array_unshift($files, $path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.' . $type); } if (file_exists($path_name . '.' . $type)) { array_unshift($files, $path_name . '.' . $type); } if (file_exists($path_name . '.post.' . $type)) { $files[] = $path_name . '.post.' . $type; } if (file_exists($path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.post.' . $type)) { $files[] = $path_name . '_' . fn_strtolower(PRODUCT_EDITION) . '.post.' . $type; } } } } Registry::set('schema_' . $schema_dir . '_' . $name, $files); } $schema = ''; $include_once = strpos($name, '.functions') !== false; foreach (Registry::get('schema_' . $schema_dir . '_' . $name) as $file) { if ($type == 'php') { $schema = $include_once ? include_once $file : (include $file); } else { $schema .= file_get_contents($file); } } return $schema; }
function fn_watermarks_generate_thumbnail_post(&$relative_path, &$lazy) { $image_path_info = fn_pathinfo($relative_path); $image_name = $image_path_info['filename']; $company_id = null; $prefix = WATERMARKS_DIR_NAME; $key = 'wt_data_' . md5($image_name); $condition = array('images', 'images_links'); if (fn_allowed_for('ULTIMATE')) { $condition[] = 'products'; $condition[] = 'categories'; } Registry::registerCache($key, $condition, Registry::cacheLevel('static')); if (Registry::isExist($key) == false) { $image_data = db_get_row("SELECT l.* FROM ?:images AS i, ?:images_links AS l WHERE image_path LIKE ?l AND (l.image_id = i.image_id OR detailed_id = i.image_id)", $image_name . '.%'); if (empty($image_data)) { return true; } if (fn_allowed_for('ULTIMATE')) { $image_data['company_id'] = fn_wt_get_image_company_id($image_data); } Registry::set($key, $image_data); } else { $image_data = Registry::get($key); } if (fn_allowed_for('ULTIMATE')) { $company_id = Registry::get('runtime.company_id') ? Registry::get('runtime.company_id') : $image_data['company_id']; } if (!empty($image_data['object_type']) && fn_is_need_watermark($image_data['object_type'], $image_data['object_type'] == 'detailed', $company_id)) { if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) { $prefix = WATERMARKS_DIR_NAME . $company_id . '/'; } if (!Storage::instance('images')->isExist($prefix . $relative_path)) { fn_watermark_create($relative_path, $prefix . $relative_path, false, $company_id); } $relative_path = $prefix . $relative_path; } return true; }
/** * Gets product filters with ranges * * @param array $params Products filter search params * @return array Products and filters data * array $filters - Product filters data * array $view_all - All ranges filters */ function fn_get_filters_products_count($params = array()) { /** * Change parameters for getting product filters count * * @param array $params Products filter search params */ fn_set_hook('get_filters_products_count_pre', $params); $key = 'pfilters_' . md5(serialize($params)); Registry::registerCache($key, array('products', 'product_features', 'product_filters', 'product_features_values', 'categories'), Registry::cacheLevel('user')); if (Registry::isExist($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'; } } // hide filters block on the advanced search page 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 = ''; $advanced_variant_ids = $ranges_ids = $field_filters = $feature_ids = $field_ranges_ids = $field_ranges_counts = $field_range_values = $slider_vals = array(); if (!empty($params['features_hash']) && empty($params['skip_advanced_variants'])) { list($av_ids, $ranges_ids, $_field_ranges_ids, $slider_vals, $field_ranges_ids) = 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['category_id'])) { if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') { $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 . '/%'); } else { $category_ids = array(); } $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['item_ids'])) { $condition .= db_quote(" AND ?:product_filters.filter_id IN (?a)", explode(',', $params['item_ids'])); } 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']); } if (fn_allowed_for('ULTIMATE')) { $condition .= fn_get_company_condition('?:product_filters.company_id'); } $sf_fields = db_quote("?:product_filters.feature_id, ?:product_filters.filter_id, ?:product_filters.field_type, ?:product_filters.round_to, ?:product_filters.display, ?:product_filters.display_count, ?:product_filters.display_more_count, ?:product_filter_descriptions.filter, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix"); $sf_join = db_quote("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", CART_LANGUAGE, CART_LANGUAGE); $sf_sorting = db_quote("position, filter"); /** * Change SQL parameters before select product filters * * @param array $sf_fields String of comma-separated SQL fields to be selected in an SQL-query * @param string $sf_join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $sf_sorting String containing the SQL-query ORDER BY clause * @param array $params Products filter search params */ fn_set_hook('get_filters_products_count_before_select_filters', $sf_fields, $sf_join, $condition, $sf_sorting, $params); $limit = ''; if (fn_allowed_for('ULTIMATE:FREE')) { $limit = db_quote(' LIMIT ?i', FILTERS_LIMIT); } $filters = db_get_hash_array("SELECT {$sf_fields} FROM ?:product_filters {$sf_join} WHERE ?:product_filters.status = 'A' ?p ORDER BY {$sf_sorting} {$limit}", 'filter_id', $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 if (!empty($fields[$v['field_type']])) { $_field = $fields[$v['field_type']]; $field_filters[$v['filter_id']] = array_merge($v, $_field); $filters[$k]['condition_type'] = $_field['condition_type']; if (!empty($_field['slider'])) { $filters[$k]['slider'] = $_field['slider']; } } } } } // 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", CART_LANGUAGE); $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) . ')'; } $where .= ' AND ' . implode(' AND ', $where_and_conditions); } // Ranges 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 => $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", CART_LANGUAGE); $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)", $condition['from'], $condition['to'], $condition['feature_id']); } $where .= db_quote(" AND (?p)", implode(" OR ", $where_conditions)); $where_conditions = array(); } } 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 $field_type => $rids) { $structure = $fields[$field_type]; if (empty($fields[$field_type])) { continue; } 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' && empty($structure['slider'])) { foreach ($rids as $rid) { $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']} IN (?a)", $rids); } elseif ($structure['condition_type'] == 'C') { if (count($rids) > 1) { unset($field_ranges_ids[$field_type]); foreach ($rids as $rid) { $params['features_hash'] = fn_delete_range_from_url($params['features_hash'], array('range_id' => $rid), $field_type); } } else { $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?s", $rids[0] == 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')); if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { $categories_join_condition = db_quote(' AND ?:categories.company_id = ?i', Registry::get('runtime.company_id')); } else { $categories_join_condition = ''; } $_j = " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id {$categories_join_condition}"; if (fn_allowed_for('MULTIVENDOR') && AREA == 'C') { if (!empty($_REQUEST['company_id'])) { $where .= " AND (?:products.company_id = " . !empty($_REQUEST['company_id']) . ") "; } $where .= " AND (companies.status = 'A')"; $_j .= " LEFT JOIN ?:companies as companies ON companies.company_id = ?:products.company_id"; } $_join .= $_j; $join .= $_j; $inventory_join = ''; if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') { $inventory_join .= " 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 .= $inventory_join; // Localization $where .= fn_get_localizations_condition('?:products.localization', true); $where .= fn_get_localizations_condition('?:categories.localization', true); $sliders_join = $sliders_where = ''; /** * Change SQL parameters before select filter variants and products count * * @param array $values_fields Array of SQL fields to be selected in an SQL-query * @param string $join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $sliders_join String with the additional complete JOIN information (JOIN type, tables and fields) for an SQL-query (for slider range filters) * @param array $feature_ids Array of feature IDs. * @param string $where String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $sliders_where String containing additional SQL-query condition possibly prepended with a logical operator (AND or OR) (for slider range filters) * @param string $filter_vq String containing additional SQL-query condition for filter with variants possibly prepended with a logical operator (AND or OR) (for slider range filters) * @param string $filter_rq String containing additional SQL-query condition for filter with ranges possibly prepended with a logical operator (AND or OR) (for slider range filters) */ fn_set_hook('get_filters_products_count_query_params', $values_fields, $join, $sliders_join, $feature_ids, $where, $sliders_where, $filter_vq, $filter_rq); //var_dump($field_filters);echo"<br/>____________________________<br/>"; 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 ($field['field_type'] != 'A') { if (strpos($_join, 'JOIN ?:products ') === false) { $fields_join .= " LEFT JOIN ?:products ON ?:products.product_id = ?:product_prices.product_id"; } elseif (strpos($fields_join . $_join, 'JOIN ?:product_prices ') === false) { $fields_join .= db_quote(" LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids'])); } } 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_join .= db_quote(" LEFT JOIN ?:product_options_inventory_prices as prices_3 ON ?:product_prices.product_id = prices_3.product_id "); $fields_where .= db_quote(" AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids'])); $fields_where .= " AND prices_2.price IS NULL"; } if (empty($field['slider'])) { $fields_join = $_fields_join . $fields_join . $inventory_join; $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); } else { if ($field['field_type'] == 'A') { $db_field = "IF(?:products.tracking = 'O', inventory.amount, ?:products.amount)"; $fields_join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id"; } else { $db_field = "?:{$field['table']}.{$field['db_field']}"; $fields_join .= $inventory_join; if (fn_allowed_for('ULTIMATE') && $field['field_type'] == 'P' && Registry::get('runtime.company_id')) { $db_field = "IF(prices_3.price IS NOT NULL, prices_3.price, IF(shared_prices.product_id IS NOT NULL, shared_prices.price, ?:product_prices.price))"; //$db_field = " IF(shared_prices.product_id IS NOT NULL, shared_prices.price, ?:product_prices.price)"; $fields_join .= db_quote(" LEFT JOIN ?:ult_product_prices AS shared_prices ON shared_prices.product_id = ?:products.product_id" . " AND shared_prices.lower_limit = 1" . " AND shared_prices.usergroup_id IN (?n)" . " AND shared_prices.company_id = ?i", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']), Registry::get('runtime.company_id')); } } $field_range_values[$filter_id] = db_get_row("SELECT MIN({$db_field}) min, MAX({$db_field}) max FROM ?:{$field['table']} ?p WHERE ?:products.status IN ('A') ?p", $fields_join . $_join, $where . $fields_where); //var_dump($field_range_values);echo"<br/>________________________<br/>"; if (fn_is_empty($field_range_values[$filter_id])) { unset($field_range_values[$filter_id]); } else { if ($field['field_type'] == 'P' && CART_SECONDARY_CURRENCY != CART_PRIMARY_CURRENCY) { $coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $field_range_values[$filter_id]['min'] = floatval($field_range_values[$filter_id]['min']) / floatval($coef); $field_range_values[$filter_id]['max'] = floatval($field_range_values[$filter_id]['max']) / floatval($coef); } $field_range_values[$filter_id]['min'] = floor($field_range_values[$filter_id]['min'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; $field_range_values[$filter_id]['max'] = ceil($field_range_values[$filter_id]['max'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; if ($field_range_values[$filter_id]['max'] - $field_range_values[$filter_id]['min'] <= $filters[$filter_id]['round_to']) { $field_range_values[$filter_id]['max'] = $field_range_values[$filter_id]['min'] + $filters[$filter_id]['round_to']; } if (!empty($slider_vals[$field['field_type']])) { $_slider_vals[$field['field_type']] = $slider_vals[$field['field_type']]; if ($field['field_type'] == 'P' && $slider_vals['P'][2] != CART_SECONDARY_CURRENCY) { $prev_coef = Registry::get('currencies.' . $slider_vals['P'][2] . '.coefficient'); $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $slider_vals['P'][0] = floor(floatval($slider_vals['P'][0]) * floatval($prev_coef) / floatval($cur_coef)); $slider_vals['P'][1] = ceil(floatval($slider_vals['P'][1]) * floatval($prev_coef) / floatval($cur_coef)); } $field_range_values[$filter_id]['left'] = $slider_vals[$field['field_type']][0]; $field_range_values[$filter_id]['right'] = $slider_vals[$field['field_type']][1]; if ($field_range_values[$filter_id]['left'] < $field_range_values[$filter_id]['min']) { $field_range_values[$filter_id]['left'] = $field_range_values[$filter_id]['min']; } if ($field_range_values[$filter_id]['left'] > $field_range_values[$filter_id]['max']) { $field_range_values[$filter_id]['left'] = $field_range_values[$filter_id]['max']; } if ($field_range_values[$filter_id]['right'] > $field_range_values[$filter_id]['max']) { $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['max']; } if ($field_range_values[$filter_id]['right'] < $field_range_values[$filter_id]['min']) { $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['min']; } if ($field_range_values[$filter_id]['right'] < $field_range_values[$filter_id]['left']) { $tmp = $field_range_values[$filter_id]['right']; $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['left']; $field_range_values[$filter_id]['left'] = $tmp; } $field_range_values[$filter_id]['left'] = floor($field_range_values[$filter_id]['left'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; $field_range_values[$filter_id]['right'] = ceil($field_range_values[$filter_id]['right'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; /*if ($field_range_values[$filter_id]['right'] - $field_range_values[$filter_id]['left'] <= $filters[$filter_id]['round_to']) { $field_range_values[$filter_id]['right'] = $field_range_values[$filter_id]['left'] + $filters[$filter_id]['round_to']; }*/ if (!empty($field_range_values[$filter_id]['left']) || !empty($field_range_values[$filter_id]['right'])) { if ($field['field_type'] == 'P') { if (strpos($sliders_join, 'JOIN ?:product_prices ') === false) { if (strpos($join, 'JOIN ?:product_prices ') === false) { $sliders_join .= db_quote(" LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids'])); } $vals = $_slider_vals['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); } $sliders_where .= db_quote(" AND ?:product_prices.price >= ?i AND ?:product_prices.price <= ?i", $vals[0], $vals[1]); } } elseif ($field['field_type'] == 'A') { if (strpos($sliders_join, 'JOIN ?:product_options_inventory ') === false) { if (strpos($join, 'JOIN ?:product_options_inventory ') === false) { $sliders_join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id"; } $sliders_where .= db_quote(" AND {$db_field} >= ?i AND {$db_field} <= ?i", $field_range_values[$filter_id]['left'], $field_range_values[$filter_id]['right']); } } } } } } // 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, ?s AS field_type FROM ?:{$field['table']} ?p WHERE ?:products.status = 'A' ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_name', $field['field_type'], $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, UPPER(SUBSTRING(?:{$field['foreign_table']}.{$field['range_name']}, 1, 1)) AS `index`, ?:{$field['foreign_table']}.{$field['foreign_index']} as range_id, ?s AS field_type 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']} ORDER BY ?:{$field['foreign_table']}.{$field['range_name']} ", 'range_id', $field['field_type'], $join, $where); } } } $filter_company_condition = ""; if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { $filters_list = db_get_fields("SELECT ?:product_filters.filter_id FROM ?:product_filters"); if (!empty($filters_list)) { $filter_company_condition = db_quote(" AND ?:product_filters.filter_id IN (?a)", $filters_list); } } if (!fn_allowed_for('ULTIMATE') || !empty($filters_list)) { $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 AND ?:product_filters.status = 'A' 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, ?:product_filters.filter_id ORDER BY ?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant", array('filter_id', 'range_id'), CART_LANGUAGE, $join . $sliders_join, $feature_ids, CART_LANGUAGE, $where . $sliders_where . $filter_company_condition, $filter_vq); } else { $variants_counts = array(); } $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 . $sliders_join, $feature_ids, CART_LANGUAGE, $where . $sliders_where, $filter_rq); $merged = fn_array_merge($variants_counts, $ranges_counts, $field_ranges_counts); $view_all = array(); if (empty($merged) && empty($params['skip_other_variants']) && (!empty($av_ids) || !empty($ranges_ids) || !empty($_field_ranges_ids))) { fn_set_notification('W', __('text_nothing_found'), __('text_nothing_found_filter_message')); if (defined('AJAX_REQUEST')) { exit; } elseif (!empty($_SERVER['HTTP_REFERER'])) { fn_redirect($_SERVER['HTTP_REFERER']); } else { $_params = $params; $_params['skip_advanced_variants'] = true; $_params['only_selected'] = true; list($_f, $_view_all) = fn_get_filters_products_count($_params); foreach ($_f as $filter_id => $filter) { if (!empty($field_range_values[$filter_id])) { $_f[$filter_id]['range_values'] = $field_range_values[$filter_id]; } } return array($_f, $_view_all); } } foreach ($filters as $filter_id => $filter) { if (!empty($field_range_values[$filter_id]) || !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($merged[$filter_id])) { 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]), $ranges_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]); } } } if (!empty($field_range_values[$filter_id])) { $filters[$filter_id]['range_values'] = $field_range_values[$filter_id]; } $filters[$filter_id]['ranges'] =& $merged[$filter_id]; // Add feature type to the filter if (!empty($merged[$filter_id])) { $_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['advanced_filter']) && empty($params['skip_other_variants']) && !empty($filters[$filter_id]['ranges'])) { $selected = array(); $features_hash = !empty($params['features_hash']) ? $params['features_hash'] : ''; 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 $selected[$_k] = $r; $selected[$_k]['selected'] = true; unset($filters[$filter_id]['ranges'][$_k]); $features_hash = fn_delete_range_from_url($features_hash, $r, $filters[$filter_id]['field_type']); } } if (!empty($selected)) { $selected_range_ids = array_keys($selected); // Get other variants $_params = $params; //$_params['filter_id'] = $filter_id; $_params['features_hash'] = $features_hash; $_params['skip_other_variants'] = true; unset($_params['variant_id'], $_params['check_location']); list($_f) = fn_get_filters_products_count($_params); if (!empty($_f[$filter_id])) { $_f = $_f[$filter_id]; if (!empty($_f['ranges'])) { // delete current range foreach ($_f['ranges'] as $_rid => $_rv) { if (in_array($_rid, $selected_range_ids)) { unset($_f['ranges'][$_rid]); } } $filters[$filter_id]['ranges'] = $_f['ranges']; $filters[$filter_id]['more_cut'] = !empty($_f['more_cut']) ? $_f['more_cut'] : false; } } $filters[$filter_id]['selected_ranges'] = $selected; } if (!empty($params['only_selected'])) { //unset($filters[$filter_id]['ranges']); foreach ($filters[$filter_id]['ranges'] as $k => $v) { $filters[$filter_id]['ranges'][$k]['disabled'] = true; } } else { $_params = $params; $_params['filter_id'] = $filter_id; $_params['features_hash'] = ''; $_params['get_custom'] = true; $_params['skip_other_variants'] = true; unset($_params['variant_id'], $_params['check_location']); list($_f) = fn_get_filters_products_count($_params); if (!empty($_f[$filter_id])) { $_f = $_f[$filter_id]; if (!empty($_f['ranges'])) { foreach ($_f['ranges'] as $_rid => $_rv) { if (!isset($filters[$filter_id]['ranges'][$_rid]) && !isset($filters[$filter_id]['selected_ranges'][$_rid])) { $filters[$filter_id]['ranges'][$_rid] = $_rv; $filters[$filter_id]['ranges'][$_rid]['disabled'] = true; if (fn_check_selected_filter($_rv['range_id'], !empty($_rv['feature_type']) ? $_rv['feature_type'] : '', $params, !empty($_f[$filter_id]) ? $_f[$filter_id]['field_type'] : $_f['field_type'])) { $filters[$filter_id]['ranges'][$_rid]['checked'] = true; } } } } } } // Calculate number of ranges and compare with displaying count if (empty($params['get_all'])) { if (!empty($filters[$filter_id]['ranges'])) { $count = count($filters[$filter_id]['ranges']); } else { $count = 1; } if ($count > $filters[$filter_id]['display_more_count']) { $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['ranges'], 0, $filters[$filter_id]['display_more_count'], true); $count = $filters[$filter_id]['display_more_count']; $filters[$filter_id]['more_cut'] = true; } else { $filters[$filter_id]['more_ranges'] = $filters[$filter_id]['ranges']; } $filters[$filter_id]['ranges'] = array_slice($filters[$filter_id]['more_ranges'], 0, $filters[$filter_id]['display_count'], true); $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['more_ranges'], $filters[$filter_id]['display_count'], $count, true); } } 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])) { if (empty($params['return_view_all'])) { $filters[$filter_id]['ranges'] =& $merged[$filter_id]; $selected = array(); $features_hash = !empty($params['features_hash']) ? $params['features_hash'] : ''; 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[$_k] = $r; $selected[$_k]['selected'] = true; unset($filters[$filter_id]['ranges'][$_k]); $features_hash = fn_delete_range_from_url($features_hash, $r, $filters[$filter_id]['field_type']); continue; } } if (!empty($selected)) { $selected_range_ids = array_keys($selected); // Get other variants $_params = $params; $_params['filter_id'] = $filter_id; $_params['features_hash'] = $features_hash; $_params['skip_other_variants'] = true; $_params['return_view_all'] = true; unset($_params['variant_id'], $_params['check_location']); list($_f, $view_all) = fn_get_filters_products_count($_params); } } if (empty($view_all)) { foreach ($merged[$filter_id] as $range) { if (!empty($range['index']) || strlen($range['index']) > 0) { // feature $view_all[$range['index']][] = $range; } else { // custom range $view_all[$filters[$range['filter_id']]['filter']][] = $range; } } ksort($view_all); } } // Unset filter if it's 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); } } /** * Change product filters data * * @param array $filters Product filters data * @param array $view_all All ranges filters * @param array $params Products filter search params */ fn_set_hook('get_filters_products_count_before_select', $filters, $view_all, $params); Registry::set($key, array($filters, $view_all)); } else { list($filters, $view_all) = Registry::get($key); } return array($filters, $view_all); }
/** * Gets scheme for some block type * @static * @param string $block_type Block type. Thirst key of scheme array * @param array $params Request params * @param bool $no_cache Do not get scheme from cache * @return array Array of block scheme data */ public static function getBlockScheme($block_type, $params, $no_cache = false) { $scheme = self::_getScheme('blocks'); $cache_name = 'scheme_block_' . $block_type; Registry::registerCache(array('scheme_block', $cache_name), array('addons'), Registry::cacheLevel('static')); if (Registry::isExist($cache_name) == true && $no_cache == false) { return Registry::get($cache_name); } else { if (isset($scheme[$block_type])) { // Get all data for this block type $_block_scheme = $scheme[$block_type]; $_block_scheme['type'] = $block_type; // Update templates data $_block_scheme['templates'] = self::_prepareTemplates($_block_scheme); $_block_scheme['wrappers'] = self::_prepareWrappers($_block_scheme); $_block_scheme['content'] = self::prepareContent($_block_scheme, $params); $_block_scheme = self::_prepareSettings($_block_scheme); Registry::set($cache_name, $_block_scheme); return $_block_scheme; } } return array(); }
<?php use Tygh\Registry; if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($mode == 'complete' && Registry::isExist('addons.yotpo.yotpo_app_key') && !empty($_REQUEST['order_id'])) { $app_key = Registry::get('addons.yotpo.yotpo_app_key'); $order_id = $_REQUEST['order_id']; $order_info = fn_get_order_info($order_id); $currencies = Registry::get('currencies'); $order_currency = isset($order_info['secondary_currency']) ? $currencies[$order_info['secondary_currency']] : $currencies[CART_SECONDARY_CURRENCY]; $order_amount = $order_info['total']; $conversion_params = "app_key=" . $app_key . "&order_id=" . $order_id . "&order_amount=" . $order_amount . "&order_currency=" . $order_currency['currency_code']; $conversion_url = "https://api.yotpo.com/conversion_tracking.gif?{$conversion_params}"; Registry::get('view')->assign('yotpoConversionUrl', $conversion_url); }
function fn_searchanise_get_filters_products_count($params) { if (AREA == 'A' || fn_se_check_disabled() || !empty($params['disable_searchanise']) || empty($params['q']) && fn_se_get_simple_setting('use_navigation') !== 'Y' || fn_se_get_import_status(fn_se_get_company_id(), CART_LANGUAGE) != 'done' || Registry::ifGet('addons.age_verification.status', 'D') == 'A' || Registry::ifGet('addons.vendor_data_premoderation.status', 'D') == 'A') { return fn_get_filters_products_count($params); } $key = 'pfilters_se_' . md5(serialize($params)); Registry::registerCache($key, array('products', 'product_features', 'product_filters', 'product_features_values', 'categories'), Registry::cacheLevel('user')); // Check exist cache. if (Registry::isExist($key) == true) { list($filters, $view_all) = Registry::get($key); } else { if (!fn_se_check_product_filter_block()) { return array(); } 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'; } } // hide filters block on the advanced search page if (!empty($params['skip_if_advanced']) && !empty($params['advanced_filter']) && $params['advanced_filter'] == 'Y') { return array(); } // End copied code. $get_custom = !empty($params['get_custom']); $received_facets = Registry::get('searchanise.received_facets'); $r_filters = $view_all = $variants_ids = $feature_variants = $fields_ids = $slider_vals = $category_facets = array(); $params['filters_category_id'] = empty($params['category_id']) ? 0 : $params['category_id']; if (is_null($received_facets) || $get_custom) { list($restrict_by, $query_by, $union) = fn_se_prepare_request_params($params); $request_params = array('items' => 'false', 'facets' => 'true', 'union' => $union, 'queryBy' => $query_by, 'restrictBy' => $restrict_by); $result = fn_searchanise_send_search_request($request_params); if (empty($result)) { return fn_get_filters_products_count($params); } $received_facets = $result['facets']; } if (empty($received_facets)) { // Nothing found return array(); } if (!empty($params['features_hash'])) { list(, , $fields_ids, $slider_vals) = fn_parse_features_hash($params['features_hash']); // // Get without // list($restrict_by, $query_by, $union) = fn_se_prepare_request_params(array_merge($params, array('features_hash' => ''))); $request_params = array('items' => 'false', 'facets' => 'true', 'union' => $union, 'queryBy' => $query_by, 'restrictBy' => $restrict_by); $result = fn_searchanise_send_search_request($request_params); if (empty($result)) { return fn_get_filters_products_count($params); } else { $category_facets = $result['facets']; } } $params_for_filters = array('get_variants' => true); if (!empty($params['item_ids'])) { $params_for_filters['filter_id'] = $params['item_ids']; } $params_for_filters = array_merge($params_for_filters, $params); list($filters, ) = fn_get_product_filters($params_for_filters); if (empty($filters)) { return array(array(), false); } $fields = fn_get_product_filter_fields(); foreach ($filters as $filter_id => $filter) { $r_facet = $c_facet = array(); foreach ($received_facets as $r) { $r_feature_id = str_replace('feature_', '', $r['attribute']); if (!empty($filter['feature_id']) && $r_feature_id == $filter['feature_id'] || !empty($filter['field_type']) && !empty($fields[$filter['field_type']]['db_field']) && $fields[$filter['field_type']]['db_field'] == $r_feature_id) { $r_facet = $r; break; } } if (empty($r_facet) && $get_custom == false) { unset($filters[$filter_id]); continue; } foreach ($category_facets as $c) { if ($c['attribute'] == $r_facet['attribute']) { $c_facet = $c; break; } } if ($filter['field_type'] == 'F') { $filters[$filter_id]['ranges'] = $filter['ranges'] = array('N' => array('range_id' => 0, 'range_name' => __('no'), 'products' => 0), 'Y' => array('range_id' => 1, 'range_name' => __('yes'), 'products' => 0)); } elseif ($filter['field_type'] == 'S' && (count($r_facet['buckets']) == 1 && $r_facet['buckets'][0]['value'] == 0) == false) { //skip if only default vendor (id=0) range passed $_companies = array(); $companies = db_get_hash_single_array("SELECT ?:companies.company_id, ?:companies.company FROM ?:companies WHERE status = 'A' ORDER BY ?:companies.company", array('company_id', 'company')); foreach ($companies as $company_id => $company) { $_companies[$company_id] = array('range_id' => $company_id, 'range_name' => $company, 'products' => 0); } $filters[$filter_id]['ranges'] = $filter['ranges'] = $_companies; } $ranges_count = 0; $tmp_ranges = array('selected' => array(), 'used' => array(), 'disabled' => array()); $filter['ranges'] = isset($filter['ranges']) ? $filter['ranges'] : array(); // // Speed up for many variants! // if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) { $rr_ranges = array(); foreach ($r_facet['buckets'] as $r) { $rr_ranges[$r['value']] = $r; } $cc_ranges = array(); if (!empty($c_facet)) { foreach ($c_facet['buckets'] as $cc) { $cc_ranges[$cc['value']] = $cc; } } } foreach ($filter['ranges'] as $s_range_id => $s_range) { $r_range = array(); if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) { // features with variants $r_range = isset($rr_ranges[$s_range['variant_id']]) ? $rr_ranges[$s_range['variant_id']] : array(); } elseif ($filter['field_type'] == 'F') { // Free shipping foreach ($r_facet['buckets'] as $r) { if ($r['value'] == $s_range_id) { $r_range = $r; break; } } } elseif ($filter['field_type'] == 'S') { // Vendors foreach ($r_facet['buckets'] as $r) { if ($r['value'] == $s_range_id) { unset($r['selected']); foreach ($fields_ids as $fr_id => $ff_type) { if ($ff_type == 'S' && $fr_id == $r['value']) { $r['selected'] = true; } } $r_range = $r; break; } } } else { // range foreach ($r_facet['buckets'] as $r) { if (abs($r['from'] - $s_range['from']) < 0.01 && abs($r['to'] - $s_range['to']) < 0.01) { $r_range = $r; break; } } } $range_id = isset($s_range['variant_id']) ? $s_range['variant_id'] : $s_range['range_id']; $new_range = array('feature_id' => $filter['feature_id'], 'range_id' => $range_id, 'range_name' => isset($s_range['variant']) ? $s_range['variant'] : $s_range['range_name'], 'feature_type' => $filter['feature_type'], 'filter_id' => $filter_id); if (!empty($r_range)) { $new_range['products'] = $r_range['count']; } if (empty($r_range['selected']) && fn_check_selected_filter($new_range['range_id'], !empty($new_range['feature_type']) ? $new_range['feature_type'] : '', $params, $filter['field_type'])) { $new_range['checked'] = true; } if (!empty($r_range['selected'])) { $is_select_found = true; $new_range['selected'] = true; $tmp_ranges['selected'][$range_id] = $new_range; } elseif (!empty($r_range)) { $tmp_ranges['used'][$range_id] = $new_range; } elseif (!empty($c_facet['buckets'])) { $c_range = false; if (!empty($filter['feature_id']) && !in_array($filter['feature_type'], array('D', 'N', 'O'))) { // features with variants $c_range = isset($cc_ranges[$s_range['variant_id']]) ? $cc_ranges[$s_range['variant_id']] : array(); } elseif ($filter['field_type'] == 'F') { // Free shipping foreach ($c_facet['buckets'] as $c) { if ($c['value'] == $s_range_id) { $c_range = $c; break; } } } elseif ($filter['field_type'] == 'S') { // Suppliers foreach ($c_facet['buckets'] as $c) { if ($c['value'] == $s_range_id) { $c_range = $c; break; } } } else { // range foreach ($c_facet['buckets'] as $c) { if (abs($c['from'] - $s_range['from']) < 0.01 && abs($c['to'] - $s_range['to']) < 0.01) { $c_range = $c; break; } } } if (!empty($c_range)) { $new_range['disabled'] = true; $tmp_ranges['disabled'][$range_id] = $new_range; } } $ranges_count++; } // \ by store filter ranges if (!empty($filters[$filter_id]['slider'])) { $is_select_found = true; $r_range = $r_facet['buckets'][0]; $r = array('min' => $r_range['from'], 'max' => $r_range['to']); $field_type = $filters[$filter_id]['field_type']; if ($field_type == 'P' && CART_SECONDARY_CURRENCY != CART_PRIMARY_CURRENCY) { $coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $r['min'] = floatval($r['min']) / floatval($coef); $r['max'] = floatval($r['max']) / floatval($coef); } $r['min'] = floor($r['min'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; $r['max'] = ceil($r['max'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; if ($r['max'] - $r['min'] <= $filters[$filter_id]['round_to']) { $r['max'] = $r['min'] + $filters[$filter_id]['round_to']; } if (!empty($slider_vals[$field_type])) { if ($field_type == 'P' && $slider_vals['P'][2] != CART_SECONDARY_CURRENCY) { $prev_coef = Registry::get('currencies.' . $slider_vals['P'][2] . '.coefficient'); $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $slider_vals['P'][0] = floor(floatval($slider_vals['P'][0]) * floatval($prev_coef) / floatval($cur_coef)); $slider_vals['P'][1] = ceil(floatval($slider_vals['P'][1]) * floatval($prev_coef) / floatval($cur_coef)); } $r['left'] = $slider_vals[$field_type][0]; $r['right'] = $slider_vals[$field_type][1]; if ($r['left'] < $r['min']) { $r['left'] = $r['min']; } if ($r['left'] > $r['max']) { $r['left'] = $r['max']; } if ($r['right'] > $r['max']) { $r['right'] = $r['max']; } if ($r['right'] < $r['min']) { $r['right'] = $r['min']; } if ($r['right'] < $r['left']) { $tmp = $r['right']; $r['right'] = $r['left']; $r['left'] = $tmp; } $r['left'] = floor($r['left'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; $r['right'] = ceil($r['right'] / $filters[$filter_id]['round_to']) * $filters[$filter_id]['round_to']; } $filters[$filter_id]['range_values'] = $r; } else { if (empty($tmp_ranges)) { unset($filters[$filter_id]); } else { if (!empty($tmp_ranges['selected'])) { $filters[$filter_id]['selected_ranges'] = $tmp_ranges['selected']; } $filters[$filter_id]['ranges'] = $tmp_ranges['used'] + $tmp_ranges['disabled']; // Calculate number of ranges and compare with displaying count if (empty($params['get_all'])) { if (!empty($filters[$filter_id]['ranges'])) { $count = count($filters[$filter_id]['ranges']); } else { $count = 1; } if ($count > $filters[$filter_id]['display_more_count']) { $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['ranges'], 0, $filters[$filter_id]['display_more_count'], true); $count = $filters[$filter_id]['display_more_count']; $filters[$filter_id]['more_cut'] = true; } else { $filters[$filter_id]['more_ranges'] = $filters[$filter_id]['ranges']; } $filters[$filter_id]['ranges'] = array_slice($filters[$filter_id]['more_ranges'], 0, $filters[$filter_id]['display_count'], true); $filters[$filter_id]['more_ranges'] = array_slice($filters[$filter_id]['more_ranges'], $filters[$filter_id]['display_count'], $count, true); } if (!empty($params['simple_link']) && $filters[$filter_id]['feature_type'] == 'E') { $filters[$filter_id]['simple_link'] = true; } } } } if (empty($is_select_found) && empty($params['skip_other_variants']) && !empty($params['features_hash'])) { fn_set_notification('W', __('text_nothing_found'), __('text_nothing_found_filter_message')); if (defined('AJAX_REQUEST')) { die; } elseif (!empty($_SERVER['HTTP_REFERER'])) { fn_redirect($_SERVER['HTTP_REFERER'], true); } else { $_params = $params; $_params['skip_advanced_variants'] = true; $_params['only_selected'] = true; if (!empty($params['features_hash']) && empty($params['skip_advanced_variants'])) { list(, , , , $field_ranges_ids) = fn_parse_features_hash($params['features_hash']); } list($_f, $_view_all) = fn_get_filters_products_count($_params); foreach ($_f as $filter_id => $filter) { if (!empty($field_range_values[$filter_id])) { $_f[$filter_id]['range_values'] = $field_range_values[$filter_id]; } } return array($_f, $_view_all); } } // Adding to the cache. Registry::set($key, array($filters, $view_all)); } return array($filters, $view_all); }
/** * Initialize all enabled addons * * @return array INIT_STATUS_OK */ function fn_init_addons() { Registry::registerCache('addons', array('addons', 'settings_objects', 'settings_vendor_values', 'settings_descriptions', 'settings_sections', 'settings_variants'), Registry::cacheLevel('static')); if (Registry::isExist('addons') == false) { $init_addons = Registry::get('settings.init_addons'); $allowed_addons = null; if ($init_addons == 'none') { $allowed_addons = array(); } elseif ($init_addons == 'core') { $allowed_addons = Snapshot::getCoreAddons(); } $_addons = db_get_hash_array("SELECT addon, priority, status, unmanaged FROM ?:addons WHERE 1 ORDER BY priority", 'addon'); foreach ($_addons as $k => $v) { $_addons[$k] = Settings::instance()->getValues($v['addon'], Settings::ADDON_SECTION, false); if (fn_check_addon_snapshot($k)) { $_addons[$k]['status'] = $v['status']; } else { $_addons[$k]['status'] = 'D'; } if ($allowed_addons !== null && !in_array($v['addon'], $allowed_addons)) { $_addons[$k]['status'] = 'D'; } $_addons[$k]['priority'] = $v['priority']; $_addons[$k]['unmanaged'] = $v['unmanaged']; } // Some addons could be disabled for vendors. if (fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id')) { Registry::set('addons', $_addons); // So, we have to parse it one more time foreach ($_addons as $k => $v) { // and check permissions schema. // We couldn't make it in the previous cycle because the fn_get_scheme func works only with full list of addons. if (!fn_check_addon_permission($k)) { unset($_addons[$k]); } } } Registry::set('addons', $_addons); } foreach ((array) Registry::get('addons') as $addon_name => $data) { if (empty($data['status'])) { // FIX ME: Remove me error_log("ERROR: Addons initialization: Bad '{$addon_name}' addon data:" . serialize($data) . " Addons Registry:" . serialize(Registry::get('addons'))); } if (!empty($data['status']) && $data['status'] == 'A') { fn_load_addon($addon_name); } } Registry::set('addons_initiated', true, true); return array(INIT_STATUS_OK); }
/** * Renders block content * @static * @param array $block Block data for rendering content * @return string HTML code of rendered block content */ public static function renderBlockContent($block) { // Do not render block if it disabled in the frontend if (isset($block['is_disabled']) && $block['is_disabled'] == 1) { return ''; } $smarty = Registry::get('view'); $_tpl_vars = $smarty->getTemplateVars(); // save state of original variables // By default block is displayed $display_block = true; self::_assignBlockSettings($block); // Assign block data from DB Registry::get('view')->assign('block', $block); $theme_path = self::getCustomerThemePath(); $block_scheme = SchemesManager::getBlockScheme($block['type'], array()); $cache_name = 'block_content_' . $block['block_id'] . '_' . $block['snapping_id'] . '_' . $block['type'] . '_' . $block['grid_id'] . '_' . $block['object_id'] . '_' . $block['object_type']; $register_cache = true; if (isset($block['content']['items']['filling']) && isset($block_scheme['content']['items']['fillings'][$block['content']['items']['filling']]['disable_cache'])) { $register_cache = !$block_scheme['content']['items']['fillings'][$block['content']['items']['filling']]['disable_cache']; } /** * Determines flags for Cache * * @param array $block Block data * @param string $cache_name Generated name of cache * @param array $block_scheme Block scheme * @param bool $register_cache Flag to register cache * @param bool $display_block Flag to display block */ fn_set_hook('render_block_register_cache', $block, $cache_name, $block_scheme, $register_cache, $display_block); if ($register_cache) { self::_registerBlockCache($cache_name, $block_scheme); } $block_content = ''; if (isset($block_scheme['cache']) && Registry::isExist($cache_name) == true && self::allowCache()) { $block_content = Registry::get($cache_name); } else { if ($block['type'] == 'main') { $block_content = self::_renderMainContent(); } else { Registry::get('view')->assign('title', $block['name']); if (!empty($block_scheme['content'])) { foreach ($block_scheme['content'] as $template_variable => $field) { /** * Actions before render any variable of block content * @param string $template_variable name of current block content variable * @param array $field Scheme of this content variable from block scheme content section * @param array $block_scheme block scheme * @param array $block Block data */ fn_set_hook('render_block_content_pre', $template_variable, $field, $block_scheme, $block); $value = self::getValue($template_variable, $field, $block_scheme, $block); // If block have not empty content - display it if (empty($value)) { $display_block = false; } Registry::get('view')->assign($template_variable, $value); } } // Assign block data from scheme Registry::get('view')->assign('block_scheme', $block_scheme); if ($display_block && file_exists($theme_path . $block['properties']['template'])) { $block_content = Registry::get('view')->fetch($block['properties']['template']); } } if (!empty($block['wrapper']) && file_exists($theme_path . $block['wrapper']) && $display_block) { Registry::get('view')->assign('content', $block_content); if ($block['type'] == 'main') { Registry::get('view')->assign('title', !empty(\Smarty::$_smarty_vars['capture']['mainbox_title']) ? \Smarty::$_smarty_vars['capture']['mainbox_title'] : '', false); } $block_content = Registry::get('view')->fetch($block['wrapper']); } else { Registry::get('view')->assign('content', $block_content); $block_content = Registry::get('view')->fetch('views/block_manager/render/block.tpl'); } fn_set_hook('render_block_content_after', $block_scheme, $block, $block_content); if (isset($block_scheme['cache']) && $display_block == true && self::allowCache()) { Registry::set($cache_name, $block_content); } } $wrap_id = $smarty->getTemplateVars('block_wrap'); $smarty->clearAllAssign(); $smarty->assign($_tpl_vars); // restore original vars \Smarty::$_smarty_vars['capture']['title'] = null; if ($display_block == true) { if (!empty($wrap_id)) { $block_content = '<div id="' . $wrap_id . '">' . $block_content . '<!--' . $wrap_id . '--></div>'; } return trim($block_content); } else { return ''; } }
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ use Tygh\Registry; use Tygh\Ym\Yml; if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { return; } if ($mode == 'view') { if (Registry::get('addons.yandex_market.enable_authorization') == 'Y') { $user_data = fn_yandex_auth(); } $company_id = Registry::get('runtime.company_id'); if (fn_allowed_for('MULTIVENDOR')) { $company_id = 0; if (!empty($user_data) && $user_data['user_type'] == 'V') { $company_id = $user_data['company_id']; } } $options = Registry::get('addons.yandex_market'); $page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 0; $lang_code = DESCR_SL; if (Registry::isExist('languages.ru')) { $lang_code = 'ru'; } $yml = new Yml($company_id, $options, $lang_code, $page, isset($_REQUEST['debug'])); $yml->get(); exit; }
function fn_exim_1c_import_features($classifier_data, $company_id, $cml) { $settings_1c = Registry::get('addons.rus_exim_1c'); if (isset($classifier_data->{$cml}['properties']->{$cml}['property'])) { $features_1c = array(); $promo_text = trim($settings_1c['exim_1c_property_product']); $shipping_params = fn_exim_1c_get_shipping_params(); $features_list = fn_explode("\n", $settings_1c['exim_1c_features_list']); $deny_or_allow_list = $settings_1c['exim_1c_deny_or_allow']; foreach ($classifier_data->{$cml}['properties']->{$cml}['property'] as $_feature) { $_variants = array(); if ($deny_or_allow_list != 'not_used') { if ($deny_or_allow_list == 'do_not_import') { if (in_array(strval($_feature->{$cml}['name']), $features_list)) { continue; } } else { if (!in_array(strval($_feature->{$cml}['name']), $features_list)) { continue; } } } $feature_data = array(); $id = db_get_field("SELECT feature_id FROM ?:product_features WHERE external_id = ?s", strval($_feature->{$cml}['id'])); $new_feature = false; $feature_id = $id; if (empty($id)) { $new_feature = true; $feature_id = 0; } $feature_id = !empty($id) ? $id : 0; $feature_data = fn_exim_1c_get_feature(strval($_feature->{$cml}['name']), $feature_id, strval($_feature->{$cml}['id']), $company_id, $settings_1c); if (fn_exim_1c_feature_display_shipping_param(strval($_feature->{$cml}['name']), $shipping_params)) { if ($promo_text != strval($_feature->{$cml}['name'])) { $feature_id = fn_update_product_feature($feature_data, $feature_id); if ($new_feature) { db_query("INSERT INTO ?:ult_objects_sharing VALUES ({$company_id}, {$feature_id}, 'product_features')"); } } else { fn_delete_feature($feature_id); } } $count = 0; if (!empty($_feature->{$cml}['variants_values'])) { $_feature_data = $_feature->{$cml}['variants_values']->{$cml}['directory']; foreach ($_feature_data as $_variant) { $_variants[$count]['id'] = strval($_variant->{$cml}['id_value']); $_variants[$count]['value'] = strval($_variant->{$cml}['value']); $count++; } } $features_1c[strval($_feature->{$cml}['id'])]['id'] = $feature_id; $features_1c[strval($_feature->{$cml}['id'])]['name'] = strval($_feature->{$cml}['name']); if (!empty($_variants)) { $features_1c[strval($_feature->{$cml}['id'])]['variants'] = $_variants; } } if (Registry::isExist('rus_exim_1c.features_1c')) { $_features_1c = Registry::get('rus_exim_1c.features_1c'); $features_1c = fn_array_merge($_features_1c, $features_1c); Registry::set('rus_exim_1c.features_1c', $features_1c); } else { Registry::set('rus_exim_1c.features_1c', $features_1c); } } }
/** * Gets data from storage * @param string $key key * @return mixed key value */ function fn_get_storage_data($key) { if (!Registry::isExist('storage_data.' . $key)) { Registry::set('storage_data.' . $key, db_get_field('SELECT `data` FROM ?:storage_data WHERE `data_key` = ?s', $key)); } return Registry::get('storage_data.' . $key); }
/** * Filters: gets available filters according to current products set * * @param array $params request params * @param string $lang_code language code * @return array available filters list */ function fn_get_filters_products_count($params = array(), $lang_code = CART_LANGUAGE) { /** * Change parameters for getting product filters count * * @param array $params Products filter search params */ fn_set_hook('get_filters_products_count_pre', $params); $cache_params = array('category_id', 'company_id', 'dispatch', 'search_performed', 'q', 'filter_id', 'item_ids', 'variant_id'); $key = array(); foreach ($cache_params as $prop) { if (isset($params[$prop])) { $key[] = $params[$prop]; } } $key = 'pfilters_' . md5(implode('|', $key)); Registry::registerCache(array('pfilters', $key), array('products', 'product_descriptions', 'product_features', 'product_filters', 'product_features_values', 'products_categories', 'categories', 'product_filter_descriptions', 'product_features_descriptions', 'product_feature_variant_descriptions', 'ult_objects_sharing'), Registry::cacheLevel('user')); $selected_filters = array(); $available_variants = array(); if (!Registry::isExist($key)) { if (!empty($params['check_location'])) { // FIXME: this is bad style, should be refactored $valid_locations = array('categories.view', 'product_features.view', 'companies.products', 'products.search'); if (!in_array($params['dispatch'], $valid_locations)) { return array(); } } $condition = $join = ''; if (!empty($params['category_id'])) { if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') { $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 . '/%'); } else { $category_ids = array(); } $category_ids[] = $params['category_id']; $condition .= db_quote(" AND (?:product_filters.categories_path = '' OR FIND_IN_SET(?i, ?:product_filters.categories_path))", $params['category_id']); } if (!empty($params['filter_id'])) { $condition .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']); } if (!empty($params['item_ids'])) { $condition .= db_quote(" AND ?:product_filters.filter_id IN (?a)", explode(',', $params['item_ids'])); } if (!empty($params['variant_id'])) { $exclude_feature_id = db_get_field("SELECT feature_id FROM ?:product_features_values WHERE variant_id = ?i", $params['variant_id']); $condition .= db_quote(" AND ?:product_filters.feature_id NOT IN (?n)", $exclude_feature_id); } if (fn_allowed_for('ULTIMATE')) { $condition .= fn_get_company_condition('?:product_filters.company_id'); } $sf_fields = db_quote("?:product_filters.feature_id, " . "?:product_filters.filter_id," . "?:product_filters.field_type," . "?:product_filters.round_to," . "?:product_filters.display," . "?:product_filters.display_count," . "?:product_filter_descriptions.filter," . "?:product_features.feature_type," . "?:product_features_descriptions.prefix," . "?:product_features_descriptions.suffix"); $sf_join = db_quote(" 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 ON ?:product_features.feature_id = ?:product_filters.feature_id" . " LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s", $lang_code, $lang_code); $sf_sorting = db_quote("?:product_filters.position, ?:product_filter_descriptions.filter"); /** * Change SQL parameters before select product filters * * @param array $sf_fields String of comma-separated SQL fields to be selected in an SQL-query * @param string $sf_join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $sf_sorting String containing the SQL-query ORDER BY clause * @param array $params Products filter search params */ fn_set_hook('get_filters_products_count_before_select_filters', $sf_fields, $sf_join, $condition, $sf_sorting, $params); $limit = ''; if (fn_allowed_for('ULTIMATE:FREE')) { $limit = db_quote(' LIMIT ?i', FILTERS_LIMIT); } $filters = db_get_hash_array("SELECT {$sf_fields} FROM ?:product_filters ?p WHERE ?:product_filters.status = 'A' ?p ORDER BY {$sf_sorting} {$limit}", 'filter_id', $sf_join, $condition); if (empty($filters)) { return array(array()); } list($variant_values, $range_values, $field_variant_values, $field_range_values) = fn_get_current_filters($params, $filters, array(), AREA, $lang_code); Registry::set($key, array($filters, $variant_values, $range_values, $field_variant_values, $field_range_values)); } else { list($filters, $variant_values, $range_values, $field_variant_values, $field_range_values) = Registry::get($key); } $range_values = fn_filter_process_ranges($range_values, $filters, $selected_filters); $field_range_values = fn_filter_process_ranges($field_range_values, $filters, $selected_filters); $merged = fn_array_merge($variant_values, $range_values, $field_variant_values, $field_range_values); $available_variants = $merged; if (!empty($params['features_hash']) && empty($params['skip_advanced_variants'])) { $selected_filters = fn_parse_filters_hash($params['features_hash']); // Get available variants for current selection $_params = $params; $_params['split_filters'] = true; list($available_variants, $available_ranges, $available_field_values, $available_field_ranges) = fn_get_current_filters($_params, $filters, $selected_filters, AREA, $lang_code); list($variant_filter_ids) = fn_split_selected_feature_variants($filters, $selected_filters, false); if (sizeof($variant_filter_ids) == 1 && sizeof($selected_filters) == 1) { $filter_id = key($variant_filter_ids); $available_variants[$filter_id] = $variant_values[$filter_id]; } $available_ranges = fn_filter_process_ranges($available_ranges, $filters, $selected_filters); $available_field_ranges = fn_filter_process_ranges($available_field_ranges, $filters, $selected_filters); $available_variants = fn_array_merge($available_variants, $available_ranges, $available_field_values, $available_field_ranges); $merged = fn_array_merge($merged, $available_variants); } foreach ($filters as $filter_id => $filter) { if (empty($merged[$filter_id]) || !empty($filter['feature_type']) && empty($available_variants[$filter_id])) { unset($filters[$filter_id]); continue; } $filters[$filter_id] = fn_array_merge($filters[$filter_id], $merged[$filter_id]); // Move selected variants to selected_variants key if (!empty($filters[$filter_id]['variants']) && !empty($selected_filters[$filter_id])) { foreach ($selected_filters[$filter_id] as $variant_id) { if (!empty($filters[$filter_id]['variants'][$variant_id])) { $filters[$filter_id]['selected_variants'][$variant_id] = $filters[$filter_id]['variants'][$variant_id]; unset($filters[$filter_id]['variants'][$variant_id]); } } } // If we selected any variants in filter, disabled unavailable variants if (!empty($available_variants) && !empty($available_variants[$filter_id])) { foreach ($filters[$filter_id]['variants'] as $variant_id => $variant_data) { if (empty($available_variants[$filter_id]['variants'][$variant_id])) { // disable variant and move it to the end of list unset($filters[$filter_id]['variants'][$variant_id]); $variant_data['disabled'] = true; $filters[$filter_id]['variants'][$variant_id] = $variant_data; } } } // If range is selected, mark this filter if (!empty($filters[$filter_id]['slider']) && !empty($selected_filters[$filter_id])) { if (!empty($filters[$filter_id]['slider']['left']) || !empty($filters[$filter_id]['right'])) { $filters[$filter_id]['selected_range'] = true; } } } return array($filters); }