示例#1
0
 if ($mode == 'm_delete_combinations') {
     foreach ($_REQUEST['combination_hashes'] as $v) {
         fn_delete_option_combination($v);
     }
     $suffix = ".inventory?product_id={$_REQUEST['product_id']}";
 }
 // Apply global options to the selected products
 if ($mode == 'apply') {
     if (!empty($_REQUEST['apply_options']['options'])) {
         $_data = $_REQUEST['apply_options'];
         foreach ($_data['options'] as $key => $value) {
             $products_ids = empty($_data['product_ids']) ? array() : explode(',', $_data['product_ids']);
             foreach ($products_ids as $k) {
                 $updated_products[$k] = db_get_row("SELECT a.product_id, a.company_id, b.product FROM ?:products as a" . " LEFT JOIN ?:product_descriptions as b ON a.product_id = b.product_id" . " AND lang_code = ?s" . " WHERE a.product_id = ?i", CART_LANGUAGE, $k);
                 if ($_data['link'] == 'N') {
                     fn_clone_product_options(0, $k, $value);
                 } else {
                     db_query("REPLACE INTO ?:product_global_option_links (option_id, product_id) VALUES (?i, ?i)", $value, $k);
                     if (fn_allowed_for('ULTIMATE')) {
                         fn_ult_share_product_option($value, $k);
                     }
                 }
             }
         }
         if (!empty($updated_products)) {
             fn_set_notification('N', __('notice'), __('options_have_been_applied_to_products'));
         }
     }
     $suffix = ".apply";
 }
 if ($mode == 'update') {
示例#2
0
$_REQUEST['product_id'] = empty($_REQUEST['product_id']) ? 0 : $_REQUEST['product_id'];
if (fn_allowed_for('MULTIVENDOR')) {
    if (isset($_REQUEST['product_id']) && !fn_company_products_check($_REQUEST['product_id']) || isset($_REQUEST['product_ids']) && !fn_company_products_check($_REQUEST['product_ids'])) {
        return array(CONTROLLER_STATUS_DENIED);
    }
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $suffix = '';
    // Define trusted variables that shouldn't be stripped
    fn_trusted_vars('product_data', 'override_products_data', 'product_files_descriptions', 'add_product_files_descriptions', 'products_data', 'product_file');
    //
    // Apply Global Option
    //
    if ($mode == 'apply_global_option') {
        if ($_REQUEST['global_option']['link'] == 'N') {
            fn_clone_product_options(0, $_REQUEST['product_id'], $_REQUEST['global_option']['id']);
        } else {
            db_query("REPLACE INTO ?:product_global_option_links (option_id, product_id) VALUES(?i, ?i)", $_REQUEST['global_option']['id'], $_REQUEST['product_id']);
            if (fn_allowed_for('ULTIMATE')) {
                fn_ult_share_product_option($_REQUEST['global_option']['id'], $_REQUEST['product_id']);
            }
        }
        $suffix = ".update?product_id={$_REQUEST['product_id']}";
    }
    //
    // Create/update product
    //
    if ($mode == 'update') {
        if (!empty($_REQUEST['product_data']['product'])) {
            fn_companies_filter_company_product_categories($_REQUEST, $_REQUEST['product_data']);
            if (empty($_REQUEST['product_data']['category_ids'])) {
示例#3
0
function fn_clone_product($product_id)
{
    // Clone main data
    $data = db_get_row("SELECT * FROM ?:products WHERE product_id = ?i", $product_id);
    unset($data['product_id']);
    $data['status'] = 'D';
    $pid = db_query("INSERT INTO ?:products ?e", $data);
    // Clone descriptions
    $data = db_get_array("SELECT * FROM ?:product_descriptions WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        if ($v['lang_code'] == CART_LANGUAGE) {
            $orig_name = $v['product'];
            $new_name = $v['product'] . ' [CLONE]';
        }
        $v['product'] .= ' [CLONE]';
        db_query("INSERT INTO ?:product_descriptions ?e", $v);
    }
    // Clone prices
    $data = db_get_array("SELECT * FROM ?:product_prices WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        unset($v['price_id']);
        db_query("INSERT INTO ?:product_prices ?e", $v);
    }
    // Clone categories links
    $data = db_get_array("SELECT * FROM ?:products_categories WHERE product_id = ?i", $product_id);
    $_cids = array();
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        db_query("INSERT INTO ?:products_categories ?e", $v);
        $_cids[] = $v['category_id'];
    }
    fn_update_product_count($_cids);
    // Clone product options
    fn_clone_product_options($product_id, $pid);
    // Clone global linked options
    $gl_options = db_get_fields("SELECT option_id FROM ?:product_global_option_links WHERE product_id = ?i", $product_id);
    if (!empty($gl_options)) {
        foreach ($gl_options as $v) {
            db_query("INSERT INTO ?:product_global_option_links (option_id, product_id) VALUES (?i, ?i)", $v, $pid);
        }
    }
    // Clone product features
    $data = db_get_array("SELECT * FROM ?:product_features_values WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        db_query("INSERT INTO ?:product_features_values ?e", $v);
    }
    // Clone blocks
    fn_clone_block_links('products', $product_id, $pid);
    // Clone addons
    fn_set_hook('clone_product', $product_id, $pid);
    // Clone images
    fn_clone_image_pairs($pid, $product_id, 'product');
    // Clone product files
    if (is_dir(DIR_DOWNLOADS . $product_id)) {
        $data = db_get_array("SELECT * FROM ?:product_files WHERE product_id = ?i", $product_id);
        foreach ($data as $v) {
            $v['product_id'] = $pid;
            $old_file_id = $v['file_id'];
            unset($v['file_id']);
            $file_id = db_query("INSERT INTO ?:product_files ?e", $v);
            $file_descr = db_get_row("SELECT * FROM ?:product_file_descriptions WHERE file_id = ?i", $old_file_id);
            $file_descr['file_id'] = $file_id;
            db_query("INSERT INTO ?:product_file_descriptions ?e", $file_descr);
        }
        fn_copy(DIR_DOWNLOADS . $product_id, DIR_DOWNLOADS . $pid);
    }
    fn_build_products_cache(array($pid));
    return array('product_id' => $pid, 'orig_name' => $orig_name, 'product' => $new_name);
}
示例#4
0
function fn_clone_product($product_id)
{
    /**
     * Adds additional actions before product cloning
     *
     * @param int $product_id Original product identifier
     */
    fn_set_hook('clone_product_pre', $product_id);
    // Clone main data
    $data = db_get_row("SELECT * FROM ?:products WHERE product_id = ?i", $product_id);
    unset($data['product_id']);
    $data['status'] = 'D';
    $data['timestamp'] = $data['updated_timestamp'] = time();
    $pid = db_query("INSERT INTO ?:products ?e", $data);
    // Clone descriptions
    $data = db_get_array("SELECT * FROM ?:product_descriptions WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        if ($v['lang_code'] == CART_LANGUAGE) {
            $orig_name = $v['product'];
            $new_name = $v['product'] . ' [CLONE]';
        }
        $v['product'] .= ' [CLONE]';
        db_query("INSERT INTO ?:product_descriptions ?e", $v);
    }
    // Clone prices
    $data = db_get_array("SELECT * FROM ?:product_prices WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        unset($v['price_id']);
        db_query("INSERT INTO ?:product_prices ?e", $v);
    }
    // Clone categories links
    $data = db_get_array("SELECT * FROM ?:products_categories WHERE product_id = ?i", $product_id);
    $_cids = array();
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        db_query("INSERT INTO ?:products_categories ?e", $v);
        $_cids[] = $v['category_id'];
    }
    fn_update_product_count($_cids);
    // Clone product options
    fn_clone_product_options($product_id, $pid);
    // Clone global linked options
    $gl_options = db_get_fields("SELECT option_id FROM ?:product_global_option_links WHERE product_id = ?i", $product_id);
    if (!empty($gl_options)) {
        foreach ($gl_options as $v) {
            db_query("INSERT INTO ?:product_global_option_links (option_id, product_id) VALUES (?i, ?i)", $v, $pid);
        }
    }
    // Clone product features
    $data = db_get_array("SELECT * FROM ?:product_features_values WHERE product_id = ?i", $product_id);
    foreach ($data as $v) {
        $v['product_id'] = $pid;
        db_query("INSERT INTO ?:product_features_values ?e", $v);
    }
    // Clone blocks
    Block::instance()->cloneDynamicObjectData('products', $product_id, $pid);
    // Clone tabs info
    ProductTabs::instance()->cloneStatuses($pid, $product_id);
    // Clone addons
    fn_set_hook('clone_product', $product_id, $pid);
    // Clone images
    fn_clone_image_pairs($pid, $product_id, 'product');
    // Clone product files
    fn_clone_product_files($product_id, $pid);
    /**
     * Adds additional actions after product cloning
     *
     * @param int    $product_id Original product identifier
     * @param int    $pid        Cloned product identifier
     * @param string $orig_name  Original product name
     * @param string $new_name   Cloned product name
     */
    fn_set_hook('clone_product_post', $product_id, $pid, $orig_name, $new_name);
    return array('product_id' => $pid, 'orig_name' => $orig_name, 'product' => $new_name);
}