/** * 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; }
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; } }