From a6f549207ab85635fc353acbcefc879e24fee1a5 Mon Sep 17 00:00:00 2001 From: vChabot Date: Wed, 21 Dec 2011 16:18:24 +0000 Subject: [PATCH] // removing categories assocation with shop --- .../themes/template/helper/form/form.tpl | 2 - admin-dev/themes/template/products/form.tpl | 9 -- classes/Category.php | 7 -- classes/Search.php | 4 - classes/shop/Shop.php | 100 ------------------ .../admin/AdminCategoriesController.php | 3 +- controllers/admin/AdminShopController.php | 12 --- controllers/front/CategoryController.php | 5 - install-dev/sql/db.sql | 7 -- install-dev/sql/db_settings_extends.sql | 4 - install-dev/sql/db_settings_lite.sql | 2 - modules/blockcategories/blockcategories.php | 22 ++-- 12 files changed, 10 insertions(+), 167 deletions(-) diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index bf33dac9b..ac8fe0ff2 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -261,8 +261,6 @@ {include file='helper/assoshop.tpl' input=$input fields_value=$fields_value} {elseif $input.type == 'categories'} {include file='helper/form/form_category.tpl' categories=$input.values} - {elseif $input.type == 'categories_select'} - {$input.category_tree} {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} {$asso_shop} {elseif $input.type == 'color'} diff --git a/admin-dev/themes/template/products/form.tpl b/admin-dev/themes/template/products/form.tpl index 1b2fa0cc6..8cefb482b 100644 --- a/admin-dev/themes/template/products/form.tpl +++ b/admin-dev/themes/template/products/form.tpl @@ -236,15 +236,6 @@

{/if} - {if isset($warning_unavailable_product)} -
-

- - {l s='This product is active in this shop but it doesn\'t belong to any active category for this shop.'} - -

