function fn_exim_set_product_feature_categories($feature_id, $feature_data, $lang_code)
{
    static $categories_ids;
    if (!empty($feature_data['parent_id'])) {
        $categories_path = '';
        $parent_feature = fn_get_product_feature_data($feature_data['parent_id']);
        if (!empty($parent_feature['categories_path'])) {
            $categories_path = $parent_feature['categories_path'];
        }
    } else {
        if (!empty($feature_data['categories_path'])) {
            $categories_path = array();
            if (!isset($categories_ids)) {
                $categories_ids = db_get_hash_single_array('SELECT category, category_id FROM ?:category_descriptions WHERE lang_code = ?s', array('category', 'category_id'), $lang_code);
            }
            $categories = explode(',', $feature_data['categories_path']);
            if (!empty($categories)) {
                foreach ($categories as $category) {
                    if (!empty($categories_ids[$category])) {
                        $categories_path[] = $categories_ids[$category];
                    }
                }
            }
            $categories_path = implode(',', $categories_path);
        } else {
            $categories_path = '';
        }
    }
    db_query("UPDATE ?:product_features SET categories_path = ?s WHERE feature_id = ?i", $categories_path, $feature_id);
    if ($feature_data['feature_type'] == 'G') {
        db_query("UPDATE ?:product_features SET categories_path = ?s WHERE parent_id = ?i", $categories_path, $feature_id);
    }
    return true;
}
Example #2
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_check_feature_variants_company_id(&$primary_object_id, &$object, &$processed_data, &$skip_record)
 {
     if (!empty($primary_object_id)) {
         $feature_id = db_get_field('SELECT feature_id FROM ?:product_feature_variants WHERE variant_id = ?i', $primary_object_id['variant_id']);
         if (empty($feature_id)) {
             $processed_data['S']++;
             $skip_record = true;
         } else {
             if (Registry::get('runtime.company_id') && !Registry::get('runtime.simple_ultimate')) {
                 $feature = fn_get_product_feature_data($feature_id);
                 if (isset($feature['company_id']) && $feature['company_id'] != Registry::get('runtime.company_id')) {
                     $processed_data['S']++;
                     $skip_record = true;
                 }
             }
         }
     }
 }
Example #4
0
/**
 * Convert Category names to its IDs
 * Example:
 *      IN array(
 *          'some_data' => ...,
 *          'categories_path' => 'Electronics,Processors'
 *      )
 *      OUT array(
 *          'some_data' => ...,
 *          'categories_path' => '12,52'
 *      )
 *
 * @param array $feature_data List of feature properties
 * @param string $lang_code 2-letters lang code
 * @return string Converted categories_path
 */
