Example #1
0
 function deleteAllProducts()
 {
     $this->useDatabase($this->destinationDB);
     $query = "SELECT product_id FROM cscart_products";
     $result = mysqli_query($this->link, $query) or die("Failed select from: cscart_products" . mysqli_error($this->link));
     while ($item = mysqli_fetch_array($result, MYSQL_ASSOC)) {
         fn_delete_product($item['product_id']);
         echo "Item {$item['product_id']} deleted<br>";
     }
 }
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;
}
Example #3
0
 public function delete($id)
 {
     $data = array();
     $status = Response::STATUS_BAD_REQUEST;
     if (!fn_product_exists($id)) {
         $status = Response::STATUS_NOT_FOUND;
     } elseif (fn_delete_product($id)) {
         $status = Response::STATUS_NO_CONTENT;
     }
     return array('status' => $status, 'data' => $data);
 }
Example #4
0
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;
}
Example #5
0
             $_SESSION['export_ranges'] = array();
         }
         if (empty($_SESSION['export_ranges']['products'])) {
             $_SESSION['export_ranges']['products'] = array('pattern_id' => 'products');
         }
         $_SESSION['export_ranges']['products']['data'] = array('product_id' => $_REQUEST['product_ids']);
         unset($_REQUEST['redirect_url']);
         return array(CONTROLLER_STATUS_REDIRECT, 'exim.export?section=products&pattern_id=' . $_SESSION['export_ranges']['products']['pattern_id']);
     }
 }
 //
 // Delete product
 //
 if ($mode == 'delete') {
     if (!empty($_REQUEST['product_id'])) {
         $result = fn_delete_product($_REQUEST['product_id']);
         if ($result) {
             fn_set_notification('N', __('notice'), __('text_product_has_been_deleted'));
         } else {
             return array(CONTROLLER_STATUS_REDIRECT, 'products.update?product_id=' . $_REQUEST['product_id']);
         }
     }
     return array(CONTROLLER_STATUS_REDIRECT, 'products.manage');
 }
 if ($mode == 'delete_subscr') {
     if (!empty($_REQUEST['product_id'])) {
         db_query("DELETE FROM ?:product_subscriptions WHERE product_id = ?i", $_REQUEST['product_id']);
     }
     return array(CONTROLLER_STATUS_REDIRECT, 'products.p_subscr');
 }
 if ($mode == 'clone') {
/**
 * Removes category by identifier
 *
 * @param int $category_id Category identifier
 * @param boolean $recurse Flag that defines if category should be deleted recursively
 * @return int/boolean Identifiers of deleted categories or false if categories were not found
 */
function fn_delete_category($category_id, $recurse = true)
{
    /**
     * Actions before category and its related data removal
     *
     * @param  int         $category_id Category identifier to delete
     * @param  boolean     $recurse     Flag that defines if category should be deleted recursively
     * @return int|boolean Identifiers of deleted categories or false if categories were not found
     */
    fn_set_hook('delete_category_pre', $category_id, $recurse);
    if (empty($category_id)) {
        return false;
    }
    // Log category deletion
    fn_log_event('categories', 'delete', array('category_id' => $category_id));
    // Delete all subcategories
    if ($recurse == true) {
        $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
        $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE category_id = ?i OR id_path LIKE ?l", $category_id, "{$id_path}/%");
    } else {
        $category_ids[] = $category_id;
    }
    foreach ($category_ids as $k => $category_id) {
        /**
         * Process category delete (run before category is deleted)
         *
         * @param int $category_id Category identifier
         */
        fn_set_hook('delete_category_before', $category_id);
        Block::instance()->removeDynamicObjectdata('categories', $category_id);
        // Deleting category
        db_query("DELETE FROM ?:categories WHERE category_id = ?i", $category_id);
        db_query("DELETE FROM ?:category_descriptions WHERE category_id = ?i", $category_id);
        // Deleting additional product associations without deleting products itself
        db_query("DELETE FROM ?:products_categories WHERE category_id = ?i AND link_type = 'A'", $category_id);
        // Remove this category from features assignments
        db_query("UPDATE ?:product_features SET categories_path = ?p", fn_remove_from_set('categories_path', $category_id));
        if (!fn_allowed_for('ULTIMATE')) {
            // Deleting main products association with deleting products
            $products_to_delete = db_get_fields("SELECT product_id FROM ?:products_categories WHERE category_id = ?i AND link_type = 'M'", $category_id);
            if (!empty($products_to_delete)) {
                foreach ($products_to_delete as $key => $value) {
                    fn_delete_product($value);
                }
            }
        }
        // Deleting category images
        fn_delete_image_pairs($category_id, 'category');
        /**
         * Process category delete (run after category is deleted)
         *
         * @param int $category_id Category identifier
         */
        fn_set_hook('delete_category_after', $category_id);
    }
    /**
     * Actions after category and its related data removal
     *
     * @param int     $category_id  Category identifier to delete
     * @param boolean $recurse      Flag that defines if category should be deleted recursively
     * @param int     $category_ids Category identifiers that were removed
     */
    fn_set_hook('delete_category_post', $category_id, $recurse, $category_ids);
    return $category_ids;
    // Returns ids of deleted categories
}
 public static function importProductsFile($data_products, $import_params)
 {
     $cml = self::$cml;
     $type_import_products = self::$s_commerceml['exim_1c_import_products'];
     $allow_import_features = self::$s_commerceml['exim_1c_allow_import_features'];
     $add_tax = self::$s_commerceml['exim_1c_add_tax'];
     $schema_version = self::$s_commerceml['exim_1c_schema_version'];
     $type_link = self::$s_commerceml['exim_1c_import_type'];
     if (!empty(self::$features_commerceml)) {
         $features_commerceml = self::$features_commerceml;
     }
     if (!empty(self::$categories_commerceml)) {
         $categories_commerceml = self::$categories_commerceml;
     } else {
         $categories_commerceml = db_get_hash_single_array("SELECT external_id, category_id FROM ?:categories WHERE external_id <> ''", array('external_id', 'category_id'));
     }
     foreach ($data_products->{$cml}['product'] as $_product) {
         if (empty($_product->{$cml}['name'])) {
             self::addMessageLog('Name is not set for product with id: ' . $_product->{$cml}['id']);
             continue;
         }
         $ids = fn_explode('#', $_product->{$cml}['id']);
         $guid_product = array_shift($ids);
         $combination_id = 0;
         if (!empty($ids)) {
             $combination_id = reset($ids);
         }
         $article = strval($_product->{$cml}['article']);
         $barcode = strval($_product->{$cml}['bar']);
         $product_data = array();
         if ($type_link == 'article') {
             $product_data = db_get_row("SELECT product_id, update_1c FROM ?:products WHERE product_code = ?s", $article);
         } elseif ($type_link == 'barcode') {
             $product_data = db_get_row("SELECT product_id, update_1c FROM ?:products WHERE product_code = ?s", $barcode);
         } else {
             $product_data = db_get_row("SELECT product_id, update_1c FROM ?:products WHERE external_id = ?s", $guid_product);
         }
         $product_update = !empty($product_data['update_1c']) ? $product_data['update_1c'] : 'Y';
         $product_id = !empty($product_data['product_id']) ? $product_data['product_id'] : 0;
         if (!empty($_product->attributes()->{$cml}['status']) && strval($_product->attributes()->{$cml}['status']) == 'Удален') {
             if ($product_id != 0) {
                 fn_delete_product($product_id);
                 self::addMessageLog('Deleted product: ' . strval($_product->{$cml}['name']));
             }
             continue;
         }
         if (!empty($_product->{$cml}['status']) && strval($_product->{$cml}['status']) == 'Удален') {
             if ($product_id != 0) {
                 fn_delete_product($product_id);
                 self::addMessageLog('Deleted product: ' . strval($_product->{$cml}['name']));
             }
             continue;
         }
         if ($type_import_products == 'all_products' || ($type_import_products == 'new_products' || $type_import_products == 'new_update_products') && $product_id == 0 || $type_import_products == 'update_products' && $product_id != 0) {
             if ($product_update == 'Y' || $product_id == 0) {
                 $product = self::dataProductFile($_product, $product_id, $guid_product, $categories_commerceml, $import_params);
                 if ($product_id == 0) {
                     self::newDataProductFile($product, $import_params);
                 }
                 if ((isset($_product->{$cml}['properties_values']->{$cml}['property_values']) || isset($_product->{$cml}['manufacturer'])) && $allow_import_features == 'Y' && !empty(self::$features_commerceml)) {
                     self::dataProductFeatures($_product, $product, $import_params);
                 }
                 if (isset($_product->{$cml}['taxes_rates']) && $add_tax == 'Y') {
                     $product['tax_ids'] = self::addProductTaxes($_product->{$cml}['taxes_rates'], $product_id, $import_params['lang_code']);
                 }
                 $product_id = fn_update_product($product, $product_id, $import_params['lang_code']);
                 self::addMessageLog('Added product: ' . $product['product'] . ' commerceml_id: ' . strval($_product->{$cml}['id']));
                 // Import product features
                 if (!empty($product['features'])) {
                     $variants_data['product_id'] = $product_id;
                     $variants_data['lang_code'] = $import_params['lang_code'];
                     $variants_data['category_id'] = $product['category_id'];
                     self::addProductFeatures($product['features'], $variants_data, $import_params);
                 }
                 // Import images
                 $image_main = true;
                 if (isset($_product->{$cml}['image'])) {
                     foreach ($_product->{$cml}['image'] as $image) {
                         $filename = fn_basename(strval($image));
                         self::addProductImage($filename, $image_main, $product_id, $import_params);
                         $image_main = false;
                     }
                 }
                 // Import combinations
                 if (isset($_product->{$cml}['product_features']->{$cml}['product_feature']) && $schema_version == '2.07') {
                     self::addProductCombinationsNewSchema($_product->{$cml}['product_features']->{$cml}['product_feature'], $product_id, $import_params, $combination_id);
                 }
             }
         }
         if (empty($import_params['service_exchange'])) {
             fn_echo(' ');
         } else {
             fn_echo('');
         }
     }
 }
Example #8
0
 public function import($db_already_cloned)
 {
     General::setProgressTitle(__CLASS__);
     if (!$db_already_cloned) {
         if (!General::cloneImportedDB($this->store_data)) {
             return false;
         }
     } else {
         General::setEmptyProgressBar(__('importing_data'));
         General::setEmptyProgressBar(__('importing_data'));
     }
     General::connectToOriginalDB(array('table_prefix' => General::formatPrefix()));
     General::processAddons($this->store_data, __CLASS__);
     $main_sql = Registry::get('config.dir.addons') . 'store_import/database/' . $this->main_sql_filename;
     General::backupSettings();
     if (is_file($main_sql)) {
         //Process main sql
         if (!db_import_sql_file($main_sql)) {
             return false;
         }
     }
     $seo_status = db_get_field("SELECT status FROM ?:addons WHERE addon = 'seo'");
     if (!empty($seo_status)) {
         $seo_multi_language = db_get_field("SELECT value FROM ?:settings_objects_upg WHERE name = 'multi_language'");
         $seo_multi_language_vendor = db_get_hash_single_array("SELECT company_id, value FROM ?:settings_vendor_values_upg WHERE object_id = (SELECT object_id FROM ?:settings_objects_upg WHERE name = 'multi_language')", array('company_id', 'value'));
         db_query("UPDATE ?:settings_objects_upg SET value = 'category_nohtml' WHERE value = 'category' AND name = 'seo_category_type'");
         db_query("UPDATE ?:settings_vendor_values_upg SET value = 'category_nohtml' WHERE value = 'category' AND object_id = (SELECT object_id FROM ?:settings_objects_upg WHERE name = 'seo_category_type')");
         db_query("UPDATE ?:settings_objects_upg SET value = 'category' WHERE value = 'file' AND name = 'seo_category_type'");
         db_query("UPDATE ?:settings_vendor_values_upg SET value = 'category' WHERE value = 'file' AND object_id = (SELECT object_id FROM ?:settings_objects_upg WHERE name = 'seo_category_type')");
         $categories = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type='c' AND lang_code = (SELECT value FROM ?:settings_objects WHERE name='frontend_default_language')");
         if (!empty($categories)) {
             foreach ($categories as $category_id) {
                 $path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
                 $apath = explode('/', $path);
                 array_pop($apath);
                 db_query("UPDATE ?:seo_names SET path = ?s WHERE type='c' AND object_id = ?i", implode('/', $apath), $category_id);
             }
         }
         $products = db_get_fields("SELECT object_id FROM ?:seo_names RIGHT JOIN ?:products ON ?:seo_names.object_id = ?:products.product_id WHERE type='p' AND lang_code = (SELECT value FROM ?:settings_objects WHERE name='frontend_default_language')");
         if (!empty($products)) {
             $condition = '';
             if (fn_allowed_for('ULTIMATE')) {
                 $condition = fn_get_company_condition('c.company_id', false);
                 $condition = !empty($condition) ? " AND ({$condition} OR {$field} = 0)" : '';
             }
             foreach ($products as $product_id) {
                 $path = db_get_hash_single_array("SELECT c.id_path, p.link_type FROM ?:categories as c LEFT JOIN ?:products_categories as p ON p.category_id = c.category_id WHERE p.product_id = ?i ?p", array('link_type', 'id_path'), $product_id, $condition);
                 $_path = !empty($path['M']) ? $path['M'] : $path['A'];
                 db_query("UPDATE ?:seo_names SET path = ?s WHERE type='p' AND object_id = ?i", $_path, $product_id);
             }
         }
         $pages = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type='a' AND lang_code = (SELECT value FROM ?:settings_objects WHERE name='frontend_default_language')");
         if (!empty($pages)) {
             foreach ($pages as $page_id) {
                 $path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $page_id);
                 $apath = explode('/', $path);
                 array_pop($apath);
                 db_query("UPDATE ?:seo_names SET path = ?s WHERE type='a' AND object_id = ?i", implode('/', $apath), $page_id);
             }
         }
     }
     General::restoreSettings();
     if (!empty($seo_status)) {
         db_query("UPDATE ?:settings_objects SET value = ?s WHERE name = 'non_latin_symbols'", $seo_multi_language);
         foreach ($seo_multi_language_vendor as $company_id => $value) {
             db_query("REPLACE INTO ?:settings_vendor_values VALUES ((SELECT object_id FROM ?:settings_objects WHERE name = 'non_latin_symbols'), ?i, ?s)", $company_id, $value);
         }
         $map = array('product_file' => 'file', 'product_category' => 'page');
         $setting = db_get_field("SELECT value FROM ?:settings_objects WHERE name = 'seo_product_type'");
         db_query("UPDATE ?:settings_objects SET value = ?s WHERE name = 'seo_page_type'", $map[$setting]);
         $obj_id = db_get_field("SELECT object_id FROM ?:settings_objects WHERE name = 'seo_page_type'");
         $settings = db_get_array("SELECT * FROM ?:settings_vendor_values WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'seo_product_type')");
         if (!empty($settings)) {
             foreach ($settings as $vendor_setting) {
                 db_query("UPDATE ?:settings_vendor_values SET value = ?s WHERE object_id = ?i AND company_id = ?i", $map[$vendor_setting['value']], $obj_id, $vendor_setting['company_id']);
             }
         }
         db_query("UPDATE ?:settings_objects SET value = 'file' WHERE name = 'seo_other_type'");
         db_query("UPDATE ?:settings_vendor_values SET value = 'file' WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'seo_other_type')");
         $empty_product_seo_names = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type = 'p' AND object_id NOT IN (SELECT product_id FROM ?:products)");
         if ($empty_product_seo_names) {
             db_query("DELETE FROM ?:seo_names WHERE object_id IN (?n)", $empty_product_seo_names);
         }
         $empty_pages_seo_names = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type = 'a' AND object_id NOT IN (SELECT page_id FROM ?:pages)");
         if ($empty_product_seo_names) {
             db_query("DELETE FROM ?:seo_names WHERE object_id IN (?n)", $empty_product_seo_names);
         }
         $empty_categories_seo_names = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type = 'c' AND object_id NOT IN (SELECT category_id FROM ?:categories)");
         if ($empty_categories_seo_names) {
             db_query("DELETE FROM ?:seo_names WHERE object_id IN (?n)", $empty_categories_seo_names);
         }
         $empty_features_seo_names = db_get_fields("SELECT object_id FROM ?:seo_names WHERE type = 'e' AND object_id NOT IN (SELECT feature_id FROM ?:product_features)");
         if ($empty_features_seo_names) {
             db_query("DELETE FROM ?:seo_names WHERE object_id IN (?n)", $empty_features_seo_names);
         }
         $_empty_product_seo_names = db_get_array("\n                SELECT ?:seo_names.*\n                FROM ?:categories\n                RIGHT JOIN ?:products_categories ON ?:categories.category_id = ?:products_categories.category_id\n                RIGHT JOIN ?:seo_names ON ?:products_categories.product_id = ?:seo_names.object_id AND ?:categories.company_id = ?:seo_names.company_id\n                WHERE ?:categories.category_id IS NULL AND ?:seo_names.type = 'p'");
         foreach ($_empty_product_seo_names as $value) {
             db_query("DELETE FROM ?:seo_names WHERE object_id = ?i AND company_id = ?i AND type = 'p'", $value['object_id'], $value['company_id']);
         }
     }
     if (db_get_field("SELECT status FROM ?:addons WHERE addon = 'suppliers'")) {
         $query_parts = array();
         $shippings = fn_get_shippings(true);
         foreach ($shippings as $shipping_id => $shipping_name) {
             $query_parts[] = db_quote('(?i, ?i, ?s)', 0, $shipping_id, 'S');
         }
         if (!empty($query_parts)) {
             db_query('REPLACE INTO ?:supplier_links VALUES ' . implode(', ', $query_parts));
         }
     }
     $products_with_empty_categories = db_get_array("SELECT category_id, product_id FROM ?:products_categories WHERE category_id NOT IN (SELECT category_id FROM ?:categories)");
     db_query("DELETE FROM ?:products_categories WHERE category_id NOT IN (SELECT category_id FROM ?:categories)");
     foreach ($products_with_empty_categories as $k => $data) {
         $product_to_delete = db_get_field("SELECT product_id FROM ?:products_categories WHERE product_id = ?i", $data['product_id']);
         if (!$product_to_delete) {
             fn_delete_product($data['product_id']);
         } else {
             $product_category = db_get_field("SELECT category_id FROM ?:products_categories WHERE product_id = ?i", $product_to_delete);
             $company_id = db_get_field("SELECT company_id FROM ?:categories WHERE category_id = ?i", $product_category);
             db_query("UPDATE ?:products_categories SET link_type = 'A' WHERE product_id = ?i", $product_to_delete);
             db_query("UPDATE ?:products_categories SET link_type = 'M' WHERE product_id = ?i AND category_id = ?i", $product_to_delete, $product_category);
             db_query("UPDATE ?:products SET company_id = ?i WHERE product_id = ?i", $company_id, $product_to_delete);
         }
     }
     $products_with_category = db_get_hash_array("SELECT ?:products_categories.product_id, ?:categories.company_id  FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id LEFT JOIN ?:products ON ?:products.product_id = ?:products_categories.product_id WHERE ?:products.company_id = ?:categories.company_id", 'product_id');
     $products_with_foreign_category = db_get_array("SELECT ?:products_categories.product_id, ?:categories.company_id, ?:products.company_id as old_company_id  FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id LEFT JOIN ?:products ON ?:products.product_id = ?:products_categories.product_id WHERE ?:products.company_id != ?:categories.company_id AND ?:products_categories.product_id NOT IN (?n)", array_keys($products_with_category));
     if (!empty($products_with_foreign_category)) {
         foreach ($products_with_foreign_category as $key => $data) {
             db_query("UPDATE ?:products SET company_id = ?i WHERE product_id = ?i", $data['company_id'], $data['product_id']);
             if (!empty($seo_status)) {
                 db_query("DELETE FROM ?:seo_names WHERE type = 'p' AND object_id = ?i AND company_id = ?i", $data['product_id'], $data['old_company_id']);
             }
         }
     }
     General::setEmptyProgressBar();
     General::setEmptyProgressBar();
     General::setEmptyProgressBar();
     General::setEmptyProgressBar();
     return true;
 }
