Пример #1
0
 public function index($id = 0, $params = array())
 {
     $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE);
     if ($this->getParentName() == 'products') {
         $parent_product = $this->getParentData();
         $params['product_id'] = $parent_product['product_id'];
         $params['existent_only'] = $this->safeGet($params, 'existent_only', true);
         $params['exclude_group'] = $this->safeGet($params, 'exclude_group', true);
         $params['variants'] = $this->safeGet($params, 'variants', true);
     }
     if (!empty($id)) {
         $params['variants'] = $this->safeGet($params, 'variants', true);
         $data = fn_get_product_feature_data($id, $params['variants'], false, $lang_code);
         if (empty($data)) {
             $status = Response::STATUS_NOT_FOUND;
         } else {
             $status = Response::STATUS_OK;
         }
     } else {
         $items_per_page = $this->safeGet($params, 'items_per_page', Registry::get('settings.Appearance.admin_elements_per_page'));
         $params['exclude_group'] = $this->safeGet($params, 'exclude_group', false);
         $params['get_descriptions'] = $this->safeGet($params, 'get_descriptions', true);
         $params['plain'] = $this->safeGet($params, 'plain', true);
         $params['variants'] = $this->safeGet($params, 'variants', false);
         list($features, $params) = fn_get_product_features($params, $items_per_page, $lang_code);
         $data = array('features' => array_values($features), 'params' => $params);
         $status = Response::STATUS_OK;
     }
     return array('status' => $status, 'data' => $data);
 }
function fn_import_feature_variant($data, $options, &$processed_data, &$skip_record)
{
    static $features;
    $skip_record = true;
    $variant = reset($data);
    if (empty($variant['Feature name'])) {
        return false;
    }
    $langs = array_keys($data);
    $main_lang = reset($langs);
    array_walk($variant, 'fn_trim_helper');
    if (!empty($variant['Feature group'])) {
        $feature_group = fn_exim_get_feature_data_by_name($variant['Feature group'], '');
        $variant['parent_id'] = $feature_group['feature_id'];
    } else {
        $variant['Feature group'] = '';
        $variant['parent_id'] = 0;
    }
    $feature = fn_exim_get_feature_data_by_name($variant['Feature name'], $variant['Feature group']);
    if (empty($feature)) {
        $processed_data['S']++;
        return false;
    }
    $feature_id = $feature['feature_id'];
    $company_id = $feature['company_id'];
    if (Registry::get('runtime.company_id') && Registry::get('runtime.company_id') != $company_id) {
        $processed_data['S']++;
        return false;
    }
    if (!isset($features)) {
        list($features) = fn_get_product_features(array('plain' => true), 0, $main_lang);
    }
    if (!empty($feature_id)) {
        if (isset($variant['variant_id'])) {
            $variant_id = db_get_field('SELECT variant_id FROM ?:product_feature_variants WHERE variant_id = ?i', $variant['variant_id']);
        }
        if (empty($variant_id)) {
            $join = db_quote('INNER JOIN ?:product_feature_variants fv ON fv.variant_id = fvd.variant_id');
            $variant_id = db_get_field("SELECT fvd.variant_id FROM ?:product_feature_variant_descriptions AS fvd {$join} WHERE variant = ?s AND feature_id = ?i", $variant['variant'], $feature_id);
        }
        $new_variant_id = fn_update_product_feature_variant($feature_id, $features[$feature_id]['feature_type'], $variant, $main_lang);
        if ($variant_id == $new_variant_id) {
            $processed_data['E']++;
        } else {
            $processed_data['N']++;
            $variant_id = $new_variant_id;
        }
        foreach ($data as $lang_code => $variant) {
            fn_update_product_feature_variant($feature_id, $features[$feature_id]['feature_type'], $variant, $lang_code);
        }
        if (!empty($variant['image_id'])) {
            fn_import_images($options['images_path'], $variant['image_id'], '', 0, 'V', $variant_id, 'feature_variant');
        }
    }
    return $variant_id;
}
function fn_exim_mailru_get_product_features($product_id, $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);
    }
    //params
    $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);
    $result = array();
    if (!empty($product_features)) {
        foreach ($product_features as $f) {
            $display_on_catalog = $features[$lang_code][$f['feature_id']]['display_on_catalog'];
            $display_on_product = $features[$lang_code][$f['feature_id']]['display_on_product'];
            if ($display_on_catalog == "Y" || $display_on_product == "Y") {
                if ($f['feature_type'] == "C") {
                    $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => $f['value'] == "Y" ? __("yes") : __("no"));
                } elseif ($f['feature_type'] == "S" && !empty($f['variant'])) {
                    $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant']));
                } elseif ($f['feature_type'] == "T" && !empty($f['value'])) {
                    $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['value']));
                } elseif ($f['feature_type'] == "M") {
                    if (!empty($f['variants'])) {
                        $_value = '';
                        $counter = count($f['variants']);
                        foreach ($f['variants'] as $_variant) {
                            if ($counter > 1) {
                                $_value .= $_variant['variant'] . ', ';
                            } else {
                                $_value = $_variant['variant'];
                            }
                        }
                        $_value = $counter > 1 ? substr($_value, 0, -2) : $_value;
                        $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($_value));
                    }
                } elseif ($f['feature_type'] == "N") {
                    $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant']));
                } elseif ($f['feature_type'] == "O") {
                    $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['value_int']));
                }
            } elseif ($f['feature_type'] == "E") {
                $result[] = array('description' => fn_exim_mailru_get_product_info($f['description']), 'value' => fn_exim_mailru_get_product_info($f['variant']));
            }
        }
    }
    return !empty($result) ? $result : '';
}
Пример #4
0
function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE)
{
    $_data = $product_data;
    if (!empty($product_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($product_data['timestamp']);
        // Minimal data for product record
    }
    if (!empty($product_data['avail_since'])) {
        $_data['avail_since'] = fn_parse_date($product_data['avail_since']);
    }
    if (isset($product_data['tax_ids'])) {
        $_data['tax_ids'] = empty($product_data['tax_ids']) ? '' : fn_create_set($product_data['tax_ids']);
    }
    if (isset($product_data['localization'])) {
        $_data['localization'] = empty($product_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    if (isset($product_data['usergroup_ids'])) {
        $_data['usergroup_ids'] = empty($product_data['usergroup_ids']) ? '' : implode(',', $_data['usergroup_ids']);
    }
    if (Registry::get('settings.General.allow_negative_amount') == 'N' && isset($_data['amount'])) {
        $_data['amount'] = abs($_data['amount']);
    }
    // add new product
    if (empty($product_id)) {
        $create = true;
        // product title can't be empty
        if (empty($product_data['product'])) {
            return false;
        }
        $product_id = db_query("INSERT INTO ?:products ?e", $_data);
        if (empty($product_id)) {
            return false;
        }
        //
        // Adding same product descriptions for all cart languages
        //
        $_data = $product_data;
        $_data['product_id'] = $product_id;
        $_data['product'] = trim($_data['product'], " -");
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:product_descriptions ?e", $_data);
        }
        // update product
    } else {
        if (isset($product_data['product']) && empty($product_data['product'])) {
            unset($product_data['product']);
        }
        db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $_data, $product_id);
        $_data = $product_data;
        if (!empty($_data['product'])) {
            $_data['product'] = trim($_data['product'], " -");
        }
        db_query("UPDATE ?:product_descriptions SET ?u WHERE product_id = ?i AND lang_code = ?s", $_data, $product_id, $lang_code);
    }
    // Log product add/update
    fn_log_event('products', !empty($create) ? 'create' : 'update', array('product_id' => $product_id));
    if (!empty($product_data['product_features'])) {
        $i_data = array('product_id' => $product_id, 'lang_code' => $lang_code);
        foreach ($product_data['product_features'] as $feature_id => $value) {
            // Check if feature is applicable for this product
            $id_paths = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id = ?i", $product_id);
            $_params = array('category_ids' => array_unique(explode('/', implode('/', $id_paths))), 'feature_id' => $feature_id);
            list($_feature) = fn_get_product_features($_params);
            if (empty($_feature)) {
                $_feature = db_get_field("SELECT description FROM ?:product_features_descriptions WHERE feature_id = ?i AND lang_code = ?s", $feature_id, CART_LANGUAGE);
                $_product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $product_id, CART_LANGUAGE);
                fn_set_notification('E', fn_get_lang_var('error'), str_replace(array('[feature_name]', '[product_name]'), array($_feature, $_product), fn_get_lang_var('product_feature_cannot_assigned')));
                continue;
            }
            $i_data['feature_id'] = $feature_id;
            unset($i_data['value']);
            unset($i_data['variant_id']);
            unset($i_data['value_int']);
            $feature_type = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $feature_id);
            // Delete variants in current language
            if ($feature_type == 'T') {
                db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i AND lang_code = ?s", $feature_id, $product_id, $lang_code);
            } else {
                db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i", $feature_id, $product_id);
            }
            if ($feature_type == 'D') {
                $i_data['value_int'] = fn_parse_date($value);
            } elseif ($feature_type == 'M') {
                if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) {
                    $value = empty($value) ? array() : $value;
                    $value[] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]);
                }
                if (!empty($value)) {
                    foreach ($value as $variant_id) {
                        foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) {
                            // insert for all languages
                            $i_data['variant_id'] = $variant_id;
                            db_query("REPLACE INTO ?:product_features_values ?e", $i_data);
                        }
                    }
                }
                continue;
            } elseif (in_array($feature_type, array('S', 'N', 'E'))) {
                if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) {
                    $i_data['variant_id'] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]);
                } elseif (!empty($value) && $value != 'disable_select') {
                    if ($feature_type == 'N') {
                        $i_data['value_int'] = db_get_field("SELECT variant FROM ?:product_feature_variant_descriptions WHERE variant_id = ?i AND lang_code = ?s", $value, CART_LANGUAGE);
                    }
                    $i_data['variant_id'] = $value;
                } else {
                    continue;
                }
            } else {
                if ($value == '') {
                    continue;
                }
                if ($feature_type == 'O') {
                    $i_data['value_int'] = $value;
                } else {
                    $i_data['value'] = $value;
                }
            }
            if ($feature_type != 'T') {
                // feature values are common for all languages, except text (T)
                foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) {
                    db_query("REPLACE INTO ?:product_features_values ?e", $i_data);
                }
            } else {
                // for text feature, update current language only
                $i_data['lang_code'] = $lang_code;
                db_query("INSERT INTO ?:product_features_values ?e", $i_data);
            }
        }
    }
    // Update product prices
    if (isset($product_data['price'])) {
        if (!isset($product_data['prices'])) {
            $product_data['prices'] = array();
            $skip_price_delete = true;
        }
        $_price = array('price' => abs($product_data['price']), 'lower_limit' => 1);
        array_unshift($product_data['prices'], $_price);
    }
    if (!empty($product_data['prices'])) {
        if (empty($skip_price_delete)) {
            db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id);
        }
        foreach ($product_data['prices'] as $v) {
            if (!empty($v['lower_limit'])) {
                $v['product_id'] = $product_id;
                db_query("REPLACE INTO ?:product_prices ?e", $v);
            }
        }
    }
    if (!empty($product_data['popularity'])) {
        $_data = array('product_id' => $product_id, 'total' => intval($product_data['popularity']));
        db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE total = ?i", $_data, $product_data['popularity']);
    }
    fn_set_hook('update_product', $product_data, $product_id, $lang_code);
    return $product_id;
}
Пример #5
0
 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;
         }
     }
 }
