/** * Removes product by identifier * * @param int $product_id Product identifier * @return boolean Flag that defines if product was deleted */ function fn_delete_product($product_id) { $status = true; /** * Check product delete (run before product is deleted) * * @param int $product_id Product identifier * @param boolean $status Flag determines if product can be deleted, if false product is not deleted */ fn_set_hook('delete_product_pre', $product_id, $status); $product_deleted = false; if (!empty($product_id)) { if (!fn_check_company_id('products', 'product_id', $product_id)) { fn_set_notification('W', __('warning'), __('access_denied')); return false; } if ($status == false) { return false; } Block::instance()->removeDynamicObjectData('products', $product_id); // Log product deletion fn_log_event('products', 'delete', array('product_id' => $product_id)); // Delete product files fn_delete_product_files(0, $product_id); // Delete product folders fn_delete_product_file_folders(0, $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); $res = 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); if (!fn_allowed_for('ULTIMATE:FREE')) { 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); // Executing delete_product functions from active addons $product_deleted = $res; } /** * Process product delete (run after product is deleted) * * @param int $product_id Product identifier * @param bool $product_deleted True if product was deleted successfully, false otherwise */ fn_set_hook('delete_product_post', $product_id, $product_deleted); return $product_deleted; }
if ($mode == 'delete_file') { if (!empty($_REQUEST['file_id']) && !empty($_REQUEST['product_id'])) { if (fn_delete_product_files($_REQUEST['file_id']) == false) { return array(CONTROLLER_STATUS_DENIED); } list($_files) = fn_get_product_files(array('product_id' => $_REQUEST['product_id'])); list($_folder) = fn_get_product_file_folders(array('product_id' => $_REQUEST['product_id'])); if (empty($_files) && empty($_folder)) { Tygh::$app['view']->assign('product_id', $_REQUEST['product_id']); } } return array(CONTROLLER_STATUS_OK, fn_url('products.update?product_id=' . $_REQUEST['product_id'] . '&selected_section=files')); } if ($mode == 'delete_folder') { if (!empty($_REQUEST['folder_id']) && !empty($_REQUEST['product_id'])) { if (fn_delete_product_file_folders($_REQUEST['folder_id'], $_REQUEST['product_id']) == false) { return array(CONTROLLER_STATUS_DENIED); } list($product_files) = fn_get_product_files(array('product_id' => $_REQUEST['product_id'])); list($product_file_folders) = fn_get_product_file_folders(array('product_id' => $_REQUEST['product_id'])); $files_tree = fn_build_files_tree($product_file_folders, $product_files); Tygh::$app['view']->assign('product_file_folders', $product_file_folders); Tygh::$app['view']->assign('product_files', $product_files); Tygh::$app['view']->assign('files_tree', $files_tree); Tygh::$app['view']->assign('product_id', $_REQUEST['product_id']); } return array(CONTROLLER_STATUS_OK, fn_url('products.update?product_id=' . $_REQUEST['product_id'] . '&selected_section=files')); } return array(CONTROLLER_STATUS_OK, 'products' . $suffix); } //
function fn_exim_import_file($product_id, $filename, $path, $delete_files = 'N') { $path = fn_get_files_dir_path() . fn_normalize_path($path); // Clean up the directory above if flag is set if ($delete_files == 'Y') { fn_delete_product_file_folders(0, $product_id); fn_delete_product_files(0, $product_id); } // Check if we have several files $files = fn_explode(',', $filename); $folders = array(); // Create folders foreach ($files as $file) { if (strpos($file, '/') !== false) { list($folder) = fn_explode('/', $file); if (!isset($folders[$folder])) { $folder_data = array('product_id' => $product_id, 'folder_name' => $folder); $folders[$folder] = fn_update_product_file_folder($folder_data, 0); } } } // Copy files foreach ($files as $file) { if (strpos($file, '/') !== false) { list($folder_name, $file) = fn_explode('/', $file); } else { $folder_name = ''; } if (strpos($file, '#') !== false) { list($f, $pr) = fn_explode('#', $file); } else { $f = $file; $pr = ''; } $file = fn_find_file($path, $f); if (!empty($file)) { $uploads = array('file_base_file' => array($file), 'type_base_file' => array('server')); if (!empty($pr)) { $preview = fn_find_file($path, $pr); if (!empty($preview)) { $uploads['file_file_preview'] = array($preview); $uploads['type_file_preview'] = array('server'); } } else { $uploads['file_file_preview'] = ""; $uploads['type_file_preview'] = ""; } $_REQUEST = fn_array_merge($_REQUEST, $uploads); // not good to add data to $_REQUEST $file_data = array('product_id' => $product_id); if (!empty($folder_name)) { $file_data['folder_id'] = $folders[$folder_name]; } if (fn_update_product_file($file_data, 0) == false) { return false; } } } return true; }