function fn_ult_delete_category_pre(&$category_id, $recurse)
{
    if ($recurse) {
        $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
        $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE category_id = ?i OR id_path LIKE ?l", $category_id, "{$id_path}/%");
    } else {
        $category_ids[] = $category_id;
    }
    foreach ($category_ids as $c_id) {
        $products_to_delete = db_get_fields("SELECT pc1.product_id FROM ?:products_categories pc1 LEFT JOIN ?:products_categories pc2 ON pc2.product_id = pc1.product_id AND pc2.category_id != pc1.category_id WHERE pc1.category_id = ?i and pc2.category_id IS NULL", $c_id);
        if (!empty($products_to_delete)) {
            foreach ($products_to_delete as $key => $value) {
                fn_delete_product($value);
            }
        }
        $products_to_check_sharing = db_get_fields("SELECT product_id FROM ?:products_categories WHERE category_id = ?i", $c_id);
        foreach ($products_to_check_sharing as $pid) {
            fn_check_and_update_product_sharing($pid);
        }
    }
}
Example #10
0
function fn_ult_delete_category_pre(&$category_id, $recurse)
{
    $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
    if ($recurse) {
        $categories = db_get_array("SELECT category_id, id_path FROM ?:categories WHERE category_id = ?i OR id_path LIKE ?l", $category_id, "{$id_path}/%");
    } else {
        $categories[] = array('category_id' => $category_id, 'id_path' => $id_path);
    }
    // Select products that doesn't belong to another categories,
    // except categories that are children of being deleted category.
    // This complex query is fast enough to be used instead of several queries nested in foreach loop.
    $sql = <<<SQL
(SELECT pc.product_id FROM ?:products_categories pc
   LEFT JOIN ?:products_categories pc2
    ON pc2.product_id = pc.product_id
    AND pc2.category_id != pc.category_id
 WHERE pc.category_id = ?i AND pc2.product_id IS NULL
)

UNION ALL

(SELECT only_descendants.product_id FROM

   (SELECT DISTINCT pc.product_id
    FROM ?:products_categories pc
      RIGHT JOIN ?:products_categories pc2
        ON pc2.product_id = pc.product_id
           AND pc2.category_id != pc.category_id
      RIGHT JOIN ?:categories AS c
        ON c.category_id = pc2.category_id
           AND c.id_path LIKE ?l
    WHERE pc.category_id = ?i) AS only_descendants

   LEFT JOIN

   (SELECT DISTINCT pc.product_id
    FROM ?:products_categories pc
      RIGHT JOIN ?:products_categories pc2
        ON pc2.product_id = pc.product_id
           AND pc2.category_id != pc.category_id
      RIGHT JOIN ?:categories AS c
        ON c.category_id = pc2.category_id
           AND c.id_path NOT LIKE ?l
    WHERE pc.category_id = ?i) AS only_not_descendants

    USING(product_id)

 WHERE only_not_descendants.product_id IS NULL
)
SQL;
    foreach ($categories as $category_data) {
        $products_to_delete = db_get_fields($sql, $category_data['category_id'], $id_path . '/%', $category_data['category_id'], $id_path . '/%', $category_data['category_id']);
        if (!empty($products_to_delete)) {
            foreach ($products_to_delete as $key => $value) {
                fn_delete_product($value);
            }
        }
        fn_ult_correct_category_products_sharing($category_data['category_id'], $category_data['id_path']);
        fn_update_product_count();
    }
}
Example #11
0
/**
 * 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;
}
Example #12
0
function fn_delete_category($category_id, $recurse = true)
{
    // Log category deletion
    fn_log_event('categories', 'delete', array('category_id' => $category_id));
    fn_clean_block_items('categories', $category_id);
    fn_clean_block_links('categories', $category_id);
    $category_ids = array();
    $category_ids[] = $category_id;
    if (!empty($category_ids[0])) {
        // Delete all subcategories
        if ($recurse == true) {
            $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
            $category_ids = db_get_fields("SELECT category_id FROM ?:categories WHERE category_id = ?i OR id_path LIKE ?l", $category_id, "{$id_path}/%");
        }
        foreach ($category_ids as $k => $v) {
            $category_id = $v;
            fn_clean_block_items('categories', $category_id);
            // Deleting category
            db_query("DELETE FROM ?:categories WHERE category_id = ?i", $category_id);
            db_query("DELETE FROM ?:category_descriptions WHERE category_id = ?i", $category_id);
            // Deleting additional product associations without deleting products itself
            db_query("DELETE FROM ?:products_categories WHERE category_id = ?i AND link_type = 'A'", $category_id);
            // Remove this category from features assignments
            db_query("UPDATE ?:product_features SET categories_path = ?p", fn_remove_from_set('categories_path', $v));
            // Deleting main products association with deleting products
            $products_to_delete = db_get_fields("SELECT product_id FROM ?:products_categories WHERE category_id = ?i AND link_type = 'M'", $category_id);
            if (!empty($products_to_delete)) {
                foreach ($products_to_delete as $key => $value) {
                    fn_delete_product($value);
                }
            }
            // Deleting category images
            fn_delete_image_pairs($category_id, 'category');
            // Executing delete_category functions from active addons
            fn_set_hook('delete_category', $category_id);
        }
        return $category_ids;
        // Returns ids of deleted categories
    } else {
        return false;
    }
}