public function deleteCategory($category_id)
 {
     $this->db->query("DELETE FROM " . DB_PREFIX . "category_path WHERE category_id = '" . (int) $category_id . "'");
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_path WHERE path_id = '" . (int) $category_id . "'");
     foreach ($query->rows as $result) {
         $this->deleteCategory($result['category_id']);
     }
     $this->db->query("DELETE FROM " . DB_PREFIX . "category WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "category_description WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "category_filter WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "category_to_store WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "category_to_layout WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE category_id = '" . (int) $category_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . (int) $category_id . "'");
     require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
     $seo = new ControllerCatalogSeoPack($this->registry);
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE `group` = 'seopack'");
     foreach ($query->rows as $result) {
         if (!$result['serialized']) {
             $data[$result['key']] = $result['value'];
         } else {
             $data[$result['key']] = unserialize($result['value']);
         }
     }
     if (isset($data)) {
         $parameters = $data['parameters'];
     }
     if (isset($parameters['autourls']) && $parameters['autourls']) {
         require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
         $seo = new ControllerCatalogSeoPack($this->registry);
         $query = $this->db->query("SELECT cd.category_id, cd.name, cd.language_id, l.code FROM " . DB_PREFIX . "category c \n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "category_description cd on c.category_id = cd.category_id \n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "language l on l.language_id = cd.language_id\n\t\t\t\t\t\t\t\twhere c.category_id = '" . (int) $category_id . "'");
         foreach ($query->rows as $category_row) {
             if (strlen($category_row['name']) > 1) {
                 $slug = $seo->generateSlug($category_row['name']);
                 $exist_query = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.query = 'category_id=" . $category_row['category_id'] . "' and language_id=" . $category_row['language_id']);
                 if (!$exist_query->num_rows) {
                     $exist_keyword = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "'");
                     if ($exist_keyword->num_rows) {
                         $exist_keyword_lang = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "' AND " . DB_PREFIX . "url_alias.query <> 'category_id=" . $category_row['category_id'] . "'");
                         if ($exist_keyword_lang->num_rows) {
                             $slug = $seo->generateSlug($category_row['name']) . '-' . rand();
                         } else {
                             $slug = $seo->generateSlug($category_row['name']) . '-' . $category_row['code'];
                         }
                     }
                     $add_query = "INSERT INTO " . DB_PREFIX . "url_alias (query, keyword,language_id) VALUES ('category_id=" . $category_row['category_id'] . "', '" . $slug . "', " . $category_row['language_id'] . ")";
                     $this->db->query($add_query);
                 }
             }
         }
     }
     $this->cache->delete('category');
 }
 public function deleteInformation($information_id)
 {
     $this->db->query("DELETE FROM " . DB_PREFIX . "information WHERE information_id = '" . (int) $information_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "information_description WHERE information_id = '" . (int) $information_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_store WHERE information_id = '" . (int) $information_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int) $information_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'information_id=" . (int) $information_id . "'");
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE `group` = 'seopack'");
     foreach ($query->rows as $result) {
         if (!$result['serialized']) {
             $data[$result['key']] = $result['value'];
         } else {
             $data[$result['key']] = unserialize($result['value']);
         }
     }
     if (isset($data)) {
         $parameters = $data['parameters'];
     }
     if (isset($parameters['ext'])) {
         $ext = $parameters['ext'];
     } else {
         $ext = '';
     }
     if (isset($parameters['autourls']) && $parameters['autourls']) {
         require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
         $seo = new ControllerCatalogSeoPack($this->registry);
         $query = $this->db->query("SELECT id.information_id, id.title, id.language_id, l.code FROM " . DB_PREFIX . "information i\n\t\t\t\t\t\t\tinner join " . DB_PREFIX . "information_description id on i.information_id = id.information_id \n\t\t\t\t\t\t\tinner join " . DB_PREFIX . "language l on l.language_id = id.language_id\n\t\t\t\t\t\t\twhere i.information_id = '" . (int) $information_id . "';");
         foreach ($query->rows as $info_row) {
             if (strlen($info_row['title']) > 1) {
                 $slug = $seo->generateSlug($info_row['title']) . $ext;
                 $exist_query = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.query = 'information_id=" . $info_row['information_id'] . "'  and language_id=" . $info_row['language_id']);
                 if (!$exist_query->num_rows) {
                     $exist_keyword = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "'");
                     if ($exist_keyword->num_rows) {
                         $exist_keyword_lang = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "' AND " . DB_PREFIX . "url_alias.query <> 'information_id=" . $info_row['information_id'] . "'");
                         if ($exist_keyword_lang->num_rows) {
                             $slug = $seo->generateSlug($info_row['title']) . '-' . rand();
                         } else {
                             $slug = $seo->generateSlug($info_row['title']) . '-' . $info_row['code'];
                         }
                     }
                     $add_query = "INSERT INTO " . DB_PREFIX . "url_alias (query, keyword, language_id) VALUES ('information_id=" . $info_row['information_id'] . "', '" . $slug . "', " . $info_row['language_id'] . ")";
                     $this->db->query($add_query);
                 }
             }
         }
     }
     $this->cache->delete('information');
 }
 public function deleteManufacturer($manufacturer_id)
 {
     $this->db->query("DELETE FROM " . DB_PREFIX . "manufacturer WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "manufacturer_to_store WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'manufacturer_id=" . (int) $manufacturer_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "manufacturer_description WHERE manufacturer_id = '" . (int) $manufacturer_id . "'");
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE `group` = 'seopack'");
     foreach ($query->rows as $result) {
         if (!$result['serialized']) {
             $data[$result['key']] = $result['value'];
         } else {
             $data[$result['key']] = unserialize($result['value']);
         }
     }
     if (isset($data)) {
         $parameters = $data['parameters'];
     }
     if (isset($parameters['autourls']) && $parameters['autourls']) {
         require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
         $seo = new ControllerCatalogSeoPack($this->registry);
         $query = $this->db->query("SELECT l.language_id, m.name, m.manufacturer_id, l.code from " . DB_PREFIX . "manufacturer m \n\t\t\t\t\t\tjoin " . DB_PREFIX . "language l\n\t\t\t\t\t\twhere m.manufacturer_id = '" . (int) $manufacturer_id . "';");
         foreach ($query->rows as $manufacturer_row) {
             if (strlen($manufacturer_row['name']) > 1) {
                 $slug = $seo->generateSlug($manufacturer_row['name'] . '-' . $manufacturer_row['code']);
                 $exist_query = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.query = 'manufacturer_id=" . $manufacturer_row['manufacturer_id'] . "' and language_id=" . $manufacturer_row['language_id']);
                 if (!$exist_query->num_rows) {
                     $exist_keyword = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "'");
                     if ($exist_keyword->num_rows) {
                         $slug = $seo->generateSlug($manufacturer_row['name']) . '-' . rand();
                     }
                     $add_query = "INSERT INTO " . DB_PREFIX . "url_alias (query, keyword,language_id) VALUES ('manufacturer_id=" . $manufacturer_row['manufacturer_id'] . "', '" . $slug . "', " . $manufacturer_row['language_id'] . ")";
                     $this->db->query($add_query);
                 }
             }
         }
     }
     $this->cache->delete('manufacturer');
 }
         $data[$result['key']] = unserialize($result['value']);
     }
 }
 if (isset($data)) {
     $parameters = $data['seoimageparameters'];
 } else {
     $parameters['keywords'] = '%p';
 }
 $query = $db->query("SELECT language_id FROM " . DB_PREFIX . "setting s\n\t\t\t\tinner join " . DB_PREFIX . "language l on s.value = l.code\n\t\t\t\twhere s.group = 'config' and s.key = 'config_language'\n\n\t\t\t");
 foreach ($query->rows as $language) {
     $language_id = $language['language_id'];
 }
 //Product images
 $query = $db->query("select pd.name as name, p.image as image, p.product_id as product_id, p.model as model, p.sku as sku, p.upc as upc, m.name as brand, cd.name as cname \n\t\t\tfrom " . DB_PREFIX . "product_description pd \n\t\t\tinner join " . DB_PREFIX . "product p on p.product_id = pd.product_id\n\t\t\tinner join " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id\n\t\t\tinner join " . DB_PREFIX . "category_description cd on cd.category_id = pc.category_id and cd.language_id = pd.language_id\n\t\t\tleft join " . DB_PREFIX . "manufacturer m on m.manufacturer_id = p.manufacturer_id\n\t\t\twhere pd.language_id = {$language_id}\n\t\t\t");
 require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
 $seo = new ControllerCatalogSeoPack($registry);
 foreach ($query->rows as $product) {
     if ($product['image'] != '') {
         $bef = array("%c", "%p", "%m", "%s", "%u", "%b");
         $aft = array($product['cname'], $product['name'], $product['model'], $product['sku'], $product['upc'], $product['brand']);
         $newimagename = str_replace($bef, $aft, $parameters['keywords']);
         $replace = '/' . $seo->generateSlug($newimagename) . '-' . $product['product_id'] . '.';
         $old_image = $product['image'];
         $new_image = preg_replace('/\\/([\\w\\s\\t\\a\\e\\f\\v\\W\\D\\s\\S]((?!\\/).)*?)\\./', $replace, $product['image']);
         if (file_exists(DIR_IMAGE . $old_image) && $old_image != $new_image) {
             echo 'Renaming for <b>' . $product['name'] . ' </b> -------- Image: ' . $new_image . '<br> ';
             rename(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
             $old_image = mysql_real_escape_string($old_image);
             $query = $db->query("update " . DB_PREFIX . "product set image = '" . $new_image . "' where image ='" . $old_image . "'");
             $query = $db->query("update " . DB_PREFIX . "product_image set image = '" . $new_image . "' where image ='" . $old_image . "'");
             $query = $db->query("update " . DB_PREFIX . "banner_image set image = '" . $new_image . "' where image ='" . $old_image . "'");
 public function deleteProduct($product_id)
 {
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_combination WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_combination_description WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_combination_setting WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_combination_value WHERE product_option_combination_id NOT IN (SELECT product_option_combination_id FROM " . DB_PREFIX . "product_option_combination)");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM `" . DB_PREFIX . "product_profile` WHERE `product_id` = " . (int) $product_id);
     $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_complementary WHERE product_id = '" . (int) $product_id . "'");
     $this->db->query("DELETE FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int) $product_id . "'");
     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE `group` = 'seopack'");
     foreach ($query->rows as $result) {
         if (!$result['serialized']) {
             $data[$result['key']] = $result['value'];
         } else {
             $data[$result['key']] = unserialize($result['value']);
         }
     }
     if (isset($data)) {
         $parameters = $data['parameters'];
     } else {
         $parameters['keywords'] = '%c%p';
         $parameters['tags'] = '%c%p';
         $parameters['metas'] = '%p - %f';
     }
     if (isset($parameters['ext'])) {
         $ext = $parameters['ext'];
     } else {
         $ext = '';
     }
     if (isset($parameters['autokeywords']) && $parameters['autokeywords']) {
         $query = $this->db->query("select pd.name as pname, cd.name as cname, pd.language_id as language_id, pd.product_id as product_id, p.sku as sku, p.model as model, p.upc as upc, m.name as brand  from " . DB_PREFIX . "product_description pd\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id\n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "product p on pd.product_id = p.product_id\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "category_description cd on cd.category_id = pc.category_id and cd.language_id = pd.language_id\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "manufacturer m on m.manufacturer_id = p.manufacturer_id\n\t\t\t\t\t\t\t\twhere p.product_id = '" . (int) $product_id . "';");
         //die('z');
         foreach ($query->rows as $product) {
             $bef = array("%", "_", "\"", "'", "\\");
             $aft = array("", " ", " ", " ", "");
             $included = explode('%', str_replace(array(' ', ','), '', $parameters['keywords']));
             $tags = array();
             if (in_array("p", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['pname']))))));
             }
             if (in_array("c", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['cname']))))));
             }
             if (in_array("s", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['sku']))))));
             }
             if (in_array("m", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['model']))))));
             }
             if (in_array("u", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['upc']))))));
             }
             if (in_array("b", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['brand']))))));
             }
             $keywords = '';
             foreach ($tags as $tag) {
                 if (strlen($tag) > 2) {
                     $keywords = $keywords . ' ' . strtolower($tag);
                 }
             }
             $exists = $this->db->query("select count(*) as times from " . DB_PREFIX . "product_description where product_id = " . $product['product_id'] . " and language_id = " . $product['language_id'] . " and meta_keyword like '%" . $keywords . "%';");
             foreach ($exists->rows as $exist) {
                 $count = $exist['times'];
             }
             $exists = $this->db->query("select length(meta_keyword) as leng from " . DB_PREFIX . "product_description where product_id = " . $product['product_id'] . " and language_id = " . $product['language_id'] . ";");
             foreach ($exists->rows as $exist) {
                 $leng = $exist['leng'];
             }
             if ($count == 0 && $leng < 255) {
                 $this->db->query("update " . DB_PREFIX . "product_description set meta_keyword = concat(meta_keyword, '" . htmlspecialchars($keywords) . "') where product_id = " . $product['product_id'] . " and language_id = " . $product['language_id'] . ";");
             }
         }
     }
     if (isset($parameters['autometa']) && $parameters['autometa']) {
         $query = $this->db->query("select pd.name as pname, p.price as price, cd.name as cname, pd.description as pdescription, pd.language_id as language_id, pd.product_id as product_id, p.model as model, p.sku as sku, p.upc as upc, m.name as brand from " . DB_PREFIX . "product_description pd\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id\n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "product p on pd.product_id = p.product_id\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "category_description cd on cd.category_id = pc.category_id and cd.language_id = pd.language_id\n\t\t\t\t\t\t\t\tleft join " . DB_PREFIX . "manufacturer m on m.manufacturer_id = p.manufacturer_id\n\t\t\t\t\t\t\t\twhere p.product_id = '" . (int) $product_id . "';");
         foreach ($query->rows as $product) {
             $bef = array("%", "_", "\"", "'", "\\", "\r", "\n");
             $aft = array("", " ", " ", " ", "", "", "");
             $ncategory = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['cname']))));
             $nproduct = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['pname']))));
             $model = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['model']))));
             $sku = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['sku']))));
             $upc = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['upc']))));
             $content = strip_tags(html_entity_decode($product['pdescription']));
             $pos = strpos($content, '.');
             if ($pos === false) {
             } else {
                 $content = substr($content, 0, $pos + 1);
             }
             $sentence = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $content))));
             $brand = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['brand']))));
             $price = trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, number_format($product['price'], 2)))));
             $bef = array("%c", "%p", "%m", "%s", "%u", "%f", "%b", "%\$");
             $aft = array($ncategory, $nproduct, $model, $sku, $upc, $sentence, $brand, $price);
             $meta_description = str_replace($bef, $aft, $parameters['metas']);
             $exists = $this->db->query("select count(*) as times from " . DB_PREFIX . "product_description where product_id = " . $product['product_id'] . " and language_id = " . $product['language_id'] . " and meta_description not like '%" . htmlspecialchars($meta_description) . "%';");
             foreach ($exists->rows as $exist) {
                 $count = $exist['times'];
             }
             if ($count) {
                 $this->db->query("update " . DB_PREFIX . "product_description set meta_description = concat(meta_description, '" . htmlspecialchars($meta_description) . "') where product_id = " . $product['product_id'] . " and language_id = " . $product['language_id'] . ";");
             }
         }
     }
     if (isset($parameters['autotags']) && $parameters['autotags']) {
         $query = $this->db->query("select pd.name as pname, pd.tag, cd.name as cname, pd.language_id as language_id, pd.product_id as product_id, p.sku as sku, p.model as model, p.upc as upc, m.name as brand from " . DB_PREFIX . "product_description pd\n\t\t\t\t\t\t\tinner join " . DB_PREFIX . "product_to_category pc on pd.product_id = pc.product_id\n\t\t\t\t\t\t\tinner join " . DB_PREFIX . "product p on pd.product_id = p.product_id\n\t\t\t\t\t\t\tinner join " . DB_PREFIX . "category_description cd on cd.category_id = pc.category_id and cd.language_id = pd.language_id\n\t\t\t\t\t\t\tleft join " . DB_PREFIX . "manufacturer m on m.manufacturer_id = p.manufacturer_id\n\t\t\t\t\t\t\twhere p.product_id = '" . (int) $product_id . "';");
         foreach ($query->rows as $product) {
             $newtags = '';
             $included = explode('%', str_replace(array(' ', ','), '', $parameters['tags']));
             $tags = array();
             $bef = array("%", "_", "\"", "'", "\\");
             $aft = array("", " ", " ", " ", "");
             if (in_array("p", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['pname']))))));
             }
             if (in_array("c", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['cname']))))));
             }
             if (in_array("s", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['sku']))))));
             }
             if (in_array("m", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['model']))))));
             }
             if (in_array("u", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['upc']))))));
             }
             if (in_array("b", $included)) {
                 $tags = array_merge($tags, explode(' ', trim(mysql_real_escape_string(htmlspecialchars_decode(str_replace($bef, $aft, $product['brand']))))));
             }
             foreach ($tags as $tag) {
                 if (strlen($tag) > 2) {
                     if (strpos($product['tag'], strtolower($tag)) === false && strpos($newtags, strtolower($tag)) === false) {
                         $newtags .= ' ' . strtolower($tag) . ',';
                     }
                 }
             }
             if ($product['tag']) {
                 $newtags = trim(mysql_real_escape_string($product['tag']) . $newtags, ' ,');
                 $this->db->query("update " . DB_PREFIX . "product_description set tag = '{$newtags}' where product_id = '" . $product['product_id'] . "' and language_id = '" . $product['language_id'] . "';");
             } else {
                 $newtags = trim($newtags, ' ,');
                 $this->db->query("update " . DB_PREFIX . "product_description set tag = '{$newtags}' where product_id = '" . $product['product_id'] . "' and language_id = '" . $product['language_id'] . "';");
             }
         }
     }
     if (isset($parameters['autourls']) && $parameters['autourls']) {
         require_once DIR_APPLICATION . 'controller/catalog/seopack.php';
         $seo = new ControllerCatalogSeoPack($this->registry);
         $query = $this->db->query("SELECT pd.product_id, pd.name, pd.language_id ,l.code FROM " . DB_PREFIX . "product p \n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "product_description pd ON p.product_id = pd.product_id \n\t\t\t\t\t\t\t\tinner join " . DB_PREFIX . "language l on l.language_id = pd.language_id \n\t\t\t\t\t\t\t\twhere p.product_id = '" . (int) $product_id . "';");
         foreach ($query->rows as $product_row) {
             if (strlen($product_row['name']) > 1) {
                 $slug = $seo->generateSlug($product_row['name']) . $ext;
                 $exist_query = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.query = 'product_id=" . $product_row['product_id'] . "' and language_id=" . $product_row['language_id']);
                 if (!$exist_query->num_rows) {
                     $exist_keyword = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "'");
                     if ($exist_keyword->num_rows) {
                         $exist_keyword_lang = $this->db->query("SELECT query FROM " . DB_PREFIX . "url_alias WHERE " . DB_PREFIX . "url_alias.keyword = '" . $slug . "' AND " . DB_PREFIX . "url_alias.query <> 'product_id=" . $product_row['product_id'] . "'");
                         if ($exist_keyword_lang->num_rows) {
                             $slug = $seo->generateSlug($product_row['name']) . '-' . rand() . $ext;
                         } else {
                             $slug = $seo->generateSlug($product_row['name']) . '-' . $product_row['code'] . $ext;
                         }
                     }
                     $add_query = "INSERT INTO " . DB_PREFIX . "url_alias (query, keyword, language_id) VALUES ('product_id=" . $product_row['product_id'] . "', '" . $slug . "', " . $product_row['language_id'] . ")";
                     $this->db->query($add_query);
                 }
             }
         }
     }
     $this->db->query("DELETE FROM " . DB_PREFIX . "product_description_download_pdf WHERE product_id = '" . (int) $product_id . "'");
     $this->cache->delete('product');
 }