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); }
function fn_delete_product($product_id) { $auth =& $_SESSION['auth']; if (!empty($product_id)) { if (defined('COMPANY_ID')) { $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $product_id); if (COMPANY_ID != $company_id) { fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('access_denied')); return false; } } fn_clean_block_items('products', $product_id); fn_clean_block_links('products', $product_id); // Log product deletion fn_log_event('products', 'delete', array('product_id' => $product_id)); $category_ids = db_get_fields("SELECT category_id FROM ?:products_categories WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:products_categories WHERE product_id = ?i", $product_id); fn_update_product_count($category_ids); db_query("DELETE FROM ?:products WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_descriptions WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_features_values WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_options_exceptions WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_popularity WHERE product_id = ?i", $product_id); fn_delete_image_pairs($product_id, 'product'); // Delete product options and inventory records for this product fn_poptions_delete_product($product_id); // Delete product files fn_rm(DIR_DOWNLOADS . $product_id); fn_build_products_cache(array($product_id)); // Executing delete_product functions from active addons fn_set_hook('delete_product', $product_id); $pid = db_get_field("SELECT product_id FROM ?:products WHERE product_id = ?i", $product_id); return empty($pid) ? true : false; } else { return false; } }