} $option_id = fn_update_product_option($_REQUEST['option_data'], $_REQUEST['option_id'], DESCR_SL); if (!empty($_REQUEST['object']) && $_REQUEST['object'] == 'product') { // FIXME (when assigning page and current url will be removed from ajax) return array(CONTROLLER_STATUS_OK, $_SERVER['HTTP_REFERER'] . '&selected_section=options'); } $suffix = ".manage"; } if ($mode == 'delete') { if (!empty($_REQUEST['option_id']) && fn_check_company_id('product_options', 'option_id', $_REQUEST['option_id']) || !empty($_REQUEST['product_id']) && fn_check_company_id('products', 'product_id', $_REQUEST['product_id'])) { $p_id = db_get_field("SELECT product_id FROM ?:product_options WHERE option_id = ?i", $_REQUEST['option_id']); if (!empty($_REQUEST['product_id']) && empty($p_id)) { // we're deleting global option from the product db_query("DELETE FROM ?:product_global_option_links WHERE product_id = ?i AND option_id = ?i", $_REQUEST['product_id'], $_REQUEST['option_id']); } else { fn_delete_product_option($_REQUEST['option_id']); } if (empty($_REQUEST['product_id']) && empty($p_id)) { // we're deleting global option itself db_query("DELETE FROM ?:product_global_option_links WHERE option_id = ?i", $_REQUEST['option_id']); } } if (!empty($_REQUEST['product_id'])) { $_options = fn_get_product_options($_REQUEST['product_id']); if (empty($_options)) { Registry::get('view')->display('views/product_options/manage.tpl'); } exit; } $suffix = ".manage"; }
function fn_delete_company($company_id) { if (empty($company_id)) { return false; } //TODO log_event // Log user deletion /*fn_log_event('companies', 'delete', array ( 'company_id' => $company_id ));*/ $condition = fn_get_company_condition('company_id'); $company_id = db_get_field("SELECT company_id FROM ?:companies WHERE 1 {$condition} AND company_id = ?i", $company_id); if (empty($company_id)) { return false; } db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id); // deleting products $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id); foreach ($product_ids as $product_id) { fn_delete_product($product_id); } // deleting shipping $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id); foreach ($shipping_ids as $shipping_id) { fn_delete_shipping($shipping_id); } if (PRODUCT_TYPE == 'MULTIVENDOR') { db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id); // deleting product_options $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id); foreach ($option_ids as $option_id) { fn_delete_product_option($option_id); } // deleting orders $order_ids = db_get_fields("SELECT order_id FROM ?:orders WHERE company_id = ?i", $company_id); foreach ($order_ids as $order_id) { fn_delete_order($order_id); } // deleting users $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i", $company_id); foreach ($user_ids as $user_id) { fn_delete_user($user_id); } // deleting pages $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id); foreach ($page_ids as $page_id) { fn_delete_page($page_id); } // deleting promotions $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id); fn_delete_promotions($promotion_ids); } //db_query("UPDATE ?:orders SET user_id = 0 WHERE company_id = ?i", $company_id); fn_set_hook('delete_company', $company_id); return true; }
function fn_delete_company($company_id) { if (empty($company_id)) { return false; } if (fn_allowed_for('MULTIVENDOR')) { // Do not delete vendor if there're any orders associated with this company if (db_get_field("SELECT COUNT(*) FROM ?:orders WHERE company_id = ?i", $company_id)) { fn_set_notification('W', __('warning'), __('unable_delete_vendor_orders_exists'), '', 'company_has_orders'); return false; } } fn_set_hook('delete_company_pre', $company_id); $result = db_query("DELETE FROM ?:companies WHERE company_id = ?i", $company_id); // deleting categories $cat_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE company_id = ?i", $company_id); foreach ($cat_ids as $cat_id) { fn_delete_category($cat_id, false); } // deleting products $product_ids = db_get_fields("SELECT product_id FROM ?:products WHERE company_id = ?i", $company_id); foreach ($product_ids as $product_id) { fn_delete_product($product_id); } // deleting shipping $shipping_ids = db_get_fields("SELECT shipping_id FROM ?:shippings WHERE company_id = ?i", $company_id); foreach ($shipping_ids as $shipping_id) { fn_delete_shipping($shipping_id); } if (fn_allowed_for('ULTIMATE')) { // deleting layouts $layouts = Layout::instance($company_id)->getList(); foreach ($layouts as $layout_id => $layout) { Layout::instance($company_id)->delete($layout_id); } } $blocks = Block::instance($company_id)->getAllUnique(); foreach ($blocks as $block) { Block::instance($company_id)->remove($block['block_id']); } $product_tabs = ProductTabs::instance($company_id)->getList(); foreach ($product_tabs as $product_tab) { ProductTabs::instance($company_id)->delete($product_tab['tab_id'], true); } $_menus = Menu::getList(db_quote(" AND company_id = ?i", $company_id)); foreach ($_menus as $menu) { Menu::delete($menu['menu_id']); } db_query("DELETE FROM ?:company_descriptions WHERE company_id = ?i", $company_id); // deleting product_options $option_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE company_id = ?i", $company_id); foreach ($option_ids as $option_id) { fn_delete_product_option($option_id); } // deleting company admins and users if (Registry::get('settings.Stores.share_users') != 'Y') { $users_condition = db_quote(' OR company_id = ?i', $company_id); } else { $users_condition = ''; // Unassign users from deleted company db_query('UPDATE ?:users SET company_id = 0 WHERE company_id = ?i', $company_id); } $user_ids = db_get_fields("SELECT user_id FROM ?:users WHERE company_id = ?i AND user_type = ?s ?p", $company_id, 'V', $users_condition); foreach ($user_ids as $user_id) { fn_delete_user($user_id); } // deleting pages $page_ids = db_get_fields("SELECT page_id FROM ?:pages WHERE company_id = ?i", $company_id); foreach ($page_ids as $page_id) { fn_delete_page($page_id); } // deleting promotions $promotion_ids = db_get_fields("SELECT promotion_id FROM ?:promotions WHERE company_id = ?i", $company_id); fn_delete_promotions($promotion_ids); // deleting features $feature_ids = db_get_fields("SELECT feature_id FROM ?:product_features WHERE company_id = ?i", $company_id); foreach ($feature_ids as $feature_id) { fn_delete_feature($feature_id); } // deleting logos $types = fn_get_logo_types(); foreach ($types as $type => $data) { fn_delete_logo($type, $company_id); } $payment_ids = db_get_fields('SELECT payment_id FROM ?:payments WHERE company_id = ?i', $company_id); foreach ($payment_ids as $payment_id) { fn_delete_payment($payment_id); } // Delete sitemap sections and links $params = array('company_id' => $company_id); $section_ids = fn_get_sitemap_sections($params); fn_delete_sitemap_sections(array_keys($section_ids)); fn_set_hook('delete_company', $company_id, $result); return $result; }
/** * Removes all product options from the product * @param int $product_id Product identifier */ function fn_poptions_delete_product($product_id) { /** * Adds additional actions before delete all product option * * @param int $product_id Product identifier */ fn_set_hook('poptions_delete_product_pre', $product_id); $option_ids = db_get_fields('SELECT option_id FROM ?:product_options WHERE product_id = ?i', $product_id); if (!empty($option_ids)) { foreach ($option_ids as $option_id) { fn_delete_product_option($option_id, $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_global_option_links WHERE product_id = ?i", $product_id); $option_combinations = db_get_fields('SELECT combination_hash FROM ?:product_options_inventory WHERE product_id = ?i', $product_id); if (!empty($option_combinations)) { foreach ($option_combinations as $hash) { fn_delete_product_combination($hash); } } /** * Adds additional actions after delete all product option * * @param int $product_id Product identifier */ fn_set_hook('poptions_delete_product_post', $product_id); }
function fn_exim_set_product_options($product_id, $data, $lang_code) { //for compatibility with the old format $data = preg_replace('{\\{\\d*\\}}', '', $data); if (!fn_is_empty($data)) { $data = fn_exim_parse_data($data); $updated_ids = array(); // store updated ids, delete other (if exist) foreach ($data as $option_key => $option) { $global_option = isset($option['global']) ? $option['global'] : false; if (!empty($option['group_name'])) { $company_id = fn_get_company_id_by_name($option['group_name']); } $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $global_option ? 0 : $product_id, $option['name'], $lang_code); $variant_ids = array(); $option['variants'] = isset($option['variants']) ? $option['variants'] : array(); foreach ($option['variants'] as $variant_pos => $variant) { $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $option_id, $variant, $lang_code); } $option_data = fn_exim_build_option_data($option, $option_id, $variant_ids, $lang_code); $option_data['company_id'] = !empty($company_id) ? $company_id : 0; if (empty($option_id)) { $option_data['product_id'] = !empty($global_option) ? 0 : $product_id; $option_data['position'] = $option_key; $updated_id = fn_update_product_option($option_data, 0, $lang_code); // Option is exist, update it } else { $updated_id = fn_update_product_option($option_data, $option_id, $lang_code); } if ($global_option) { $glob_link = array('option_id' => $updated_id, 'product_id' => $product_id); db_query('REPLACE INTO ?:product_global_option_links ?e', $glob_link); } $variant_ids = array(); foreach ($option['variants'] as $variant_pos => $variant) { $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $updated_id, $variant, $lang_code); } $updated_ids[] = $updated_id; } // Delete all other options if (!empty($updated_ids)) { $obsolete_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE option_id NOT IN (?n) AND product_id = ?i", $updated_ids, $product_id); if (!empty($obsolete_ids)) { foreach ($obsolete_ids as $o_id) { fn_delete_product_option($o_id, $product_id); } } } } return true; }
public function delete($id) { $data = array(); $status = Response::STATUS_NO_CONTENT; $product_id = $this->safeGet($params, 'product_id', 0); if (empty($product_id)) { $product_id = db_get_field('SELECT product_id FROM ?:product_options WHERE option_id = ?i', $id); } list($_status, $message) = $this->checkProductId($product_id); if ($_status != Response::STATUS_OK) { return array('status' => $status, 'data' => array('message' => $message)); } if (fn_delete_product_option($id)) { $status = Response::STATUS_NO_CONTENT; } else { $status = Response::STATUS_NOT_FOUND; } return array('status' => $status, 'data' => $data); }
function fn_exim_set_product_options($product_id, $data, $lang_code, $features_delimiter) { list($main_lang) = array_keys($data); $option_ids = array(); foreach ($data as $lang_code => $options) { //for compatibility with the old format $options = preg_replace('{\\{\\d*\\}}', '', $options); if (!fn_is_empty($options)) { reset($option_ids); $options = fn_exim_parse_data($options, ',', $features_delimiter, true); $updated_ids = array(); // store updated ids, delete other (if exist) foreach ($options as $option_key => $option) { unset($_REQUEST['file_variant_image_image_icon'], $_REQUEST['variant_image_image_data']); $global_option = isset($option['global']) ? $option['global'] : false; if (!empty($option['group_name'])) { $company_id = fn_get_company_id_by_name($option['group_name']); } if ($lang_code == $main_lang) { $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $global_option ? 0 : $product_id, $option['name'], $lang_code); } else { if ($lang_code != $main_lang && empty($option_ids)) { continue 2; } $option_id = key($option_ids); } $variant_ids = array(); $option['variants'] = isset($option['variants']) ? $option['variants'] : array(); if ($lang_code == $main_lang) { foreach ($option['variants'] as $variant_pos => $variant) { $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $option_id, $variant['name'], $lang_code); } } else { $var_ids = $option_ids[$option_id]; foreach ($option['variants'] as $variant_pos => $variant) { $variant_id = current($var_ids); if ($lang_code != $main_lang && $variant_id === false) { continue 3; } next($var_ids); $variant_ids[$variant_pos] = $variant_id; } } $option_data = fn_exim_build_option_data($option, $option_id, $variant_ids, $lang_code); if (empty($option_data)) { continue; } $option_data['company_id'] = !empty($company_id) ? $company_id : 0; // Prepare variant images if (!empty($option_data['variants'])) { foreach ($option_data['variants'] as $key => $variant) { if (!empty($variant['image'])) { $_REQUEST['file_variant_image_image_icon'][$key] = $variant['image']; $_REQUEST['type_variant_image_image_icon'][$key] = 'server'; $_REQUEST['variant_image_image_data'][$key] = array('pair_id' => false, 'type' => 'V', 'object_id' => 0, 'image_alt' => ''); } } } if (empty($option_id)) { $option_data['product_id'] = !empty($global_option) ? 0 : $product_id; $option_data['position'] = $option_key; $updated_id = fn_update_product_option($option_data, 0, $lang_code); // Option is exist, update it } else { $option_data['product_id'] = $product_id; $updated_id = fn_update_product_option($option_data, $option_id, $lang_code); } if ($lang_code == $main_lang) { $option_ids[$updated_id] = array(); } if ($global_option) { $glob_link = array('option_id' => $updated_id, 'product_id' => $product_id); db_query('REPLACE INTO ?:product_global_option_links ?e', $glob_link); } $variant_ids = array(); if ($lang_code == $main_lang) { foreach ($option['variants'] as $variant_pos => $variant) { $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $updated_id, $variant['name'], $lang_code); $option_ids[$updated_id][] = $variant_ids[$variant_pos]; } } else { $var_ids = $option_ids[$updated_id]; foreach ($option['variants'] as $variant_pos => $variant) { $variant_id = current($var_ids); if ($lang_code != $main_lang && $variant_id === false) { continue 3; } next($var_ids); $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $updated_id, $variant_id, $lang_code); } } $updated_ids[] = $updated_id; } // Delete all other options if (!empty($updated_ids)) { $obsolete_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE option_id NOT IN (?n) AND product_id = ?i", $updated_ids, $product_id); if (!empty($obsolete_ids)) { foreach ($obsolete_ids as $o_id) { fn_delete_product_option($o_id, $product_id); } } } } } return true; }
function fn_exim_set_product_options($product_id, $data, $lang_code = '') { $pair_delimiter = ':'; $set_delimiter = ';'; $vars_delimiter = ','; if (!empty($data)) { $options = explode($set_delimiter, $data); if (!empty($options)) { $updated_ids = array(); // store updated ids, delete other (if exist) $o_position = 0; foreach ($options as $option) { $o_position += 10; $pair = explode($pair_delimiter, $option); $variants = ''; if (is_array($pair)) { array_walk($pair, 'fn_trim_helper'); if (($pos = strpos($pair[1], '[')) !== false) { // option has variants $variants = substr($pair[1], $pos + 1, strlen($pair[1]) - $pos - 2); $variants = explode($vars_delimiter, $variants); } $option_str = explode('_', fn_exim_get_item_id($pair[0])); $option_id = $option_str[0]; $global_option = !empty($option_str[1]) && $option_str[1] == 'L'; if ($global_option) { $glob_link = array('option_id' => $option_id, 'product_id' => $product_id); db_query('REPLACE INTO ?:product_global_option_links ?e', $glob_link); } $_restore = false; if (!empty($option_id)) { $_restore = !db_get_field("SELECT option_id FROM ?:product_options WHERE option_id = ?i", $option_id); } // Check if product option exists - FIXME!!! Global? if (empty($option_id)) { $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $product_id, $pair[0], $lang_code); } $option_type = substr($pair[1], 0, 1); // Generate array for variants $v_data = array(); $v_data_ids = array(); if (!empty($variants) && is_array($variants)) { $position = 0; foreach ($variants as $v) { $position += 10; $v_data[] = array('variant_name' => $v, 'position' => $position); if ($variant_id = fn_exim_get_item_id($v)) { $v_data_ids[] = array('variant_id' => $variant_id, 'variant_name' => $v, 'position' => $position); } } } if ($option_type == 'C') { $v_data = $v_data_ids = array(); if (!empty($option_id)) { // check if variant exist $v_data_ids = db_get_array("SELECT * FROM ?:product_option_variants WHERE option_id = ?i AND position = 1", $option_id); } // If not, generate default variant if (empty($v_data_ids)) { $v_data_ids = array(array('position' => 1)); } } $option_data = array('option_name' => $pair[0], 'option_type' => $option_type, 'variants' => empty($v_data_ids) ? $v_data : $v_data_ids); // Option doesn't exist, create new if (empty($option_id) || $_restore) { if ($_restore) { $option_data['option_id'] = $option_id; } $option_data['product_id'] = !empty($global_option) ? 0 : $product_id; $option_data['position'] = $o_position; $updated_ids[] = fn_update_product_option($option_data, 0, $lang_code); // Option is exist, update it } else { $updated_ids[] = fn_update_product_option($option_data, $option_id, $lang_code); } } } // Delete all other options if (!empty($updated_ids)) { $obsolete_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE option_id NOT IN (?n) AND product_id = ?i", $updated_ids, $product_id); if (!empty($obsolete_ids)) { foreach ($obsolete_ids as $o_id) { fn_delete_product_option($o_id, $product_id); } } } } } return true; }