// Fix display of breadcrumb (dont show categories disabled) + it's now impossible to browse categories outside of root category for shops

This commit is contained in:
rMalie
2011-08-17 12:32:04 +00:00
parent 3d733ae6e2
commit fc2e036fc2
8 changed files with 67 additions and 63 deletions
-1
View File
@@ -1399,7 +1399,6 @@ class AdminProducts extends AdminTab
public function display($token = NULL) public function display($token = NULL)
{ {
if ($id_category = (int)Tools::getValue('id_category')) if ($id_category = (int)Tools::getValue('id_category'))
AdminTab::$currentIndex .= '&id_category='.$id_category; AdminTab::$currentIndex .= '&id_category='.$id_category;
$this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $this->context->shop->getID(true)); $this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $this->context->shop->getID(true));
+1 -1
View File
@@ -211,7 +211,7 @@ class CMSCategoryCore extends ObjectModel
$category['cms'] = Db::getInstance()->ExecuteS($sql); $category['cms'] = Db::getInstance()->ExecuteS($sql);
if ($links == 1) if ($links == 1)
{ {
$category['link'] = $context->link->getCMSCategoryLink($current, $category['link_rewrite']); $category['link'] = $link->getCMSCategoryLink($current, $category['link_rewrite']);
foreach($category['cms'] as $key => $cms) foreach($category['cms'] as $key => $cms)
$category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); $category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']);
} }
+20 -2
View File
@@ -596,7 +596,7 @@ class CategoryCore extends ObjectModel
if (!$shop) if (!$shop)
$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
return new Category($context->shop->getCategory(), $id_lang); return new Category($shop->getCategory(), $id_lang);
} }
/** /**
@@ -986,13 +986,31 @@ class CategoryCore extends ObjectModel
*/ */
public static function getInterval($id) public static function getInterval($id)
{ {
$sql = 'SELECT nleft, nright FROM '._DB_PREFIX_.'category $sql = 'SELECT nleft, nright, level_depth
FROM '._DB_PREFIX_.'category
WHERE id_category = '.(int)$id; WHERE id_category = '.(int)$id;
if (!$result = Db::getInstance()->getRow($sql)) if (!$result = Db::getInstance()->getRow($sql))
return false; return false;
return $result; return $result;
} }
/**
* Check if current category is a child of shop root category
*
* @since 1.5.0
* @param Shop $shop
* @return bool
*/
public function inShop(Shop $shop = null)
{
if (!$shop)
$shop = Context::getContext()->shop;
if (!$interval = Category::getInterval($shop->getCategory()))
return false;
return ($this->nleft >= $interval['nleft'] && $this->nright <= $interval['nright']);
}
public function getChildrenWs() public function getChildrenWs()
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
+26 -20
View File
@@ -820,6 +820,7 @@ class ToolsCore
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$id_category = (int)$id_category;
if ($id_category == 1) if ($id_category == 1)
return '<span class="navigation_end">'.$path.'</span>'; return '<span class="navigation_end">'.$path.'</span>';
@@ -828,23 +829,23 @@ class ToolsCore
$pipe = '>'; $pipe = '>';
$fullPath = ''; $fullPath = '';
if ($categoryType === 'products') if ($categoryType === 'products')
{ {
$category = Db::getInstance()->getRow(' $interval = Category::getInterval($id_category);
SELECT id_category, level_depth, nleft, nright $intervalRoot = Category::getInterval($context->shop->getCategory());
FROM '._DB_PREFIX_.'category if ($interval)
WHERE id_category = '.(int)$id_category);
if (isset($category['id_category']))
{ {
$categories = Db::getInstance()->ExecuteS(' $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
SELECT c.id_category, cl.name, cl.link_rewrite FROM '._DB_PREFIX_.'category c
FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.$context->shop->sqlLang('cl').')
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category) WHERE c.nleft <= '.$interval['nleft'].'
WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)$context->language->id.' AND c.id_category != 1 AND c.nright >= '.$interval['nright'].'
ORDER BY c.level_depth ASC AND c.nleft >= '.$intervalRoot['nleft'].'
LIMIT '.(int)$category['level_depth']); AND c.nright <= '.$intervalRoot['nright'].'
AND cl.id_lang = '.(int)$context->language->id.'
AND c.active = 1
ORDER BY c.level_depth ASC';
$categories = Db::getInstance()->ExecuteS($sql);
$n = 1; $n = 1;
$nCategories = (int)sizeof($categories); $nCategories = (int)sizeof($categories);
@@ -860,7 +861,7 @@ class ToolsCore
return $fullPath.$path; return $fullPath.$path;
} }
} }
elseif ($categoryType === 'CMS') else if ($categoryType === 'CMS')
{ {
$category = new CMSCategory($id_category, $context->language->id); $category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category)) if (!Validate::isLoadedObject($category))
@@ -872,7 +873,7 @@ class ToolsCore
else else
$fullPath = ($linkOntheLastItem ? '<a href="'.self::safeOutput($categoryLink).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($linkOntheLastItem ? '</a>' : ''); $fullPath = ($linkOntheLastItem ? '<a href="'.self::safeOutput($categoryLink).'">' : '').htmlentities($path, ENT_NOQUOTES, 'UTF-8').($linkOntheLastItem ? '</a>' : '');
return self::getPath((int)($category->id_parent), $fullPath, $linkOntheLastItem, $categoryType); return self::getPath($category->id_parent, $fullPath, $linkOntheLastItem, $categoryType);
} }
} }
@@ -884,16 +885,21 @@ class ToolsCore
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$id_category = (int)$id_category;
$pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'); $pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
if($type_cat === 'products') $defaultCategory = 1;
$category = new Category($id_category, $context->language->id); if ($type_cat === 'products')
{
$defaultCategory = $context->shop->getCategory();
$category = new Category($id_category, $context->language->id);
}
else if ($type_cat === 'CMS') else if ($type_cat === 'CMS')
$category = new CMSCategory($id_category, $context->language->id); $category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category)) if (!Validate::isLoadedObject($category))
$id_category = 1; $id_category = $defaultCategory;
if ($id_category == 1) if ($id_category == $defaultCategory)
return htmlentities($end, ENT_NOQUOTES, 'UTF-8'); return htmlentities($end, ENT_NOQUOTES, 'UTF-8');
return self::getPath($id_category, $category->name, true, $type_cat).'<span class="navigation-pipe">'.$pipe.'</span> <span class="navigation_product">'.htmlentities($end, ENT_NOQUOTES, 'UTF-8').'</span>'; return self::getPath($id_category, $category->name, true, $type_cat).'<span class="navigation-pipe">'.$pipe.'</span> <span class="navigation_product">'.htmlentities($end, ENT_NOQUOTES, 'UTF-8').'</span>';
+2 -2
View File
@@ -99,7 +99,7 @@ class CmsControllerCore extends FrontController
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'cms' => $this->cms, 'cms' => $this->cms,
'content_only' => (int)(Tools::getValue('content_only')), 'content_only' => (int)(Tools::getValue('content_only')),
'path' => ((isset($this->cms->id_cms_category) AND $this->cms->id_cms_category) ? Tools::getFullPath((int)($this->cms->id_cms_category), $this->cms->meta_title, 'CMS') : Tools::getFullPath(1, $this->cms->meta_title, 'CMS')) 'path' => ((isset($this->cms->id_cms_category) AND $this->cms->id_cms_category) ? Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS') : Tools::getFullPath(1, $this->cms->meta_title, 'CMS'))
)); ));
} }
elseif ($this->assignCase == 2) elseif ($this->assignCase == 2)
@@ -108,7 +108,7 @@ class CmsControllerCore extends FrontController
'category' => $this->cms_category, 'category' => $this->cms_category,
'sub_category' => $this->cms_category->getSubCategories($this->context->language->id), 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ), 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ),
'path' => ($this->cms_category->id !== 1) ? Tools::getPath((int)($this->cms_category->id), $this->cms_category->name, false, 'CMS') : '', 'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
)); ));
} }
} }
+3 -3
View File
@@ -92,7 +92,7 @@ class CategoryControllerCore extends FrontController
$this->errors[] = Tools::displayError('Missing category ID'); $this->errors[] = Tools::displayError('Missing category ID');
else else
{ {
if (!Validate::isLoadedObject($this->category)) if (!Validate::isLoadedObject($this->category) || !$this->category->inShop())
$this->errors[] = Tools::displayError('Category does not exist'); $this->errors[] = Tools::displayError('Category does not exist');
elseif (!$this->category->checkAccess($this->context->customer->id)) elseif (!$this->category->checkAccess($this->context->customer->id))
$this->errors[] = Tools::displayError('You do not have access to this category.'); $this->errors[] = Tools::displayError('You do not have access to this category.');
@@ -103,7 +103,7 @@ class CategoryControllerCore extends FrontController
$rewrited_url = $this->context->link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite); $rewrited_url = $this->context->link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite);
/* Scenes (could be externalised to another controler if you need them */ /* Scenes (could be externalised to another controler if you need them */
$this->context->smarty->assign('scenes', Scene::getScenes((int)($this->category->id), $this->context->language->id, true, false)); $this->context->smarty->assign('scenes', Scene::getScenes($this->category->id, $this->context->language->id, true, false));
/* Scenes images formats */ /* Scenes images formats */
if ($sceneImageTypes = ImageType::getImagesTypes('scenes')) if ($sceneImageTypes = ImageType::getImagesTypes('scenes'))
@@ -142,7 +142,7 @@ class CategoryControllerCore extends FrontController
'id_category' => (int)($this->category->id), 'id_category' => (int)($this->category->id),
'id_category_parent' => (int)($this->category->id_parent), 'id_category_parent' => (int)($this->category->id_parent),
'return_category_name' => Tools::safeOutput($this->category->name), 'return_category_name' => Tools::safeOutput($this->category->name),
'path' => Tools::getPath((int)($this->category->id)), 'path' => Tools::getPath($this->category->id),
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'categorySize' => Image::getSize('category'), 'categorySize' => Image::getSize('category'),
'mediumSize' => Image::getSize('medium'), 'mediumSize' => Image::getSize('medium'),
+1 -1
View File
@@ -167,7 +167,7 @@ class ProductControllerCore extends FrontController
if (isset($category) AND Validate::isLoadedObject($category)) if (isset($category) AND Validate::isLoadedObject($category))
{ {
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'path' => Tools::getPath((int)$category->id, $this->product->name, true), 'path' => Tools::getPath($category->id, $this->product->name, true),
'category' => $category, 'category' => $category,
'subCategories' => $category->getSubCategories($this->context->language->id, true), 'subCategories' => $category->getSubCategories($this->context->language->id, true),
'id_category_current' => (int)($category->id), 'id_category_current' => (int)($category->id),
+12 -31
View File
@@ -122,8 +122,11 @@ class BlockCategories extends Module
</form>'; </form>';
} }
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0)
{ {
if (is_null($id_category))
$id_category = $this->context->shop->getCategory();
$children = array(); $children = array();
if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth))
foreach ($resultParents[$id_category] as $subcat) foreach ($resultParents[$id_category] as $subcat)
@@ -156,7 +159,7 @@ class BlockCategories extends Module
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.$id_lang.' AND cl.`id_shop`='.(int)$id_current_shop.') LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.$this->context->shop->sqlLang('cl').')
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1) WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
@@ -177,13 +180,8 @@ class BlockCategories extends Module
} }
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents); unset($resultParents, $resultIds);
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
$shopcurrentroot = $this->context->shop->getCategory();
if ($blockCategTree['id'] != $shopcurrentroot)
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category')) if (Tools::isSubmit('id_category'))
{ {
@@ -216,7 +214,6 @@ class BlockCategories extends Module
public function hookFooter($params) public function hookFooter($params)
{ {
$this->context = $this->context;
$id_current_shop = $this->context->shop->getID(); $id_current_shop = $this->context->shop->getID();
$id_customer = (int)($params['cookie']->id_customer); $id_customer = (int)($params['cookie']->id_customer);
@@ -225,7 +222,8 @@ class BlockCategories extends Module
$id_product = (int)(Tools::getValue('id_product', 0)); $id_product = (int)(Tools::getValue('id_product', 0));
$id_category = (int)(Tools::getValue('id_category', 0)); $id_category = (int)(Tools::getValue('id_category', 0));
$id_lang = (int)($params['cookie']->id_lang); $id_lang = (int)($params['cookie']->id_lang);
$smartyCacheId = 'blockcategories|'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category; $smartyCacheId = 'blockcategories|'.$id_current_shop.'_'.$groups.'_'.$id_lang.'_'.$id_product.'_'.$id_category;
Tools::enableCache(); Tools::enableCache();
if (!$this->isCached('blockcategories_footer.tpl', $smartyCacheId)) if (!$this->isCached('blockcategories_footer.tpl', $smartyCacheId))
{ {
@@ -234,7 +232,7 @@ class BlockCategories extends Module
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c 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.' AND cl.`id_shop`='.(int)$id_current_shop.') LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.$id_lang.$this->context->shop->sqlLang('cl').')
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1) WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').' '.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
@@ -260,13 +258,8 @@ class BlockCategories extends Module
$this->context->smarty->assign('widthColumn', $widthColumn); $this->context->smarty->assign('widthColumn', $widthColumn);
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH')); $blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents); unset($resultParents, $resultIds);
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
if($blockCategTree['id'] != $this->context->shop->getCategory())
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category')) if (Tools::isSubmit('id_category'))
@@ -298,18 +291,6 @@ class BlockCategories extends Module
return $display; return $display;
} }
public function cleanTree($categories)
{
$id_category_root = Context::getContext()->shop->getCategory();
foreach ($categories AS $row)
{
if ($row['id'] == $id_category_root)
return $row;
elseif (sizeof($row['children']))
$this->cleanTree($row['children']);
}
}
public function hookRightColumn($params) public function hookRightColumn($params)
{ {
return $this->hookLeftColumn($params); return $this->hookLeftColumn($params);