function fn_exim_get_features_convert_category_path($feature_data, $lang_code, $category_delimiter = '///')
{
    $categories_path = '';
    if (!empty($feature_data['parent_id'])) {
        $categories_path = '';
        $parent_feature = fn_get_product_feature_data($feature_data['parent_id']);
        if (!empty($parent_feature['categories_path'])) {
            $categories_path = $parent_feature['categories_path'];
        }
    } else {
        if (!empty($feature_data['categories_path'])) {
            $categories_path = array();
            if (!isset($categories_ids)) {
                $categories_ids = db_get_hash_single_array('SELECT category, category_id FROM ?:category_descriptions WHERE lang_code = ?s', array('category', 'category_id'), $lang_code);
            }
            $_categories_paths = explode(',', $feature_data['categories_path']);
            if (!empty($_categories_paths)) {
                foreach ($_categories_paths as $category_path) {
                    if (strpos($category_path, $category_delimiter)) {
                        $categories = explode($category_delimiter, $category_path);
                        array_walk($categories, 'fn_trim_helper');
                        $cat_ids_path = array();
                        foreach ($categories as $category) {
                            if (!empty($categories_ids[$category])) {
                                $cat_ids_path[] = $categories_ids[$category];
                            }
                        }
                        $cat_ids_path = implode('/', $cat_ids_path);
                        $__cat_id = db_get_field("SELECT category_id FROM ?:categories WHERE id_path = ?s", $cat_ids_path);
                        if (!empty($__cat_id)) {
                            $categories_path[] = $__cat_id;
                        }
                    } else {
                        if (!empty($categories_ids[$category])) {
                            $categories_path[] = $categories_ids[$category];
                        }
                    }
                }
            }
            $categories_path = implode(',', $categories_path);
        }
    }
    return $categories_path;
}
Example #5
0
                $filter_names_array = db_get_fields("SELECT filter FROM ?:product_filter_descriptions WHERE filter_id IN (?n) AND lang_code = ?s", $filter_ids, DESCR_SL);
                fn_set_notification('W', __('warning'), __('text_product_filters_were_disabled', array('[url]' => fn_url('product_filters.manage'), '[filters_list]' => implode(', ', $filter_names_array))));
            }
        }
        exit;
    }
    if ($mode == 'delete') {
        if (!empty($_REQUEST['feature_id'])) {
            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);
/**
 * Updates product feature
 *
 * @param array $feature_data Feature data
 * @param int $feature_id Feature identifier
 * @param string $lang_code 2-letters language code
 * @return int/boolean Feature identifier if product feature was updated, false otherwise
 */
function fn_update_product_feature($feature_data, $feature_id, $lang_code = DESCR_SL)
{
    /**
     * Changes before product feature updating
     *
     * @param array  $feature_data Feature data
     * @param int    $feature_id   Feature identifier
     * @param string $lang_code    2-letters language code
     */
    fn_set_hook('update_product_feature_pre', $feature_data, $feature_id, $lang_code);
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
        if (!empty($feature_id) && $feature_id != NEW_FEATURE_GROUP_ID) {
            if (!fn_check_company_id('product_features', 'feature_id', $feature_id)) {
                fn_company_access_denied_notification();
                return false;
            }
            unset($feature_data['company_id']);
        }
    }
    $deleted_variants = array();
    $old_feature_data = array();
    // If this feature belongs to the group, get categories assignment from this group
    if (!empty($feature_data['parent_id'])) {
        $gdata = db_get_row("SELECT categories_path, display_on_product, display_on_catalog, display_on_header FROM ?:product_features WHERE feature_id = ?i", $feature_data['parent_id']);
        if (!empty($gdata)) {
            $gdata = fn_filter_feature_group_data($gdata);
            $feature_data = fn_array_merge($feature_data, $gdata);
        }
    }
    if (!intval($feature_id)) {
        // check for intval as we use "0G" for new group
        $feature_data['feature_id'] = $feature_id = db_query("INSERT INTO ?:product_features ?e", $feature_data);
        foreach (fn_get_translation_languages() as $feature_data['lang_code'] => $_d) {
            db_query("INSERT INTO ?:product_features_descriptions ?e", $feature_data);
        }
    } else {
        $old_feature_data = fn_get_product_feature_data($feature_id, false, false, DESCR_SL);
        $arow = db_query("UPDATE ?:product_features SET ?u WHERE feature_id = ?i", $feature_data, $feature_id);
        db_query('UPDATE ?:product_features_descriptions SET ?u WHERE feature_id = ?i AND lang_code = ?s', $feature_data, $feature_id, $lang_code);
        if (!$old_feature_data) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('feature'))), '', '404');
            $feature_id = false;
        }
    }
    if ($feature_id) {
        // If this feature is group, set its categories to all children
        if ($feature_data['feature_type'] == 'G') {
            $u = array('categories_path' => !empty($feature_data['categories_path']) ? $feature_data['categories_path'] : '', 'display_on_product' => !empty($feature_data['display_on_product']) ? $feature_data['display_on_product'] : '', 'display_on_catalog' => !empty($feature_data['display_on_catalog']) ? $feature_data['display_on_catalog'] : '', 'display_on_header' => !empty($feature_data['display_on_header']) ? $feature_data['display_on_header'] : '');
            $u = fn_filter_feature_group_data($u);
            db_query("UPDATE ?:product_features SET ?u WHERE parent_id = ?i", $u, $feature_id);
        }
        // Delete variants for simple features
        $old_categories = $old_feature_data ? fn_explode(',', $old_feature_data['categories_path']) : array();
        $new_categories = isset($feature_data['categories_path']) ? fn_explode(',', $feature_data['categories_path']) : array();
        if ($old_feature_data && $feature_data['feature_type'] != $old_feature_data['feature_type']) {
            if (strpos('SMNE', $feature_data['feature_type']) === false) {
                fn_delete_product_feature_variants($feature_id);
            }
        }
        // Remove features values/variants if we changed categories list
        sort($old_categories);
        sort($new_categories);
        if (!fn_is_empty($new_categories) && (fn_is_empty($old_categories) || $old_categories != $new_categories)) {
            db_query('DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id NOT IN (SELECT product_id FROM ?:products_categories WHERE link_type = ?s AND category_id IN (?a))', $feature_id, 'M', $new_categories);
        }
        if (strpos('SMNE', $feature_data['feature_type']) !== false) {
            fn_update_product_feature_variants($feature_id, $feature_data, $lang_code);
        }
        /**
         * Adds additional actions after product feature updating
         *
         * @param array  $feature_data     Feature data
         * @param int    $feature_id       Feature identifier
         * @param array  $deleted_variants Deleted product feature variants identifiers
         * @param string $lang_code        2-letters language code
         */
        fn_set_hook('update_product_feature_post', $feature_data, $feature_id, $deleted_variants, $lang_code);
    }
    return $feature_id;
}
                $objects[] = array('value' => 'disable_select', 'name' => '-' . __('enter_other') . '-');
            }
        }
    }
    if (!$start) {
        array_unshift($objects, array('value' => '', 'name' => '-' . __('none') . '-'));
    }
    Registry::get('view')->assign('objects', $objects);
    Registry::get('view')->assign('id', $_REQUEST['result_ids']);
    Registry::get('view')->display('common/ajax_select_object.tpl');
    exit;
} elseif ($mode == 'get_variants') {
    $params = $_REQUEST;
    $params['get_images'] = true;
    list($variants, $search) = fn_get_product_feature_variants($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL);
    Registry::get('view')->assign('feature', fn_get_product_feature_data($_REQUEST['feature_id'], false, false, DESCR_SL));
    Registry::get('view')->assign('feature_variants', $variants);
    Registry::get('view')->assign('search', $search);
    Registry::get('view')->assign('feature_type', $_REQUEST['feature_type']);
    Registry::get('view')->assign('id', $_REQUEST['feature_id']);
    Registry::get('view')->display('views/product_features/components/variants_list.tpl');
    exit;
} elseif ($mode == 'update_status') {
    fn_tools_update_status($_REQUEST);
    if (!empty($_REQUEST['status']) && $_REQUEST['status'] == 'D') {
        $filter_ids = db_get_fields("SELECT filter_id FROM ?:product_filters WHERE feature_id = ?i AND status = 'A'", $_REQUEST['id']);
        if (!empty($filter_ids)) {
            db_query("UPDATE ?:product_filters SET status = 'D' WHERE filter_id IN (?n)", $filter_ids);
            $filter_names_array = db_get_fields("SELECT filter FROM ?:product_filter_descriptions WHERE filter_id IN (?n) AND lang_code = ?s", $filter_ids, DESCR_SL);
            fn_set_notification('W', __('warning'), __('text_product_filters_were_disabled', array('[url]' => fn_url('product_filters.manage'), '[filters_list]' => implode(', ', $filter_names_array))));
        }
// $Id: product_features.php 10184 2010-07-23 11:11:24Z klerik $
//
if (!defined('AREA')) {
    die('Access denied');
}
fn_define('KEEP_UPLOADED_FILES', true);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    fn_trusted_vars('feature_data');
    // Update features
    if ($mode == 'update') {
        fn_update_product_feature($_REQUEST['feature_data'], $_REQUEST['feature_id'], DESCR_SL);
    }
    return array(CONTROLLER_STATUS_OK, "product_features.manage");
}
if ($mode == 'update') {
    $view->assign('feature', fn_get_product_feature_data($_REQUEST['feature_id'], true, true, DESCR_SL));
    list($group_features) = fn_get_product_features(array('feature_types' => 'G'), 0, DESCR_SL);
    $view->assign('group_features', $group_features);
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['feature_id'])) {
        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;
    list($features, $search, $has_ungroupped) = fn_get_product_features($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL);
    $view->assign('features', $features);
    $view->assign('search', $search);
    $view->assign('has_ungroupped', $has_ungroupped);
Example #9
0
    }
    fn_add_breadcrumb($filters[$filter_id]['filter']);
    $variants = array();
    if (!empty($filters[$filter_id]['variants'])) {
        foreach ($filters[$filter_id]['variants'] as $variant) {
            $variants[fn_substr($variant['variant'], 0, 1)][] = $variant;
        }
    }
    ksort($variants);
    Tygh::$app['view']->assign('variants', $variants);
} elseif ($mode == 'view') {
    $variant_data = fn_get_product_feature_variant($_REQUEST['variant_id']);
    if (empty($variant_data)) {
        return array(CONTROLLER_STATUS_NO_PAGE);
    } else {
        $feature_data = fn_get_product_feature_data($variant_data['feature_id']);
        if (empty($feature_data)) {
            return array(CONTROLLER_STATUS_NO_PAGE);
        }
    }
    Tygh::$app['view']->assign('variant_data', $variant_data);
    fn_add_breadcrumb($variant_data['variant']);
    // Override meta description/keywords
    if (!empty($variant_data['meta_description']) || !empty($variant_data['meta_keywords'])) {
        Tygh::$app['view']->assign('meta_description', $variant_data['meta_description']);
        Tygh::$app['view']->assign('meta_keywords', $variant_data['meta_keywords']);
    }
    // Override page title
    if (!empty($variant_data['page_title'])) {
        Tygh::$app['view']->assign('page_title', $variant_data['page_title']);
    }