combination_hash); db_query("DELETE FROM ?:product_options_inventory WHERE combination_hash = ?i", $combination_hash); fn_delete_image_pairs($combination_hash, 'product_option'); return true; } /** * Returns product creation timestamp * * @param int $product_id Product ID * @param bool $day_begin Set timestamp to beginning of the day * @return int product creation timestamp */ function fn_get_product_timestamp($product_id, $day_begin = false) { if (empty($product_id)) { return false; } $timestamp = db_get_field("SELECT timestamp FROM ?:products WHERE product_id = ?i", $product_id); if ($day_begin) { $timestamp = mktime(0,0,0, date("m", $timestamp), date("d", $timestamp), date("Y", $timestamp)); } return $timestamp; } /** * 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', // disabled '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; } /** * Returns identifier of category used for trash * * @param int $company_id Company identifier * @return int|boolean Identifier of trash category, false when none exists */ function fn_get_trash_category($company_id) { $trash_id = db_get_field( "SELECT category_id" . " FROM ?:categories" . " WHERE is_trash = 'Y'" . " AND company_id = ?i", $company_id ); if (!is_numeric($trash_id)) { $trash_id = false; } return $trash_id; } /** * Checks if category is used for trash * * @param int $category_id Category ID to check for * @return boolean Category is used for trash */ function fn_is_trash_category($category_id) { $is_trash = db_get_field( "SELECT is_trash" . " FROM ?:categories" . " WHERE category_id = ?i", $category_id ); return $is_trash == 'Y'; } /** * Adds product to trash category * * @param int $product_id Product ID * @param int $trash_category_id Trash category ID */ function fn_add_product_to_trash($product_id, $trash_category_id) { $data = array( 'product_id' => $product_id, 'category_id' => $trash_category_id, 'position' => 0, 'link_type' => 'M' ); db_query("INSERT INTO ?:products_categories ?e", $data); } /** * Moves products left without categories in their store to trash * * @param array $category_ids Deleted categories identifiers * @return array Deleted products identifiers */ function fn_trash_orphaned_products($category_ids) { $orphaned_products = array(); $trashes = array(); $category_ids = array_unique($category_ids); if ($category_ids) { $narrowed_products_list = db_get_fields( "SELECT DISTINCT product_id" . " FROM ?:products_categories" . " WHERE category_id IN (?n)", $category_ids ); if (!empty($narrowed_products_list)) { $orphaned_products = db_get_hash_single_array( "SELECT" . " cp.product_id," . " p.company_id," . " c.category_id," . " GROUP_CONCAT(c.category_id) AS owner_groups" . " FROM ?:products p" . " LEFT JOIN ?:products_categories cp" . " ON p.product_id = cp.product_id" . " LEFT JOIN ?:categories c" . " ON cp.category_id = c.category_id" . " AND p.company_id = c.company_id" . " WHERE p.product_id in (?n)" . " GROUP BY cp.product_id" . " HAVING owner_groups IS NULL", array('product_id', 'company_id'), $narrowed_products_list ); if (!empty($orphaned_products)) { // Deleting product associations db_query("DELETE FROM ?:products_categories" . " WHERE category_id IN (?n)" . " OR product_id IN (?n)", $category_ids, array_keys($orphaned_products) ); // Moving products to trash foreach($orphaned_products as $product_id => $company_id) { if (!isset($trashes[$company_id])) { $trash_category_id = fn_get_trash_category($company_id); if (!$trash_category_id) { $trash_category_id = fn_create_trash_category($company_id); } $trashes[$company_id] = $trash_category_id; } fn_add_product_to_trash($product_id, $trashes[$company_id]); } fn_update_product_count(); } } } return array($orphaned_products, $trashes); } /** * Deletes products from trash category * * @param int $trash_category_id Trash category identifier * @return array Deleted product identifiers */ function fn_empty_trash($trash_category_id) { $products_to_delete = db_get_fields( "SELECT DISTINCT product_id" . " FROM ?:products_categories" . " WHERE category_id = ?i", $trash_category_id ); if (!empty($products_to_delete)) { foreach($products_to_delete as $product_id) { fn_delete_product($product_id); } } return $products_to_delete; } /** * Filtering product data before save * * @param array &$request $_REQUEST * @param array &$product_data Product data */ function fn_filter_product_data(&$request, &$product_data) { /** * Filtering product data * * @param array $request $_REQUEST * @param array $product_data $product_data */ fn_set_hook('filter_product_data', $request, $product_data); } Service unavailable
Sorry, service is temporarily unavailable.