fn_delete_feature($_REQUEST['feature_id']); } } return array(CONTROLLER_STATUS_OK, 'product_features.manage'); } if ($mode == 'update') { $selected_section = empty($_REQUEST['selected_section']) ? 'detailed' : $_REQUEST['selected_section']; $feature = fn_get_product_feature_data($_REQUEST['feature_id'], false, false, DESCR_SL); Registry::get('view')->assign('feature', $feature); list($group_features) = fn_get_product_features(array('feature_types' => ProductFeatures::GROUP), 0, DESCR_SL); Registry::get('view')->assign('group_features', $group_features); if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) { Registry::get('view')->assign('picker_selected_companies', fn_ult_get_controller_shared_companies($_REQUEST['feature_id'])); } $params = array('feature_id' => $feature['feature_id'], 'feature_type' => $feature['feature_type'], 'get_images' => true, 'page' => !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1, 'items_per_page' => !empty($_REQUEST['items_per_page']) ? $_REQUEST['items_per_page'] : Registry::get('settings.Appearance.admin_elements_per_page')); list($variants, $search) = fn_get_product_feature_variants($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL); Registry::get('view')->assign('feature_variants', $variants); Registry::get('view')->assign('search', $search); } elseif ($mode == 'manage') { $params = $_REQUEST; $params['get_descriptions'] = true; $params['search_in_subcats'] = true; list($features, $search, $has_ungroupped) = fn_get_product_features($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL); Registry::get('view')->assign('features', $features); Registry::get('view')->assign('search', $search); Registry::get('view')->assign('has_ungroupped', $has_ungroupped); if (empty($features) && defined('AJAX_REQUEST')) { Registry::get('ajax')->assign('force_redirection', fn_url('product_features.manage')); } list($group_features) = fn_get_product_features(array('feature_types' => ProductFeatures::GROUP), 0, DESCR_SL); Registry::get('view')->assign('group_features', $group_features);
function fn_exim_get_product_features_variants($feature_id, $lang_code) { list($feature_variants) = fn_get_product_feature_variants(array('feature_id' => $feature_id), 0, $lang_code); $variants = array(); foreach ($feature_variants as $variant) { $variants[] = fn_exim_wrap_value($variant['variant'], "'", ','); } $variants = implode(', ', $variants); return $variants; }
/** * Gets product filters by search params * * @param array $params Products filter search params * @param int $items_per_page Items per page * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) * @return array Product filters */ function fn_get_product_filters($params = array(), $items_per_page = 0, $lang_code = DESCR_SL) { /** * Changes product filters search params * * @param array $params Products filter search params * @param int $items_per_page Items per page * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_product_filters_pre', $params, $items_per_page, $lang_code); // Init filter $params = LastView::instance()->update('product_filters', $params); // Set default values to input params $default_params = array('page' => 1, 'items_per_page' => $items_per_page); $params = array_merge($default_params, $params); $condition = $group = ''; if (!empty($params['filter_id'])) { $condition .= db_quote(" AND ?:product_filters.filter_id IN (?n)", (array) $params['filter_id']); } if (isset($params['filter_name']) && fn_string_not_empty($params['filter_name'])) { $condition .= db_quote(" AND ?:product_filter_descriptions.filter LIKE ?l", "%" . trim($params['filter_name']) . "%"); } if (!empty($params['show_on_home_page'])) { $condition .= db_quote(" AND ?:product_filters.show_on_home_page = ?s", $params['show_on_home_page']); } if (!empty($params['status'])) { $condition .= db_quote(" AND ?:product_filters.status = ?s", $params['status']); } if (isset($params['feature_name']) && fn_string_not_empty($params['feature_name'])) { $condition .= db_quote(" AND ?:product_features_descriptions.description LIKE ?l", "%" . trim($params['feature_name']) . "%"); } if (!empty($params['category_ids'])) { $c_ids = is_array($params['category_ids']) ? $params['category_ids'] : fn_explode(',', $params['category_ids']); $find_set = array(" ?:product_filters.categories_path = '' "); foreach ($c_ids as $k => $v) { $find_set[] = db_quote(" FIND_IN_SET(?i, ?:product_filters.categories_path) ", $v); } $find_in_set = db_quote(" AND (?p)", implode('OR', $find_set)); $condition .= $find_in_set; } if (fn_allowed_for('ULTIMATE')) { $condition .= fn_get_company_condition('?:product_filters.company_id'); } $limit = ''; if (!empty($params['items_per_page'])) { $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:product_filters LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.lang_code = ?s AND ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id WHERE 1 ?p", $lang_code, $lang_code, $condition); $limit = db_paginate($params['page'], $params['items_per_page']); } $fields = ""; if (!empty($params['short'])) { $fields .= db_quote("?:product_filters.filter_id, ?:product_filters.feature_id, ?:product_filters.field_type, ?:product_filters.status, "); if (fn_allowed_for('ULTIMATE')) { $fields .= db_quote("?:product_filters.company_id, "); } } else { $fields .= db_quote("?:product_filters.*, ?:product_features_descriptions.description as feature, "); } $fields .= db_quote("?:product_filter_descriptions.filter, ?:product_features.feature_type, ?:product_features.parent_id, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix"); $join = db_quote("LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.lang_code = ?s AND ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id", $lang_code, $lang_code); $sorting = db_quote("?:product_filters.position, ?:product_filter_descriptions.filter"); $group_by = db_quote("GROUP BY ?:product_filters.filter_id"); /** * Changes SQL parameters for product filters select * * @param string $fields String of comma-separated 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 $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $group_by String containing the SQL-query GROUP BY field * @param string $sorting String containing the SQL-query ORDER BY clause * @param string $limit String containing the SQL-query LIMIT clause * @param array $params Products filter search params * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_product_filters_before_select', $fields, $join, $condition, $group_by, $sorting, $limit, $params, $lang_code); $filters = db_get_hash_array("SELECT {$fields} FROM ?:product_filters {$join} WHERE 1 ?p {$group_by} ORDER BY {$sorting} {$limit}", 'filter_id', $condition); if (!empty($filters)) { $fields = fn_get_product_filter_fields(); // Get feature group if exist $parent_ids = array(); foreach ($filters as $k => $v) { if (!empty($v['parent_id'])) { $parent_ids[] = $v['parent_id']; } } $groups = db_get_hash_array("SELECT feature_id, description FROM ?:product_features_descriptions WHERE feature_id IN (?n) AND lang_code = ?s", 'feature_id', $parent_ids, $lang_code); foreach ($filters as $k => $filter) { if (!empty($filter['parent_id']) && !empty($groups[$filter['parent_id']])) { $filters[$k]['feature_group'] = $groups[$filter['parent_id']]['description']; } if (!empty($filter['field_type'])) { $filters[$k]['feature'] = __($fields[$filter['field_type']]['description']); } if (empty($filter['feature_id'])) { $filters[$k]['condition_type'] = $fields[$filter['field_type']]['condition_type']; } if (!empty($fields[$filter['field_type']]['slider'])) { $filters[$k]['slider'] = $fields[$filter['field_type']]['slider']; } if (!empty($params['get_descriptions'])) { $d = array(); $filters[$k]['filter_description'] = __('filter_by') . ': <span>' . $filters[$k]['feature'] . (!empty($filters[$k]['feature_group']) ? ' (' . $filters[$k]['feature_group'] . ' )' : '') . '</span>'; if ($filter['show_on_home_page'] == 'Y') { $d[] = __('home_page'); } $d = fn_array_merge($d, fn_get_categories_list($filter['categories_path'], $lang_code), false); $filters[$k]['filter_description'] .= ' | ' . __('display_on') . ': <span>' . implode(', ', $d) . '</span>'; } $_ids[$filter['filter_id']] = $filter['feature_type'] != 'N' ? $filter['feature_id'] : null; } if (!empty($params['get_variants'])) { $ranges = db_get_hash_array("SELECT ?:product_filter_ranges.*, ?:product_filter_ranges_descriptions.range_name 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 WHERE filter_id IN (?a) ORDER BY position", 'range_id', $lang_code, array_keys($_ids)); if (!empty($ranges)) { foreach ($ranges as $range_id => $range) { unset($_ids[$range['filter_id']]); $filters[$range['filter_id']]['ranges'][$range_id] = $range; } } unset($ranges); if (!empty($_ids)) { list($variants) = fn_get_product_feature_variants(array('feature_id' => array_values($_ids))); $_ids_revert = array(); foreach ($_ids as $filter_id => $feature_id) { if (!empty($feature_id)) { $_ids_revert[$feature_id][] = $filter_id; } } foreach ($variants as $variant_id => $variant) { if (!empty($_ids_revert[$variant['feature_id']])) { foreach ($_ids_revert[$variant['feature_id']] as $filter_id) { if (!empty($params['short'])) { $filters[$filter_id]['ranges'][$variant_id] = array('variant_id' => $variant['variant_id'], 'variant' => $variant['variant']); } else { $filters[$filter_id]['ranges'][$variant_id] = $variant; } } } unset($variants[$variant_id]); } unset($variants); } unset($_ids); } } /** * Changes product filters data * * @param array $filters Product filters * @param array $params Products filter search params * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_product_filters_post', $filters, $params, $lang_code); return array($filters, $params); }
function fn_exim_get_product_features($product_id, $features_delimiter, $lang_code = CART_LANGUAGE) { static $features; if (!isset($features[$lang_code])) { list($features[$lang_code]) = fn_get_product_features(array('plain' => true), 0, $lang_code); } $main_category = db_get_field('SELECT category_id FROM ?:products_categories WHERE product_id = ?i AND link_type = ?s', $product_id, 'M'); $product = array('product_id' => $product_id, 'main_category' => $main_category); $product_features = fn_get_product_features_list($product, 'A', $lang_code); $pair_delimiter = ':'; $set_delimiter = ';'; $result = array(); if (!empty($product_features)) { foreach ($product_features as $f) { $parent = ''; if (!empty($f['parent_id'])) { $parent = '(' . str_replace($set_delimiter, '\\\\' . $set_delimiter, $features[$lang_code][$f['parent_id']]['description']) . ') '; } $f['value_int'] = empty($f['value_int']) ? 0 : floatval($f['value_int']); if (!empty($f['value']) || !empty($f['value_int'])) { $result[] = $parent . "{$f['description']}{$pair_delimiter} {$f['feature_type']}[" . (!empty($f['value']) ? $f['value'] : $f['value_int']) . ']'; } else { $_params = array('feature_id' => $f['feature_id'], 'product_id' => $product_id, 'feature_type' => $f['feature_type'], 'selected_only' => true); list($variants) = fn_get_product_feature_variants($_params, 0, $lang_code); if ($variants) { $values = array(); foreach ($variants as $v) { $values[] = str_replace($set_delimiter, '\\\\' . $set_delimiter, $v['variant']); } $feature_description = str_replace($set_delimiter, '\\\\' . $set_delimiter, $f['description']); $result[] = $parent . "{$feature_description}{$pair_delimiter} {$f['feature_type']}[" . implode($features_delimiter, $values) . ']'; } } } } return !empty($result) ? implode($set_delimiter . ' ', $result) : ''; }
public static function dataProductFeatures($data_product, &$product, $import_params) { $property_for_promo_text = trim(self::$s_commerceml['exim_1c_property_product']); $cml = self::$cml; $features_commerceml = self::$features_commerceml; if (!empty($data_product->{$cml}['properties_values']->{$cml}['property_values'])) { foreach ($data_product->{$cml}['properties_values']->{$cml}['property_values'] as $_feature) { $variant_data = array(); $feature_id = strval($_feature->{$cml}['id']); if (!isset($features_commerceml[$feature_id]) || empty($_feature->{$cml}['value'])) { continue; } $p_feature_name = strval($_feature->{$cml}['value']); $feature_name = trim($features_commerceml[$feature_id]['name'], " "); if (!empty($features_commerceml[$feature_id])) { $product_params = self::dataShippingParams($p_feature_name, $feature_name, $import_params); if (!empty($product_params)) { $product = array_merge($product, $product_params); } if (!empty($property_for_promo_text) && $property_for_promo_text == $feature_name) { if (!empty($features_commerceml[$feature_id]['variants'])) { $product['promo_text'] = $features_commerceml[$feature_id]['variants'][$p_feature_name]['value']; } else { $product['promo_text'] = $p_feature_name; } } } if (!empty($features_commerceml[$feature_id]['id'])) { $variant_data['feature_id'] = $features_commerceml[$feature_id]['id']; $variant_data['feature_types'] = $features_commerceml[$feature_id]['type']; $variant_data['lang_code'] = $import_params['lang_code']; list($d_variants, $variant_params, $has_ungroupped) = fn_get_product_features($variant_data, 0, $import_params['lang_code']); $variant_data = $d_variants[$variant_data['feature_id']]; if ($variant_data['feature_type'] == ProductFeatures::NUMBER_SELECTBOX) { $p_feature_name = str_replace(',', '.', $p_feature_name); $variant_data['value_int'] = $p_feature_name; } $is_id = false; $variant = ''; if (!empty($features_commerceml[$feature_id]['variants'])) { foreach ($features_commerceml[$feature_id]['variants'] as $_variant) { if ($p_feature_name == $_variant['id']) { $variant = $_variant['value']; $is_id = true; break; } } if (!$is_id) { $variant = $p_feature_name; } } else { $variant = $p_feature_name; } $variant_data['variant'] = $variant; list($d_variants, $params_variant) = fn_get_product_feature_variants(array('feature_id' => array($variant_data['feature_id']), 'search_query' => $variant), 0, $import_params['lang_code']); if (!empty($d_variants)) { $d_variant = reset($d_variants); $variant_data['variant_id'] = $d_variant['variant_id']; } else { $variant_data['variant_id'] = fn_add_feature_variant($variant_data['feature_id'], array('variant' => $variant)); } $product['features'][$feature_id] = $variant_data; } } } $variant_data = array(); if (self::$s_commerceml['exim_1c_used_brand'] == 'field_brand') { if (isset($data_product->{$cml}['manufacturer'])) { $variant_data['feature_id'] = $features_commerceml['brand1c']['id']; $variant_data['lang_code'] = $import_params['lang_code']; $variant_id = db_get_field("SELECT variant_id FROM ?:product_feature_variants WHERE feature_id = ?i AND external_id = ?s", $variant_data['feature_id'], strval($data_product->{$cml}['manufacturer']->{$cml}['id'])); $variant = strval($data_product->{$cml}['manufacturer']->{$cml}['name']); if (empty($variant_id)) { $variant_data['variant_id'] = fn_add_feature_variant($variant_data['feature_id'], array('variant' => $variant)); db_query("UPDATE ?:product_feature_variants SET external_id = ?s WHERE variant_id = ?i", strval($data_product->{$cml}['manufacturer']->{$cml}['id']), $variant_data['variant_id']); } else { $variant_data['variant_id'] = $variant_id; } $product['features'][$variant_data['feature_id']] = $variant_data; } } }
public function update($id, $params) { fn_define('NEW_FEATURE_GROUP_ID', 'OG'); $status = Response::STATUS_BAD_REQUEST; $data = array(); unset($params['feature_id']); if (!empty($params['variants'])) { list($variants) = fn_get_product_feature_variants(array('feature_id' => $id)); $params['original_var_ids'] = implode(',', array_keys($variants)); } $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE); $feature_id = fn_update_product_feature($params, $id, $lang_code); if ($feature_id) { $status = Response::STATUS_OK; $data = array('feature_id' => $feature_id); } return array('status' => $status, 'data' => $data); }
Tygh::$app['view']->display('common/ajax_select_object.tpl'); exit; } elseif ($mode == 'get_variants_list') { if (isset($_REQUEST['feature_id'])) { $feature_id = (int) $_REQUEST['feature_id']; } else { exit; } $page_number = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1; $page_size = isset($_REQUEST['page_size']) ? (int) $_REQUEST['page_size'] : 3; $search_query = isset($_REQUEST['q']) ? $_REQUEST['q'] : null; $lang_code = isset($_REQUEST['lang_code']) ? $_REQUEST['lang_code'] : CART_LANGUAGE; $search = array('page' => $page_number, 'feature_id' => $feature_id, 'search_query' => $search_query, 'get_images' => true); if (isset($_REQUEST['product_id'])) { $search['product_id'] = (int) $_REQUEST['product_id']; } list($variants, $search) = fn_get_product_feature_variants($search, $page_size, $lang_code); $objects = array_values(array_map(function ($feature_variant) { $image_url = null; if (isset($feature_variant['image_pair'])) { $image_data = fn_image_to_display($feature_variant['image_pair'], isset($_REQUEST['image_width']) ? (int) $_REQUEST['image_width'] : 50, isset($_REQUEST['image_height']) ? (int) $_REQUEST['image_height'] : 50); if (!empty($image_data['image_path'])) { $image_url = $image_data['image_path']; } } return array('id' => $feature_variant['variant_id'], 'text' => $feature_variant['variant'], 'image_url' => $image_url); }, $variants)); Tygh::$app['ajax']->assign('objects', $objects); Tygh::$app['ajax']->assign('total_objects', $search['total_items']); exit; }
function fn_get_product_filters($params = array(), $items_per_page = 0, $lang_code = DESCR_SL) { // Init filter $params = fn_init_view('product_filters', $params); // Set default values to input params $params['page'] = empty($params['page']) ? 1 : $params['page']; // default page is 1 $condition = $group = ''; if (!empty($params['filter_id'])) { $condition .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']); } if (isset($params['filter_name']) && fn_string_no_empty($params['filter_name'])) { $condition .= db_quote(" AND ?:product_filter_descriptions.filter LIKE ?l", "%" . trim($params['filter_name']) . "%"); } if (isset($params['feature_name']) && fn_string_no_empty($params['feature_name'])) { $condition .= db_quote(" AND ?:product_features_descriptions.description LIKE ?l", "%" . trim($params['feature_name']) . "%"); } if (!empty($params['category_ids'])) { $c_ids = is_array($params['category_ids']) ? $params['category_ids'] : fn_explode(',', $params['category_ids']); $find_set = array(" ?:product_filters.categories_path = '' "); foreach ($c_ids as $k => $v) { $find_set[] = db_quote(" FIND_IN_SET(?i, ?:product_filters.categories_path) ", $v); } $find_in_set = db_quote(" AND (?p)", implode('OR', $find_set)); $condition .= $find_in_set; } $limit = ''; if (!empty($items_per_page)) { $total = db_get_field("SELECT COUNT(*) FROM ?:product_filters LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.lang_code = ?s AND ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id WHERE 1 ?p", $lang_code, $lang_code, $condition); $limit = fn_paginate($params['page'], $total, $items_per_page); } $filters = db_get_hash_array("SELECT ?:product_filters.*, ?:product_filter_descriptions.filter, ?:product_features.feature_type, ?:product_features.parent_id, ?:product_features_descriptions.description as feature, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix FROM ?:product_filters LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.lang_code = ?s AND ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id WHERE 1 ?p GROUP BY ?:product_filters.filter_id ORDER BY ?:product_filters.position, ?:product_filter_descriptions.filter {$limit}", 'filter_id', $lang_code, $lang_code, $condition); if (!empty($filters)) { $fields = fn_get_product_filter_fields(); // Get feature group if exist $parent_ids = array(); foreach ($filters as $k => $v) { if (!empty($v['parent_id'])) { $parent_ids[$v['parent_id']] = true; } } $groups = db_get_hash_array("SELECT feature_id, description FROM ?:product_features_descriptions WHERE feature_id IN (?n) AND lang_code = ?s", 'feature_id', array_keys($parent_ids), $lang_code); foreach ($filters as $k => $filter) { if (!empty($filter['parent_id']) && !empty($groups[$filter['parent_id']])) { $filters[$k]['feature_group'] = $groups[$filter['parent_id']]['description']; } if (!empty($filter['field_type'])) { $filters[$k]['feature'] = fn_get_lang_var($fields[$filter['field_type']]['description']); } if (empty($filter['feature_id'])) { $filters[$k]['condition_type'] = $fields[$filter['field_type']]['condition_type']; } if (!empty($params['get_descriptions'])) { $d = array(); $filters[$k]['filter_description'] = fn_get_lang_var('filter_by') . ': <strong>' . $filters[$k]['feature'] . (!empty($filters[$k]['feature_group']) ? ' (' . $filters[$k]['feature_group'] . ' )' : '') . '</strong>'; if ($filter['show_on_home_page'] == 'Y') { $d[] = fn_get_lang_var('home_page'); } $d = fn_array_merge($d, fn_get_categories_list($filter['categories_path'], $lang_code), false); $filters[$k]['filter_description'] .= ' | ' . fn_get_lang_var('display_on') . ': <strong>' . implode(', ', $d) . '</strong>'; } if (!empty($params['get_variants'])) { $filters[$k]['ranges'] = db_get_array("SELECT ?:product_filter_ranges.*, ?:product_filter_ranges_descriptions.range_name 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 WHERE filter_id = ?i ORDER BY position", $lang_code, $filter['filter_id']); if (empty($filters[$k]['ranges']) && !empty($filter['feature_id']) && $filter['feature_type'] != 'N') { $filters[$k]['ranges'] = fn_get_product_feature_variants($filter['feature_id'], 0, $filter['feature_type']); } } } } return array($filters, $params); }