Beispiel #1
0
 function importCategories()
 {
     $this->useDatabase($this->sourceDB);
     $query = "SELECT * FROM `categories` ORDER BY `categories`.`cat_id` ASC";
     $result = mysqli_query($this->link, $query) or die('Failed to select categories: ' . mysqli_error($this->link));
     while ($category = mysqli_fetch_array($result, MYSQL_ASSOC)) {
         $template = array('category_id' => $category['id'], 'category' => $category['name'], 'parent_id' => $category['cat_id'], 'description' => '', 'status' => 'A', 'page_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'usergroup_ids' => '', 'position' => $category['position'], 'timestamp' => date('j/m/Y'), 'product_details_layout' => 'default', 'use_cusom_templates' => 'N', 'iscussion_type' => 'D');
         fn_update_category($template);
         echo "category {$category['name']} {$category['cat_id']} {$category['position']} added.<br>";
     }
 }
 public function update($id, $params)
 {
     $data = array();
     $status = Response::STATUS_BAD_REQUEST;
     unset($params['category_id']);
     $lang_code = $this->safeGet($params, 'lang_code', DEFAULT_LANGUAGE);
     $category_id = fn_update_category($params, $id, $lang_code);
     $this->prepareImages($params, $id);
     $updated = fn_attach_image_pairs('category_main', 'category', $id, DESCR_SL);
     if ($category_id || $updated) {
         if ($updated && fn_notification_exists('extra', '404')) {
             fn_delete_notification('404');
         }
         $status = Response::STATUS_OK;
         $data = array('category_id' => $id);
     }
     return array('status' => $status, 'data' => $data);
 }
Beispiel #3
0
     }
     $suffix = ".manage";
 }
 //
 // Processing multiple updating of category elements
 //
 if ($mode == 'm_update') {
     // Update multiple categories data
     if (is_array($_REQUEST['categories_data'])) {
         fn_attach_image_pairs('category_main', 'category', 0, DESCR_SL);
         foreach ($_REQUEST['categories_data'] as $k => $v) {
             if (!fn_allowed_for('ULTIMATE') || fn_allowed_for('ULTIMATE') && fn_check_company_id('categories', 'category_id', $k)) {
                 if (fn_allowed_for('ULTIMATE')) {
                     fn_set_company_id($v);
                 }
                 fn_update_category($v, $k, DESCR_SL);
             }
         }
     }
     $suffix = ".manage";
 }
 //
 // Processing deleting of multiple category elements
 //
 if ($mode == 'm_delete') {
     if (isset($_REQUEST['category_ids'])) {
         $category_deletion_queue = fn_filter_redundant_deleting_category_ids((array) $_REQUEST['category_ids']);
         foreach ($category_deletion_queue as $category_id) {
             if (fn_allowed_for('MULTIVENDOR') || fn_allowed_for('ULTIMATE') && fn_check_company_id('categories', 'category_id', $category_id)) {
                 fn_delete_category($category_id, true);
             }
Beispiel #4
0
                 if (!fn_twg_api_update_product($product, $product['product_id'], $lang_code)) {
                     $msg = str_replace('[object_id]', $product['product_id'], __('twgadmin_wrong_api_object_data'));
                     $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'products', __('twgadmin_wrong_api_object_data')));
                 }
             } else {
                 $response->addError('ERROR_WRONG_OBJECT_DATA', str_replace('[object]', 'products', __('twgadmin_wrong_api_object_data')));
             }
         }
     }
 }
 if ($object == 'categories') {
     if ($_REQUEST['action'] == 'update') {
         foreach ($data as $category) {
             // allow to update only order status
             if (!empty($category['category_id'])) {
                 if (!fn_update_category($category, $category['category_id'], $lang_code)) {
                     $msg = str_replace('[object_id]', $category['category_id'], __('twgadmin_wrong_api_object_data'));
                     $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'categories', __('twgadmin_wrong_api_object_data')));
                 } elseif (!empty($category['icon'])) {
                     TwigmoImage::updateIconsByApiData($category['icon'], $category['category_id'], 'category');
                 }
             } else {
                 $response->addError('ERROR_WRONG_OBJECT_DATA', str_replace('[object]', 'categories', __('twgadmin_wrong_api_object_data')));
             }
         }
     }
 }
 if ($object == 'images') {
     if ($_REQUEST['action'] == 'delete') {
         foreach ($data as $image) {
             if (empty($image['image_id'])) {
Beispiel #5
0
function fn_exim_1c_get_default_category($company_id, $settings_1c)
{
    $default_category = $settings_1c['exim_1c_default_category'];
    $default_category = db_get_field("SELECT category_id FROM ?:categories WHERE category_id = ?i", $default_category);
    if (!empty($default_category)) {
        return $default_category;
    } else {
        if (!Registry::isExist('rus_exim_1c.default_category')) {
            $category_data = array('category' => 'Default category', 'status' => 'D', 'parent_id' => 0, 'company_id' => $company_id);
            Registry::set('rus_exim_1c.default_category', fn_update_category($category_data, 0));
        }
        return Registry::get('rus_exim_1c.default_category');
    }
}
/**
 * Creates categories tree by path
 *
 * @param integer $product_id Product ID
 * @param string $link_type M - main category, A - additional
 * @param string $categories_data categories path
 * @param string $category_delimiter Delimiter in categories path
 * @param string $store_name Store name (is used for saving category company_id)
 * @return boolean True if any categories were updated.
 */
function fn_exim_set_product_categories($product_id, $link_type, $categories_data, $category_delimiter, $store_name = '')
{
    if (fn_is_empty($categories_data)) {
        return false;
    }
    $set_delimiter = ';';
    if (fn_allowed_for('ULTIMATE')) {
        $store_delimiter = ':';
        $paths_store = array();
    }
    $paths = array();
    $updated_categories = array();
    foreach ($categories_data as $lang => $data) {
        // Check if array is provided
        if (strpos($data, $set_delimiter) !== false) {
            $_paths = explode($set_delimiter, $data);
            array_walk($_paths, 'fn_trim_helper');
        } else {
            $_paths = array($data);
        }
        foreach ($_paths as $k => $cat_path) {
            if (fn_allowed_for('ULTIMATE')) {
                if (strpos($cat_path, $store_delimiter)) {
                    $cat_path = explode($store_delimiter, $cat_path);
                    $paths_store[$k] = $cat_path[0];
                    $cat_path = $cat_path[1];
                }
            }
            $category = strpos($cat_path, $category_delimiter) !== false ? explode($category_delimiter, $cat_path) : array($cat_path);
            foreach ($category as $key_cat => $cat) {
                $paths[$k][$key_cat][$lang] = $cat;
            }
        }
    }
    if (!fn_is_empty($paths)) {
        $category_condition = '';
        $joins = '';
        $select = '?:products_categories.*';
        if (fn_allowed_for('ULTIMATE')) {
            $joins = ' JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id ';
            $category_condition = fn_get_company_condition('?:categories.company_id');
            $select .= ', ?:categories.category_id, ?:categories.company_id';
        }
        $cat_ids = array();
        $old_data = db_get_hash_array("SELECT {$select} FROM ?:products_categories {$joins} WHERE product_id = ?i AND link_type = ?s {$category_condition}", 'category_id', $product_id, $link_type);
        foreach ($old_data as $k => $v) {
            if ($v['link_type'] == $link_type) {
                $updated_categories[] = $k;
            }
            $cat_ids[] = $v['category_id'];
        }
        if (!empty($cat_ids)) {
            db_query("DELETE FROM ?:products_categories WHERE product_id = ?i AND category_id IN (?a)", $product_id, $cat_ids);
        }
    }
    $company_id = 0;
    if (fn_allowed_for('ULTIMATE')) {
        if (Registry::get('runtime.company_id')) {
            $company_id = Registry::get('runtime.company_id');
        } else {
            $company_id = fn_get_company_id_by_name($store_name);
            if (!$company_id) {
                $company_data = array('company' => $store_name, 'email' => '');
                $company_id = fn_update_company($company_data, 0);
            }
        }
    }
    foreach ($paths as $key_path => $categories) {
        if (!empty($categories)) {
            $parent_id = '0';
            foreach ($categories as $cat) {
                $category_condition = '';
                if (fn_allowed_for('ULTIMATE')) {
                    if (!empty($paths_store[$key_path]) && !Registry::get('runtime.company_id')) {
                        $path_company_id = fn_get_company_id_by_name($paths_store[$key_path]);
                        $category_condition = fn_get_company_condition('?:categories.company_id', true, $path_company_id);
                    } else {
                        $category_condition = fn_get_company_condition('?:categories.company_id', true, $company_id);
                    }
                }
                reset($cat);
                $main_lang = key($cat);
                $main_cat = array_shift($cat);
                $category_id = db_get_field("SELECT ?:categories.category_id FROM ?:category_descriptions INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id {$category_condition} WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i", $main_cat, $main_lang, $parent_id);
                if (!empty($category_id)) {
                    $parent_id = $category_id;
                } else {
                    $category_data = array('parent_id' => $parent_id, 'category' => $main_cat, 'timestamp' => TIME);
                    if (fn_allowed_for('ULTIMATE')) {
                        $category_data['company_id'] = !empty($path_company_id) ? $path_company_id : $company_id;
                    }
                    $category_id = fn_update_category($category_data);
                    foreach ($cat as $lang => $cat_data) {
                        $category_data = array('parent_id' => $parent_id, 'category' => $cat_data, 'timestamp' => TIME);
                        if (fn_allowed_for('ULTIMATE')) {
                            $category_data['company_id'] = $company_id;
                        }
                        fn_update_category($category_data, $category_id, $lang);
                    }
                    $parent_id = $category_id;
                }
            }
            $data = array('product_id' => $product_id, 'category_id' => $category_id, 'link_type' => $link_type);
            if (!empty($old_data) && !empty($old_data[$category_id])) {
                $data = fn_array_merge($old_data[$category_id], $data);
            }
            db_query("REPLACE INTO ?:products_categories ?e", $data);
            $updated_categories[] = $category_id;
        }
    }
    if (!empty($updated_categories)) {
        fn_update_product_count($updated_categories);
        return true;
    }
    return false;
}
 public static function getDefaultCategory()
 {
     $default_category = self::$s_commerceml['exim_1c_default_category'];
     $default_category = db_get_field("SELECT category_id FROM ?:categories WHERE category_id = ?i", $default_category);
     if (!empty($default_category)) {
         return $default_category;
     } else {
         if (empty(self::$default_category)) {
             $category_data = array('category' => 'Default category', 'status' => 'D', 'parent_id' => 0, 'company_id' => self::$company_id);
             self::$default_category = fn_update_category($category_data, 0);
         }
         return self::$default_category;
     }
 }
Beispiel #8
0
 function fn_exim_set_product_categories($product_id, $link_type, $data, $category_delimiter, $lang_code = CART_LANGUAGE)
 {
     if (empty($data)) {
         return false;
     }
     $set_delimiter = ';';
     $paths = array();
     $updated_categories = array();
     // Check if array is provided
     if (strpos($data, $set_delimiter) !== false) {
         $paths = explode($set_delimiter, $data);
         array_walk($paths, 'fn_trim_helper');
     } else {
         $paths[] = $data;
     }
     if (!fn_is_empty($paths)) {
         $old_data = db_get_hash_array("SELECT * FROM ?:products_categories WHERE product_id= ?i", 'category_id', $product_id);
         foreach ($old_data as $k => $v) {
             if ($v['link_type'] == $link_type) {
                 $updated_categories[] = $k;
             }
         }
         db_query("DELETE FROM ?:products_categories WHERE product_id = ?i AND link_type = ?s", $product_id, $link_type);
     }
     foreach ($paths as $category) {
         $categories = strpos($category, $category_delimiter) !== false ? explode($category_delimiter, $category) : array($category);
         if (!empty($categories)) {
             $parent_id = '0';
             foreach ($categories as $cat) {
                 $category_id = db_get_field("SELECT ?:categories.category_id FROM ?:category_descriptions INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i", $cat, $lang_code, $parent_id);
                 if (!empty($category_id)) {
                     $parent_id = $category_id;
                 } else {
                     $category_data = array('parent_id' => $parent_id, 'category' => $cat);
                     $category_id = fn_update_category($category_data);
                     $parent_id = $category_id;
                 }
             }
             $data = array('product_id' => $product_id, 'category_id' => $category_id, 'link_type' => $link_type);
             if (!empty($old_data) && !empty($old_data[$category_id])) {
                 $data = fn_array_merge($old_data[$category_id], $data);
             }
             db_query("REPLACE INTO ?:products_categories ?e", $data);
             $updated_categories[] = $category_id;
         }
     }
     if (!empty($updated_categories)) {
         fn_update_product_count($updated_categories);
         return true;
     }
     return false;
 }
Beispiel #9
0
/**
 * Creates category used for trash
 *
 * @param int $company_id Company ID
 * @return int ID of trash category
 */
function fn_create_trash_category($company_id)
{
    $category_data = array('category' => __('trash_category'), 'description' => __('trash_category_description'), 'status' => 'D', 'is_trash' => 'Y', 'company_id' => $company_id, 'timestamp' => time(), 'selected_views' => '', 'product_details_view' => 'default', 'use_custom_templates' => 'N');
    $trash_id = fn_update_category($category_data);
    return $trash_id;
}