Пример #6
0
         continue;
     }
     if (is_array($offer_feature_name)) {
         $offers_features['common'][$offer_feature_key] = array();
         if (!empty($category_data['yml2_' . fn_uncamelize($offer_feature_key) . '_select'])) {
             $offer_data = explode('.', $category_data['yml2_' . fn_uncamelize($offer_feature_key) . '_select']);
             $offers_features['common'][$offer_feature_key] = array('type' => isset($offer_data[0]) ? $offer_data[0] : '', 'value' => isset($offer_data[1]) ? $offer_data[1] : '');
         }
         $offers_features['common'][$offer_feature_key] = array_merge($offers_features['common'][$offer_feature_key], $offer_feature_name);
     }
 }
 Tygh::$app['view']->assign('yml2_offer_features', $offers_features);
 Tygh::$app['view']->assign('yml2_model_select', $offers_features['common']['model']);
 Tygh::$app['view']->assign('yml2_type_prefix_select', $offers_features['common']['typePrefix']);
 $params = array('category_ids' => $category_data['category_id'], 'plain' => true);
 list($features) = fn_get_product_features($params);
 Tygh::$app['view']->assign('features', $features);
 $parent = false;
 if (!empty($_REQUEST['category_id'])) {
     $category_id = $_REQUEST['category_id'];
 } elseif (!empty($_REQUEST['parent_id'])) {
     $category_id = $_REQUEST['parent_id'];
     $parent = true;
 }
 $offer_type_parent_category = array();
 if (!empty($category_id)) {
     $offer_type_parent_category = fn_yml_get_parent_categories_field('yml2_offer_type', $category_id, $parent);
     $yml2_model_category = fn_yml_get_parent_categories_field('yml2_model', $category_id, $parent);
     $yml2_type_prefix_category = fn_yml_get_parent_categories_field('yml2_type_prefix', $category_id, $parent);
     $yml2_market_category = fn_yml_get_parent_categories_field('yml2_market_category', $category_id, $parent);
     $yml2_parent_type_prefix_select = fn_yml_get_parent_categories_field('yml2_type_prefix_select', $category_id, $parent);
Пример #7
0
    $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);
} elseif ($mode == 'get_feature_variants_list') {
    if (empty($_REQUEST['feature_id'])) {
        exit;
    }
    $pattern = !empty($_REQUEST['pattern']) ? $_REQUEST['pattern'] : '';
    $start = !empty($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    $limit = (!empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 10) + 1;
    $sorting = db_quote("?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant");
    $join = db_quote(" 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", DESCR_SL);
    $condition = db_quote(" AND ?:product_feature_variants.feature_id = ?i", $_REQUEST['feature_id']);
    fn_set_hook('get_feature_variants_list', $condition, $join, $pattern, $start, $limit);
    $objects = db_get_hash_array("SELECT SQL_CALC_FOUND_ROWS ?:product_feature_variants.variant_id AS value, ?:product_feature_variant_descriptions.variant AS name FROM ?:product_feature_variants {$join} WHERE 1 {$condition} AND ?:product_feature_variant_descriptions.variant LIKE ?l ORDER BY ?p LIMIT ?i, ?i", 'value', '%' . $pattern . '%', $sorting, $start, $limit);
    if (defined('AJAX_REQUEST') && sizeof($objects) < $limit) {
        Registry::get('ajax')->assign('completed', true);
Пример #8
0
/**
 * Gets all available brands.
 *
 * @param array $object Block manager object
 * @param array $block Current block settings
 * @param array $scheme Scheme of current block
 * @return array Found brands
 */
function fn_get_all_brands($object, $block, $scheme)
{
    $params = array('exclude_group' => true, 'get_descriptions' => true, 'feature_types' => array('E'), 'variants' => true, 'plain' => trues);
    list($features) = fn_get_product_features($params, 0);
    $variants = array();
    foreach ($features as $feature) {
        $variants = array_merge($variants, $feature['variants']);
    }
    return $variants;
}
Пример #9
0
function fn_get_paginated_product_features($request, $auth, $product_data = array(), $lang_code = DESCR_SL)
{
    $path = array();
    if (!empty($request['over'])) {
        // get features for categories of selected products only
        $categories = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id IN (?n)", $_SESSION['product_ids']);
        foreach ($categories as $category) {
            $path = array_merge($path, explode('/', $category));
        }
        $path = array_unique($path);
    }
    if (empty($product_data) && !empty($request['product_id'])) {
        $product_data = fn_get_product_data($request['product_id'], $auth, $lang_code, '', false, false, false, false, false, false, false, false);
    }
    if (!empty($product_data['product_id'])) {
        $path = !empty($product_data['main_category']) ? explode('/', db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $product_data['main_category'])) : '';
        if (fn_allowed_for('ULTIMATE')) {
            if ($product_data['shared_product'] == 'Y') {
                //we should get features for all categories, not only main
                $path = !empty($product_data['category_ids']) ? explode('/', implode('/', db_get_fields("SELECT id_path FROM ?:categories WHERE category_id IN (?a)", $product_data['category_ids']))) : '';
            }
        }
    }
    $_params = fn_array_merge($request, array('category_ids' => $path, 'product_company_id' => !empty($product_data['company_id']) ? $product_data['company_id'] : 0, 'statuses' => array('A', 'H'), 'variants' => true, 'plain' => false, 'display_on' => '', 'existent_only' => false, 'variants_selected_only' => false));
    return fn_get_product_features($_params, PRODUCT_FEATURES_THRESHOLD, $lang_code);
}
Пример #10
0
function fn_get_filters_products_count($params = array())
{
    $key = 'pfilters_' . md5(serialize($params));
    Registry::register_cache($key, array('products', 'product_features', 'product_filters', 'product_features_values'), CACHE_LEVEL_USER);
    if (Registry::is_exist($key) == false) {
        if (!empty($params['check_location'])) {
            // FIXME: this is bad style, should be refactored
            $valid_locations = array('index.index', 'products.search', 'categories.view', 'product_features.view');
            if (!in_array($params['dispatch'], $valid_locations)) {
                return array();
            }
            if ($params['dispatch'] == 'categories.view') {
                $params['simple_link'] = true;
                // this parameter means that extended filters on this page should be displayed as simple
                $params['filter_custom_advanced'] = true;
                // this parameter means that extended filtering should be stayed on the same page
            } else {
                if ($params['dispatch'] == 'product_features.view') {
                    $params['simple_link'] = true;
                    $params['features_hash'] = (!empty($params['features_hash']) ? $params['features_hash'] . '.' : '') . 'V' . $params['variant_id'];
                    //$params['exclude_feature_id'] = db_get_field("SELECT feature_id FROM ?:product_features_values WHERE variant_id = ?i", $params['variant_id']);
                }
                $params['get_for_home'] = 'Y';
            }
        }
        if (!empty($params['skip_if_advanced']) && !empty($params['advanced_filter']) && $params['advanced_filter'] == 'Y') {
            return array();
        }
        // Base fields for the SELECT queries
        $values_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_features_values.variant_id as range_id', '?:product_feature_variant_descriptions.variant as range_name', '?:product_features.feature_type', '?:product_filters.filter_id');
        $ranges_fields = array('?:product_features_values.feature_id', 'COUNT(DISTINCT ?:products.product_id) as products', '?:product_filter_ranges.range_id', '?:product_filter_ranges_descriptions.range_name', '?:product_filter_ranges.filter_id', '?:product_features.feature_type');
        $condition = $where = $join = $filter_vq = $filter_rq = '';
        $variants_ids = $ranges_ids = $field_filters = $feature_ids = $field_ranges_ids = $field_ranges_counts = array();
        if (!empty($params['features_hash'])) {
            list($variants_ids, $ranges_ids, $_field_ranges_ids) = fn_parse_features_hash($params['features_hash']);
            $field_ranges_ids = array_flip($_field_ranges_ids);
        }
        if (!empty($params['category_id'])) {
            $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $params['category_id']);
            $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE id_path LIKE ?l", $id_path . '/%');
            $category_ids[] = $params['category_id'];
            $condition .= db_quote(" AND (categories_path = '' OR FIND_IN_SET(?i, categories_path))", $params['category_id']);
            $where .= db_quote(" AND ?:products_categories.category_id IN (?n)", $category_ids);
        } elseif (empty($params['get_for_home']) && empty($params['get_custom'])) {
            $condition .= " AND categories_path = ''";
        }
        if (!empty($params['filter_id'])) {
            $condition .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']);
        }
        if (!empty($params['get_for_home'])) {
            $condition .= db_quote(" AND ?:product_filters.show_on_home_page = ?s", $params['get_for_home']);
        }
        if (!empty($params['exclude_feature_id'])) {
            $condition .= db_quote(" AND ?:product_filters.feature_id NOT IN (?n)", $params['exclude_feature_id']);
        }
        $filters = db_get_hash_array("SELECT ?:product_filters.feature_id, ?:product_filters.filter_id, ?:product_filters.field_type, ?:product_filter_descriptions.filter, ?:product_features_descriptions.prefix, ?:product_features_descriptions.suffix FROM ?:product_filters LEFT JOIN ?:product_filter_descriptions ON ?:product_filter_descriptions.filter_id = ?:product_filters.filter_id AND ?:product_filter_descriptions.lang_code = ?s LEFT JOIN ?:product_features_descriptions ON ?:product_features_descriptions.feature_id = ?:product_filters.feature_id AND ?:product_features_descriptions.lang_code = ?s WHERE ?:product_filters.status = 'A' ?p ORDER by position", 'filter_id', CART_LANGUAGE, CART_LANGUAGE, $condition);
        $fields = fn_get_product_filter_fields();
        if (empty($filters) && empty($params['advanced_filter'])) {
            return array(array(), false);
        } else {
            foreach ($filters as $k => $v) {
                if (!empty($v['feature_id'])) {
                    // Feature filters
                    $feature_ids[] = $v['feature_id'];
                } else {
                    // Product field filters
                    $_field = $fields[$v['field_type']];
                    $field_filters[$v['filter_id']] = array_merge($v, $_field);
                    $filters[$k]['condition_type'] = $_field['condition_type'];
                }
            }
        }
        // Variants
        if (!empty($variants_ids)) {
            $join .= " LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS simple_variants FROM ?:product_features_values WHERE lang_code = '" . CART_LANGUAGE . "' GROUP BY product_id) AS pfv_simple ON pfv_simple.product_id = ?:products.product_id";
            $where_condtions = array();
            foreach ($variants_ids as $k => $variant_id) {
                $where_condtions[] = db_quote(" FIND_IN_SET('?i', simple_variants)", $variant_id);
            }
            $where .= ' AND ' . implode(' AND ', $where_condtions);
        }
        // Ranges
        if (!empty($ranges_ids)) {
            $range_conditions = db_get_array("SELECT `from`, `to`, feature_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", $ranges_ids);
            foreach ($range_conditions as $k => $condition) {
                $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = ?:products.product_id AND var_val_{$k}.lang_code = ?s", CART_LANGUAGE);
                $where .= db_quote(" AND (var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $condition['from'], $condition['to'], $condition['feature_id']);
            }
        }
        if (!empty($params['filter_id']) && empty($params['view_all'])) {
            $filter_vq .= db_quote(" AND ?:product_filters.filter_id = ?i", $params['filter_id']);
            $filter_rq .= db_quote(" AND ?:product_filter_ranges.filter_id = ?i", $params['filter_id']);
        }
        if (!empty($params['view_all'])) {
            $values_fields[] = "UPPER(SUBSTRING(?:product_feature_variant_descriptions.variant, 1, 1)) AS `index`";
        }
        $_join = $join;
        // Build condition for the standart fields
        if (!empty($_field_ranges_ids)) {
            foreach ($_field_ranges_ids as $rid => $field_type) {
                $structure = $fields[$field_type];
                if ($structure['table'] !== 'products' && strpos($join, 'JOIN ?:' . $structure['table']) === false) {
                    $join .= " LEFT JOIN ?:{$structure['table']} ON ?:{$structure['table']}.product_id = ?:products.product_id";
                }
                if ($structure['condition_type'] == 'D') {
                    $range_condition = db_get_row("SELECT `from`, `to` FROM ?:product_filter_ranges WHERE range_id = ?i", $rid);
                    if (!empty($range_condition)) {
                        $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} >= ?i AND ?:{$structure['table']}.{$structure['db_field']} <= ?i", $range_condition['from'], $range_condition['to']);
                    }
                } elseif ($structure['condition_type'] == 'F') {
                    $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?i", $rid);
                } elseif ($structure['condition_type'] == 'C') {
                    $where .= db_quote(" AND ?:{$structure['table']}.{$structure['db_field']} = ?s", $rid == 1 ? 'Y' : 'N');
                }
                if (!empty($structure['join_params'])) {
                    foreach ($structure['join_params'] as $field => $param) {
                        $join .= db_quote(" AND ?:{$structure['table']}.{$field} = ?s ", $param);
                    }
                }
            }
        }
        // Product availability conditions
        $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:categories.usergroup_ids', true) . ')';
        $where .= ' AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], '?:products.usergroup_ids', true) . ')';
        $where .= db_quote(" AND ?:categories.status IN (?a) AND ?:products.status IN (?a)", array('A', 'H'), array('A'));
        $_j = " INNER JOIN ?:products_categories ON ?:products_categories.product_id = ?:products.product_id LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id";
        if (Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') {
            $_j .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = ?:products.product_id";
            $where .= " AND IF(?:products.tracking = 'O', inventory.amount > 0, ?:products.amount > 0)";
        }
        $_join .= $_j;
        $join .= $_j;
        // Localization
        $where .= fn_get_localizations_condition('?:products.localization', true);
        $where .= fn_get_localizations_condition('?:categories.localization', true);
        $variants_counts = db_get_hash_multi_array("SELECT " . implode(', ', $values_fields) . " FROM ?:product_features_values LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filters ON ?:product_filters.feature_id = ?:product_features_values.feature_id LEFT JOIN ?:product_feature_variants ON ?:product_feature_variants.variant_id = ?:product_features_values.variant_id LEFT JOIN ?:product_feature_variant_descriptions ON ?:product_feature_variant_descriptions.variant_id = ?:product_feature_variants.variant_id AND ?:product_feature_variant_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filters.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s AND ?:product_features_values.variant_id ?p ?p AND ?:product_features.feature_type IN ('S', 'M', 'E') GROUP BY ?:product_features_values.variant_id ORDER BY ?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant", array('filter_id', 'range_id'), CART_LANGUAGE, $join, $feature_ids, CART_LANGUAGE, $where, $filter_vq);
        $ranges_counts = db_get_hash_multi_array("SELECT " . implode(', ', $ranges_fields) . " FROM ?:product_filter_ranges LEFT JOIN ?:product_features_values ON ?:product_features_values.feature_id = ?:product_filter_ranges.feature_id AND ?:product_features_values.value_int >= ?:product_filter_ranges.from AND ?:product_features_values.value_int <= ?:product_filter_ranges.to LEFT JOIN ?:products ON ?:products.product_id = ?:product_features_values.product_id LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s LEFT JOIN ?:product_features ON ?:product_features.feature_id = ?:product_filter_ranges.feature_id ?p WHERE ?:product_features_values.feature_id IN (?n) AND ?:product_features_values.lang_code = ?s ?p ?p GROUP BY ?:product_filter_ranges.range_id ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", array('filter_id', 'range_id'), CART_LANGUAGE, $join, $feature_ids, CART_LANGUAGE, $where, $filter_rq);
        if (!empty($field_filters)) {
            // Field ranges
            foreach ($field_filters as $filter_id => $field) {
                $fields_join = $fields_where = '';
                // Dinamic ranges (price, amount etc)
                if ($field['condition_type'] == 'D') {
                    $fields_join = " LEFT JOIN ?:{$field['table']} ON ?:{$field['table']}.{$field['db_field']} >= ?:product_filter_ranges.from AND ?:{$field['table']}.{$field['db_field']} <= ?:product_filter_ranges.to ";
                    if (strpos($fields_join . $_join, 'JOIN ?:products ') === false) {
                        $fields_join .= db_quote(" LEFT JOIN ?:products ON ?:products.product_id = ?:product_prices.product_id AND ?:product_prices.lower_limit = 1 AND ?:product_prices.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                    } elseif (strpos($fields_join . $_join, 'JOIN ?:product_prices ') === false) {
                        $fields_join .= " LEFT JOIN ?:product_prices ON ?:product_prices.product_id = ?:products.product_id";
                    }
                    if ($field['table'] == 'product_prices') {
                        $fields_join .= db_quote(" LEFT JOIN ?:product_prices as prices_2 ON ?:product_prices.product_id = prices_2.product_id AND ?:product_prices.price > prices_2.price AND prices_2.lower_limit = 1 AND prices_2.usergroup_id IN (?n)", array_merge(array(USERGROUP_ALL), $_SESSION['auth']['usergroup_ids']));
                        $fields_where .= " AND prices_2.price IS NULL";
                    }
                    $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:product_filter_ranges.range_id, ?:product_filter_ranges_descriptions.range_name, ?:product_filter_ranges.filter_id FROM ?:product_filter_ranges LEFT JOIN ?:product_filter_ranges_descriptions ON ?:product_filter_ranges_descriptions.range_id = ?:product_filter_ranges.range_id AND ?:product_filter_ranges_descriptions.lang_code = ?s ?p WHERE ?:products.status IN ('A') AND ?:product_filter_ranges.filter_id = ?i ?p GROUP BY ?:product_filter_ranges.range_id HAVING products != 0 ORDER BY ?:product_filter_ranges.position, ?:product_filter_ranges_descriptions.range_name", 'range_id', CART_LANGUAGE, $fields_join . $_join, $filter_id, $where . $fields_where);
                    // Char values (free shipping etc)
                } elseif ($field['condition_type'] == 'C') {
                    $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['table']}.{$field['db_field']} as range_name FROM ?:{$field['table']} ?p WHERE ?:products.status = 'A' ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_name', $join, $where);
                    if (!empty($field_ranges_counts[$filter_id])) {
                        foreach ($field_ranges_counts[$filter_id] as $range_key => $range) {
                            $field_ranges_counts[$filter_id][$range_key]['range_name'] = $field['variant_descriptions'][$range['range_name']];
                            $field_ranges_counts[$filter_id][$range_key]['range_id'] = $range['range_name'] == 'Y' ? 1 : 0;
                        }
                    }
                    // Fixed values (supplier etc)
                } elseif ($field['condition_type'] == 'F') {
                    $field_ranges_counts[$filter_id] = db_get_hash_array("SELECT COUNT(DISTINCT ?:{$field['table']}.product_id) as products, ?:{$field['foreign_table']}.{$field['range_name']} as range_name, ?:{$field['foreign_table']}.{$field['foreign_index']} as range_id FROM ?:{$field['table']} LEFT JOIN ?:{$field['foreign_table']} ON ?:{$field['foreign_table']}.{$field['foreign_index']} = ?:{$field['table']}.{$field['db_field']} ?p WHERE ?:products.status IN ('A') ?p GROUP BY ?:{$field['table']}.{$field['db_field']}", 'range_id', $join, $where);
                }
            }
        }
        $merged = fn_array_merge($variants_counts, $ranges_counts, $field_ranges_counts);
        $view_all = array();
        foreach ($filters as $filter_id => $filter) {
            if (!empty($merged[$filter_id]) && empty($params['view_all']) || !empty($params['filter_id']) && $params['filter_id'] != $filter_id) {
                // Check if filter range was selected
                if (empty($filters[$filter_id]['feature_id'])) {
                    $intersect = array_intersect(array_keys($merged[$filter_id]), $field_ranges_ids);
                } else {
                    $intersect = array_intersect(array_keys($merged[$filter_id]), $variants_ids);
                }
                if (!empty($intersect)) {
                    foreach ($merged[$filter_id] as $k => $v) {
                        if (!in_array($v['range_id'], $intersect)) {
                            // Unset unselected ranges
                            unset($merged[$filter_id][$k]);
                        }
                    }
                }
                // Calculate number of ranges and compare with constant
                $count = count($merged[$filter_id]);
                if ($count > FILTERS_RANGES_MORE_COUNT && empty($params['get_all'])) {
                    $merged[$filter_id] = array_slice($merged[$filter_id], 0, FILTERS_RANGES_MORE_COUNT, true);
                    $filters[$filter_id]['more_cut'] = true;
                }
                $filters[$filter_id]['ranges'] =& $merged[$filter_id];
                // Add feature type to the filter
                $_first = reset($merged[$filter_id]);
                if (!empty($_first['feature_type'])) {
                    $filters[$filter_id]['feature_type'] = $_first['feature_type'];
                }
                if (!empty($params['simple_link']) && $filters[$filter_id]['feature_type'] == 'E') {
                    $filters[$filter_id]['simple_link'] = true;
                }
                if (empty($params['skip_other_variants'])) {
                    foreach ($filters[$filter_id]['ranges'] as $_k => $r) {
                        if (!fn_check_selected_filter($r['range_id'], !empty($r['feature_type']) ? $r['feature_type'] : '', $params, $filters[$filter_id]['field_type'])) {
                            // selected variant
                            $filters[$filter_id]['ranges'] = array($_k => $r);
                            $filters[$filter_id]['ranges'][$_k]['selected'] = true;
                            // mark selected variant
                            // Get other variants
                            $_params = $params;
                            $_params['filter_id'] = $filter_id;
                            $_params['req_range_id'] = $r['range_id'];
                            $_params['features_hash'] = fn_delete_range_from_url($params['features_hash'], $r, $filters[$filter_id]['field_type']);
                            $_params['skip_other_variants'] = true;
                            unset($_params['variant_id'], $_params['check_location']);
                            list($_f) = fn_get_filters_products_count($_params);
                            if (!empty($_f)) {
                                $_f = reset($_f);
                                // delete current range
                                foreach ($_f['ranges'] as $_rid => $_rv) {
                                    if ($_rv['range_id'] == $r['range_id']) {
                                        unset($_f['ranges'][$_rid]);
                                        break;
                                    }
                                }
                                $filters[$filter_id]['other_variants'] = $_f['ranges'];
                            }
                            break;
                        }
                    }
                } else {
                    if (!empty($params['variant_id']) && !empty($filters[$filter_id]['ranges'][$params['variant_id']])) {
                        $filters[$filter_id]['ranges'][$params['variant_id']]['selected'] = true;
                        // mark selected variant
                    }
                }
                continue;
                // If its "view all" page, return all ranges
            } elseif (!empty($params['filter_id']) && $params['filter_id'] == $filter_id && !empty($merged[$filter_id])) {
                foreach ($merged[$filter_id] as $range) {
                    if (!empty($range['index'])) {
                        // feature
                        $view_all[$range['index']][] = $range;
                    } else {
                        // custom range
                        $view_all[$filters[$range['filter_id']]['filter']][] = $range;
                    }
                }
                ksort($view_all);
            }
            // Unset filter if he is empty
            unset($filters[$filter_id]);
        }
        if (!empty($params['advanced_filter'])) {
            $_params = array('feature_types' => array('C', 'T'), 'plain' => true, 'category_ids' => array(empty($params['category_id']) ? 0 : $params['category_id']));
            list($features) = fn_get_product_features($_params);
            if (!empty($features)) {
                $filters = array_merge($filters, $features);
            }
        }
        Registry::set($key, array($filters, $view_all));
    } else {
        list($filters, $view_all) = Registry::get($key);
    }
    return array($filters, $view_all);
}
Пример #11
0
    }, $variants));
    Tygh::$app['ajax']->assign('objects', $objects);
    Tygh::$app['ajax']->assign('total_objects', $search['total_items']);
    exit;
} elseif ($mode == 'get_features_list') {
    $page_number = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1;
    $page_size = isset($_REQUEST['page_size']) ? (int) $_REQUEST['page_size'] : 10;
    $search_query = isset($_REQUEST['q']) ? $_REQUEST['q'] : null;
    $lang_code = isset($_REQUEST['lang_code']) ? $_REQUEST['lang_code'] : CART_LANGUAGE;
    $search = array('page' => $page_number, 'search_query' => $search_query, 'get_descriptions' => true);
    if (isset($_REQUEST['preselected'])) {
        $search['feature_id'] = $_REQUEST['preselected'];
        $search['plain'] = true;
        $search['exclude_group'] = true;
    }
    list($features, $search) = fn_get_product_features($search, $page_size, $lang_code);
    // This weird recursive functional code is efficient, but is not nicely readable.
    // It will be refactored along with implementing Select2 controller mode base class.
    $feature_converter = function ($feature_list) use(&$feature_converter, $lang_code) {
        return array_values(array_map(function ($feature) use(&$feature_converter, $lang_code) {
            $return = array('id' => (int) $feature['feature_id'], 'text' => $feature['description'], 'object' => array('feature_type' => $feature['feature_type']));
            if ($feature['feature_type'] == ProductFeatures::SINGLE_CHECKBOX) {
                $return['object']['variants'] = array(array('id' => 'Y', 'text' => __('yes')), array('id' => 'N', 'text' => __('no')));
            } elseif ($feature['feature_type'] == ProductFeatures::GROUP) {
                $return['children'] = array();
                if (!empty($feature['subfeatures'])) {
                    // Recursive call that fills subfeatures list
                    $return['children'] = $feature_converter($feature['subfeatures']);
                }
            } elseif (in_array($feature['feature_type'], array(ProductFeatures::TEXT_SELECTBOX, ProductFeatures::NUMBER_SELECTBOX, ProductFeatures::EXTENDED))) {
                $return['object']['variants'] = fn_url("product_features.get_variants_list?feature_id={$feature['feature_id']}&lang_code={$lang_code}");
        fn_delete_feature($_REQUEST['feature_id']);
    }
    return array(CONTROLLER_STATUS_REDIRECT, "product_features.manage");
} elseif ($mode == 'manage') {
    $params = $_REQUEST;
    $params['exclude_group'] = true;
    $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' => 'G'), 0, DESCR_SL);
    Registry::get('view')->assign('group_features', $group_features);
} elseif ($mode == 'get_feature_variants_list') {
    if (empty($_REQUEST['feature_id'])) {
        exit;
    }
    $pattern = !empty($_REQUEST['pattern']) ? $_REQUEST['pattern'] : '';
    $start = !empty($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    $limit = (!empty($_REQUEST['limit']) ? $_REQUEST['limit'] : 10) + 1;
    $sorting = db_quote("?:product_feature_variants.position, ?:product_feature_variant_descriptions.variant");
    $join = db_quote(" 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", DESCR_SL);
    $condition = db_quote(" AND ?:product_feature_variants.feature_id = ?i", $_REQUEST['feature_id']);
    fn_set_hook('get_feature_variants_list', $condition, $join, $pattern, $start, $limit);
    $objects = db_get_hash_array("SELECT SQL_CALC_FOUND_ROWS ?:product_feature_variants.variant_id AS value, ?:product_feature_variant_descriptions.variant AS name FROM ?:product_feature_variants {$join} WHERE 1 {$condition} AND ?:product_feature_variant_descriptions.variant LIKE ?l ORDER BY ?p LIMIT ?i, ?i", 'value', '%' . $pattern . '%', $sorting, $start, $limit);
    if (defined('AJAX_REQUEST') && sizeof($objects) < $limit) {
        Registry::get('ajax')->assign('completed', true);
Пример #13
0
/**
 * Get product features and convert the to common format
 *
 * @param string $lang_code language code
 * @return array formatted data
 */
function fn_promotions_get_features($lang_code = CART_LANGUAGE)
{
    $params = array('variants' => true, 'plain' => false);
    list($features) = fn_get_product_features($params);
    $res = array();
    foreach ($features as $k => $v) {
        if ($v['feature_type'] == ProductFeatures::GROUP) {
            $res[$k]['is_group'] = true;
            $res[$k]['group'] = $v['description'];
            $res[$k]['items'] = array();
            if (!empty($v['subfeatures'])) {
                foreach ($v['subfeatures'] as $_k => $_v) {
                    $res[$k]['items'][$_k]['value'] = $_v['description'];
                    if (!empty($_v['variants'])) {
                        foreach ($_v['variants'] as $__k => $__v) {
                            $res[$k]['items'][$_k]['variants'][$__k] = $__v['variant'];
                        }
                    } elseif ($_v['feature_type'] == ProductFeatures::SINGLE_CHECKBOX) {
                        $res[$k]['items'][$_k]['variants'] = array('Y' => __('yes'), 'N' => __('no'));
                    }
                }
            }
        } else {
            $res[$k]['value'] = $v['description'];
            if (!empty($v['variants'])) {
                foreach ($v['variants'] as $__k => $__v) {
                    $res[$k]['variants'][$__k] = $__v['variant'];
                }
            } elseif ($v['feature_type'] == ProductFeatures::SINGLE_CHECKBOX) {
                $res[$k]['variants'] = array('Y' => __('yes'), 'N' => __('no'));
            }
        }
    }
    return $res;
}
Пример #14
0
 }
 if (!empty($selected_fields['main_pair']) && $selected_fields['main_pair'] == 'Y') {
     $get_main_pair = true;
     $fields2update[] = 'main_pair';
 }
 if (!empty($selected_fields['data']['taxes']) && $selected_fields['data']['taxes'] == 'Y') {
     $view->assign('taxes', fn_get_taxes());
     $fields2update[] = 'taxes';
     $get_taxes = true;
 }
 if (!empty($selected_fields['data']['features']) && $selected_fields['data']['features'] == 'Y') {
     $fields2update[] = 'features';
     // get features for categories of selected products only
     $id_paths = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id IN (?n)", $product_ids);
     $_params = array('variants' => true, 'category_ids' => array_unique(explode('/', implode('/', $id_paths))));
     list($all_product_features) = fn_get_product_features($_params, 0, DESCR_SL);
     $view->assign('all_product_features', $all_product_features);
 }
 foreach ($product_ids as $value) {
     $products_data[$value] = fn_get_product_data($value, $auth, DESCR_SL, '?:products.*, ?:product_descriptions.*', false, $get_main_pair, $get_taxes);
 }
 $filled_groups = array();
 $field_names = array();
 foreach ($fields2update as $k => $field) {
     if ($field == 'main_pair') {
         $desc = 'image_pair';
     } elseif ($field == 'tracking') {
         $desc = 'inventory';
     } elseif ($field == 'edp_shipping') {
         $desc = 'downloadable_shipping';
     } elseif ($field == 'is_edp') {
Пример #15
0
 function fn_exim_get_product_features($product_id, $features_delimiter, $lang_code = CART_LANGUAGE)
 {
     $pair_delimiter = ':';
     $set_delimiter = '; ';
     $result = array();
     $_params = array('variants' => true, 'product_id' => $product_id, 'plain' => true);
     list($features) = fn_get_product_features($_params, 0, $lang_code);
     if (!empty($features)) {
         foreach ($features as $f) {
             $parent = '';
             if (!empty($f['parent_id'])) {
                 $parent = '(' . $features[$f['parent_id']]['description'] . ') ';
             }
             if (!empty($f['value']) || !empty($f['value_int'])) {
                 $result[] = fn_exim_post_item_id($f['feature_id']) . $parent . "{$f['description']}{$pair_delimiter} {$f['feature_type']}[" . (!empty($f['value']) ? $f['value'] : $f['value_int']) . ']';
             } elseif (!empty($f['variants'])) {
                 $values = array();
                 foreach ($f['variants'] as $v) {
                     if (!empty($v['selected'])) {
                         $values[] = $v['variant'];
                     }
                 }
                 if (!empty($values)) {
                     $result[] = fn_exim_post_item_id($f['feature_id']) . $parent . "{$f['description']}{$pair_delimiter} {$f['feature_type']}[" . implode($features_delimiter, $values) . ']';
                 }
             }
         }
     }
     return !empty($result) ? implode($set_delimiter, $result) : '';
 }
Пример #16
0
function fn_stat_product_search_data($search_params, $text_conditions = array())
{
    $text_conditions['find_results_with'] = (empty($search_params['q']) ? '- ' . fn_get_lang_var('empty') . ' -' : $search_params['q']) . ' [' . ($search_params['match'] == 'exact' ? fn_get_lang_var('exact_phrase') : ($search_params['match'] == 'all' ? fn_get_lang_var('all_words') : fn_get_lang_var('any_words'))) . ']';
    $_data = array();
    if (!empty($search_params['pname'])) {
        $_data[] = fn_get_lang_var('product_name');
    }
    if (!empty($search_params['pshort'])) {
        $_data[] = fn_get_lang_var('short_description');
    }
    if (!empty($search_params['pfull'])) {
        $_data[] = fn_get_lang_var('full_description');
    }
    if (!empty($search_params['pkeywords'])) {
        $_data[] = fn_get_lang_var('keywords');
    }
    if (!empty($_data)) {
        $text_conditions['search_in'] = implode(', ', $_data);
    }
    if (!empty($search_params['feature'])) {
        list($product_features) = fn_get_product_features();
        $_data = array();
        foreach ($search_params['feature'] as $feature_id) {
            $_data[] = $product_features[$feature_id]['description'];
        }
        if (!empty($_data)) {
            $text_conditions['search_by_product_features'] = implode(', ', $_data);
        }
    }
    if (!empty($search_params['cid'])) {
        $text_conditions['search_in_category'] = fn_get_category_name($search_params['cid'], CART_LANGUAGE) . (empty($search_params['subcats']) ? '' : ' [' . fn_get_lang_var('search_in_subcategories') . ']');
    }
    if (!empty($search_params['pcode'])) {
        $text_conditions['search_by_sku'] = $search_params['pcode'];
    }
    if (!empty($search_params['price_from']) || !empty($search_params['price_to'])) {
        $text_conditions['search_by_price'] = fn_format_price($search_params['price_from']) . ' - ' . fn_format_price($search_params['price_to']);
    }
    if (!empty($search_params['weight_from']) || !empty($search_params['weight_to'])) {
        $text_conditions['search_by_weight'] = (empty($search_params['weight_from']) ? '0' : $search_params['weight_from']) . ' - ' . (empty($search_params['weight_to']) ? '0' : $search_params['weight_to']) . " ({Registry::get('settings.General.weight_symbol')})";
    }
    fn_set_hook('stat_product_search_data', $search_params, $text_conditions);
    return $text_conditions;
}
Пример #17
0
            db_query('UPDATE ?:product_filters SET categories_path = ?s WHERE filter_id = ?i', implode(',', $categories), $_REQUEST['filter_id']);
        }
    }
    return array(CONTROLLER_STATUS_OK, "product_filters.manage");
}
if ($mode == 'manage') {
    $params = $_REQUEST;
    $params['get_fields'] = true;
    $params['get_descriptions'] = true;
    list($filters, $search) = fn_get_product_filters($params, Registry::get('settings.Appearance.admin_elements_per_page'));
    $view->assign('filters', $filters);
    $view->assign('search', $search);
    if (empty($filters) && defined('AJAX_REQUEST')) {
        $ajax->assign('force_redirection', "product_filters.manage");
    }
    list($filter_features) = fn_get_product_features(array('variants' => true, 'plain' => true, 'feature_types' => array('S', 'E', 'N', 'M', 'O', 'D')), 0, DESCR_SL);
    $view->assign('filter_features', $filter_features);
} elseif ($mode == 'update') {
    $params = $_REQUEST;
    $params['get_fields'] = true;
    $params['get_variants'] = true;
    list($filters) = fn_get_product_filters($params);
    $view->assign('filter', array_shift($filters));
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['filter_id'])) {
        fn_delete_product_filter($_REQUEST['filter_id']);
    }
    return array(CONTROLLER_STATUS_REDIRECT, "product_filters.manage");
}
function fn_update_product_filter($filter_data, $filter_id, $lang_code = DESCR_SL)
{
Пример #18
0
/**
 * Gets all available brands.
 *
 * @return array Found brands
 */
function fn_get_all_brands()
{
    $params = array('exclude_group' => true, 'get_descriptions' => true, 'feature_types' => array(ProductFeatures::EXTENDED), 'variants' => true, 'plain' => true);
    list($features) = fn_get_product_features($params, 0);
    $variants = array();
    foreach ($features as $feature) {
        $variants = array_merge($variants, $feature['variants']);
    }
    return $variants;
}
Пример #19
0
 /**
  * Export product features
  */
 protected function getProductFeatures($product)
 {
     static $features;
     $lang_code = $this->lang_code;
     if (!isset($features[$lang_code])) {
         list($features[$lang_code]) = fn_get_product_features(array('plain' => true), 0, $lang_code);
     }
     $product = array('product_id' => $product['product_id'], 'main_category' => $product['category_id']);
     $product_features = fn_get_product_features_list($product, 'A', $lang_code);
     $result = array();
     if (!empty($product_features)) {
         foreach ($product_features as $f) {
             $display_on_catalog = $features[$lang_code][$f['feature_id']]['display_on_catalog'];
             $display_on_product = $features[$lang_code][$f['feature_id']]['display_on_product'];
             if ($display_on_catalog == "Y" || $display_on_product == "Y") {
                 if ($f['feature_type'] == "C") {
                     $result[] = array('description' => $f['description'], 'value' => $f['value'] == "Y" ? __("yes") : __("no"));
                 } elseif ($f['feature_type'] == "S" && !empty($f['variant'])) {
                     $result[] = array('description' => $f['description'], 'value' => $f['variant']);
                 } elseif ($f['feature_type'] == "T" && !empty($f['value'])) {
                     $result[] = array('description' => $f['description'], 'value' => $f['value']);
                 } elseif ($f['feature_type'] == "M") {
                     if (!empty($f['variants'])) {
                         $_value = '';
                         $counter = count($f['variants']);
                         foreach ($f['variants'] as $_variant) {
                             if ($counter > 1) {
                                 $_value .= $_variant['variant'] . ', ';
                             } else {
                                 $_value = $_variant['variant'];
                             }
                         }
                         $_value = $counter > 1 ? substr($_value, 0, -2) : $_value;
                         $result[] = array('description' => $f['description'], 'value' => $_value);
                     }
                 } elseif ($f['feature_type'] == "N") {
                     $result[] = array('description' => $f['description'], 'value' => $f['variant']);
                 } elseif ($f['feature_type'] == "O") {
                     $result[] = array('description' => $f['description'], 'value' => $f['value_int']);
                 } elseif ($f['feature_type'] == "E") {
                     $result[] = array('description' => $f['description'], 'value' => $f['variant']);
                 }
             }
         }
     }
     return !empty($result) ? $result : '';
 }
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) : '';
}
Пример #21
0
if ($mode == 'manage' || $mode == 'picker') {
    $params = $_REQUEST;
    $params['get_descriptions'] = true;
    list($filters, $search) = fn_get_product_filters($params, Registry::get('settings.Appearance.admin_elements_per_page'));
    Tygh::$app['view']->assign('filters', $filters);
    Tygh::$app['view']->assign('search', $search);
    if (fn_allowed_for('ULTIMATE:FREE') && count($filters) > FILTERS_LIMIT) {
        fn_set_notification('W', __('warning'), __('product_filters_free_limit'));
    }
    if ($mode == 'manage') {
        Tygh::$app['view']->assign('filter_fields', fn_get_product_filter_fields());
        if (empty($filters) && defined('AJAX_REQUEST')) {
            Tygh::$app['ajax']->assign('force_redirection', fn_url('product_filters.manage'));
        }
        $params = array('variants' => true, 'plain' => true, 'feature_types' => array(ProductFeatures::SINGLE_CHECKBOX, ProductFeatures::TEXT_SELECTBOX, ProductFeatures::EXTENDED, ProductFeatures::NUMBER_SELECTBOX, ProductFeatures::MULTIPLE_CHECKBOX, ProductFeatures::NUMBER_FIELD, ProductFeatures::DATE));
        list($filter_features) = fn_get_product_features($params, 0, DESCR_SL);
        Tygh::$app['view']->assign('filter_features', $filter_features);
    }
    if ($mode == 'picker') {
        Tygh::$app['view']->display('pickers/filters/picker_contents.tpl');
        exit;
    }
} elseif ($mode == 'update') {
    $params = $_REQUEST;
    $params['get_variants'] = true;
    list($filters) = fn_get_product_filters($params);
    Tygh::$app['view']->assign('filter', array_shift($filters));
    if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) {
        Tygh::$app['view']->assign('picker_selected_companies', fn_ult_get_controller_shared_companies($_REQUEST['filter_id']));
    }
}
Пример #22
0
function fn_get_product_data_for_compare($product_ids, $action)
{
    $auth =& Tygh::$app['session']['auth'];
    $comparison_data = array('product_features' => array(0 => array()));
    $tmp = array();
    foreach ($product_ids as $product_id) {
        $product_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE, '', false, true, false, false, false, false);
        list($product_data['product_features']) = fn_get_product_features(array('product_id' => $product_id, 'product_company_id' => !empty($product_data['company_id']) ? $product_data['company_id'] : 0, 'statuses' => array('A'), 'variants' => true, 'plain' => false, 'existent_only' => true, 'variants_selected_only' => true), 0);
        fn_gather_additional_product_data($product_data, false, false, false, true, false);
        if (!empty($product_data['product_features'])) {
            foreach ($product_data['product_features'] as $k => $v) {
                if ($v['display_on_product'] === 'N' && $v['display_on_catalog'] == 'N' && $v['display_on_header'] == 'N') {
                    continue;
                }
                if ($v['feature_type'] == ProductFeatures::GROUP && empty($v['subfeatures'])) {
                    continue;
                }
                $_features = $v['feature_type'] == ProductFeatures::GROUP ? $v['subfeatures'] : array($k => $v);
                $group_id = $v['feature_type'] == ProductFeatures::GROUP ? $k : 0;
                $comparison_data['feature_groups'][$k] = $v['description'];
                foreach ($_features as $_k => $_v) {
                    if (in_array($_k, Tygh::$app['session']['excluded_features'])) {
                        if (empty($comparison_data['hidden_features'][$_k])) {
                            $comparison_data['hidden_features'][$_k] = $_v['description'];
                        }
                        continue;
                    }
                    if (empty($comparison_data['product_features'][$group_id][$_k])) {
                        $comparison_data['product_features'][$group_id][$_k] = $_v['description'];
                    }
                }
            }
        }
        $comparison_data['products'][] = $product_data;
        unset($product_data);
    }
    if ($action != 'show_all' && !empty($comparison_data['product_features'])) {
        $value = '';
        foreach ($comparison_data['product_features'] as $group_id => $v) {
            foreach ($v as $feature_id => $_v) {
                unset($value);
                $c = $action == 'similar_only' ? true : false;
                foreach ($comparison_data['products'] as $product) {
                    $features = !empty($group_id) && isset($product['product_features'][$group_id]['subfeatures']) ? $product['product_features'][$group_id]['subfeatures'] : $product['product_features'];
                    if (empty($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                    if (!isset($value)) {
                        $value = fn_get_feature_selected_value($features[$feature_id]);
                        continue;
                    } elseif ($value != fn_get_feature_selected_value($features[$feature_id])) {
                        $c = !$c;
                        break;
                    }
                }
                if ($c == false) {
                    unset($comparison_data['product_features'][$group_id][$feature_id]);
                }
            }
        }
    }
    return $comparison_data;
}