-
- {/if} {* all input are here *} {foreach $product_tabs key=numStep item=tab} diff --git a/classes/Category.php b/classes/Category.php index 126236c9b..2943ddc9d 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -663,10 +663,8 @@ class CategoryCore extends ObjectModel SELECT c.`id_category`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.Context::getContext()->shop->addSqlRestrictionOnLang('cl').' - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category` WHERE `id_lang` = '.(int)$id_lang.' AND c.`id_parent` = '.(int)$id_parent.' - AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true).' '.($active ? 'AND `active` = 1' : '').' ORDER BY `position` ASC'); } @@ -715,10 +713,8 @@ class CategoryCore extends ObjectModel )' : '0').' AS nbSelectedSubCat FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.$shop->addSqlRestrictionOnLang('cl').' - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category` WHERE `id_lang` = '.(int)$id_lang.' AND c.`id_parent` = '.(int)$id_parent.' - AND cs.`id_shop` = '.(int)$shop->getID(true).' ORDER BY `position` ASC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } @@ -887,10 +883,7 @@ class CategoryCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('cl').') - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs - ON c.`id_category` = cs.`id_category` WHERE c.`id_category` = '.(int)$id_current.' - AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true).' AND c.`id_parent` != 0 '); diff --git a/classes/Search.php b/classes/Search.php index ccd902044..83eee8dc2 100644 --- a/classes/Search.php +++ b/classes/Search.php @@ -595,9 +595,7 @@ class SearchCore LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`) WHERE p.`active` = 1 - AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().' AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$id_customer.')').' @@ -631,10 +629,8 @@ class SearchCore LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`) '.Product::sqlStock('p', 0).' WHERE p.`active` = 1 - AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().' AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$id_customer.')').' diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index e51562d33..57196a565 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -889,104 +889,4 @@ class ShopCore extends ObjectModel $without[] = $shop; return $without; } - - public static function getCategories($id = 0) - { - // build query - $query = new DbQuery(); - $query->select('id_category'); - $query->from('category_shop'); - $query->where('id_shop = '.(int)$id - ); - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); - - $array = array(); - foreach ($result as $row) - $array[] = $row['id_category']; - - return $array; - } - - /** - * Update categories for a shop - * - * @param string $productCategories Categories list to associate a shop - * @return array Update/insertion result - */ - public function updateCategories($categories) - { - // if array is empty or if the default category is not selected, return false - if (empty($categories) || !in_array($this->id_category, $categories)) - return false; - - // delete categories for this shop - $this->deleteCategories(); - - // and add $categories to this shop - return $this->addToCategories($categories); - } - - /** - * Delete shop from category $id_category - * @param int $id_category - * @return bool - */ - public function deleteCategory($id_category) - { - return Db::getInstance()->execute( - 'DELETE FROM `'._DB_PREFIX_.'category_shop` - WHERE `id_shop` = '.(int)$this->id.' - AND id_category = '.(int)$id_category.'' - ); - } - - /** - * Delete every categories - * @return bool - */ - public function deleteCategories() - { - return Db::getInstance()->execute(' - DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE `id_shop` = '.(int)$this->id.' - '); - } - - /** - * Add some categories to a shop - * @param array $categories - * @return bool - */ - public function addToCategories($categories) - { - $sql = ' - INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES'; - foreach ($categories as $c) - $sql .= '("'.(int)$c.'", "'.(int)$this->id.'"),'; - // removing last comma to avoid SQL error - $sql = substr($sql, 0, strlen($sql) - 1); - - return Db::getInstance()->execute($sql); - } - - public static function isCategoryAvailable($id_category) - { - return (bool)Db::getInstance()->getValue(' - SELECT `id_category` - FROM `'._DB_PREFIX_.'category_shop` - WHERE `id_category` = '.(int)$id_category.' - AND `id_shop` = '.(int)Context::getContext()->shop->getID(true)); - } - - public static function isProductAvailable($id_product) - { - return (bool)Db::getInstance()->getValue(' - SELECT p.`id_product` - FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'category_product` cp - ON p.`id_product` = cp.`id_product` - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs - ON cp.`id_category` = cs.`id_category` - WHERE p.`id_product` = '.(int)$id_product.' - AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true)); - } } diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 837da85ab..ce7279d00 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -170,8 +170,7 @@ class AdminCategoriesControllerCore extends AdminController { $this->initToolbar(); $obj = $this->loadObject(true); - $id_shop = Context::getContext()->shop->getID(true); - $selected_cat = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? $obj->id_parent : Tools::getValue('id_parent', 1)); + $selected_cat = array(isset($obj->id_parent) ? $obj->id_parent : Tools::getValue('id_parent', 1)); $this->fields_form = array( 'tinymce' => true, diff --git a/controllers/admin/AdminShopController.php b/controllers/admin/AdminShopController.php index b87b825f4..00e96dafc 100755 --- a/controllers/admin/AdminShopController.php +++ b/controllers/admin/AdminShopController.php @@ -286,18 +286,6 @@ class AdminShopControllerCore extends AdminController 'category_tree' => $this->initCategoriesAssociation($this) ); - $categories = Category::getCategories($this->context->language->id, false, false); - $this->fields_form['input'][] = array( - 'type' => 'select', - 'label' => $this->l('Category root:'), - 'name' => 'id_category', - 'options' => array( - 'query' => $categories, - 'id' => 'id_category', - 'name' => 'name' - ) - ); - $this->fields_form['input'][] = array( 'type' => 'radio', 'label' => $this->l('Status:'), diff --git a/controllers/front/CategoryController.php b/controllers/front/CategoryController.php index 4f069e080..c88f79e61 100644 --- a/controllers/front/CategoryController.php +++ b/controllers/front/CategoryController.php @@ -49,11 +49,6 @@ class CategoryControllerCore extends FrontController public function canonicalRedirection($canonicalURL = '') { - if (!Shop::isCategoryAvailable(Tools::getValue('id_category'))) - { - $this->redirect_after = '404'; - $this->redirect(); - } if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category)) parent::canonicalRedirection($this->context->link->getCategoryLink($this->category)); } diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql index ca6d5190b..9cbcbd439 100644 --- a/install-dev/sql/db.sql +++ b/install-dev/sql/db.sql @@ -2333,11 +2333,4 @@ CREATE TABLE `PREFIX_specific_price_rule_condition` ( `value` VARCHAR(255) NOT NULL, PRIMARY KEY (`id_specific_price_rule_condition`), INDEX (`id_specific_price_rule_condition_group`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; - -CREATE TABLE `PREFIX_category_shop` ( - `id_category` int(11) NOT NULL, - `id_shop` int(11) NOT NULL, - PRIMARY KEY (`id_category`, `id_shop`), - UNIQUE KEY `id_category_shop` (`id_category`,`id_shop`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/install-dev/sql/db_settings_extends.sql b/install-dev/sql/db_settings_extends.sql index 7025a760a..12c7e44f3 100644 --- a/install-dev/sql/db_settings_extends.sql +++ b/install-dev/sql/db_settings_extends.sql @@ -1725,10 +1725,6 @@ INSERT INTO `PREFIX_homeslider_slides_lang` (id_slide, id_lang, title, descripti (4, 5, "PHP.net", "PrestaShop use PHP, the well-known open-source technology", "php", "http://www.php.net", "sample-4.jpg"), (5, 5, "Smarty.net", "PrestaShop use the template engine Smarty (V3)", "Smarty", "http://www.smarty.net", "sample-5.jpg"); -INSERT INTO `PREFIX_category_shop` (`id_category`, `id_shop`) VALUES -(2, 1), -(3, 1), -(4, 1); CREATE TABLE IF NOT EXISTS `PREFIX_linksmenutop` ( `id_link` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index 2b974b330..2dca0a3eb 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -1606,5 +1606,3 @@ INSERT INTO `PREFIX_supply_order_state_lang` (`id_supply_order_state`, `id_lang` (6, 3, 'order fenced'), (6, 4, 'order fenced'), (6, 5, 'order fenced'); - -INSERT INTO `PREFIX_category_shop` (`id_category`, `id_shop`) VALUES (1, 1); diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index fc89441ea..7b7a57488 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -172,27 +172,23 @@ class BlockCategories extends Module {*/ $maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH'); /*p(' - SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite - FROM `'._DB_PREFIX_.'category` c - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.$this->context->shop->addSqlRestrictionOnLang('cl').') - LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category` - WHERE (c.`active` = 1 OR c.`id_category` = 1) - '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' - AND cg.`id_group` IN ('.pSQL($groups).') - AND cs.`id_shop` = '.(int)$id_current_shop.' - GROUP BY id_category - ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'));*/ + SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite + FROM `'._DB_PREFIX_.'category` c + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.$this->context->shop->addSqlRestrictionOnLang('cl').') + LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) + WHERE (c.`active` = 1 OR c.`id_category` = 1) + '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' + AND cg.`id_group` IN ('.pSQL($groups).') + GROUP BY id_category + ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'));*/ if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite FROM `'._DB_PREFIX_.'category` c LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.$this->context->shop->addSqlRestrictionOnLang('cl').') LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) - LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category` WHERE (c.`active` = 1 OR c.`id_category` = 1) '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' AND cg.`id_group` IN ('.pSQL($groups).') - AND cs.`id_shop` = '.(int)$id_current_shop.' GROUP BY id_category ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')) )