Merge branch 'ticket/r13161-Fusion-Levest-Roykin' into dev

This commit is contained in:
Rodney Figaro 2017-05-10 14:18:27 +02:00
commit 2d3c944003
17 changed files with 102 additions and 64 deletions

View File

@ -8,6 +8,61 @@ class Category extends CategoryCore
const CATEGORY_SAVEUR = 12;
const CATEGORY_SAVEUR_ALL = 27;
const CATEGORY_LEVEL_BRANDS = 2;
const CATEGORY_BRAND_ROYKIN = 53;
private static $default_sub_category_ids = array();
public static function getDefault($context = null)
{
return self::CATEGORY_BRAND_ROYKIN;
}
public static function getDefaultSubCategory($id_category, $on_notfound_use_firstsubcategory = false, $context = null)
{
if (empty(self::$default_sub_category_ids)) {
self::$default_sub_category_ids = array(
self::CATEGORY_HOME => self::CATEGORY_BRAND_ROYKIN,
self::CATEGORY_BRAND_ROYKIN => self::CATEGORY_COLLECTION,
//self::CATEGORY_COLLECTION => self::CATEGORY_COLLECTION_ALL,
//self::CATEGORY_SAVEUR => self::CATEGORY_SAVEUR_ALL,
);
}
if (isset(self::$default_sub_category_ids[$id_category])) {
return self::$default_sub_category_ids[$id_category];
}
if ($on_notfound_use_firstsubcategory) {
return self::getFirstSubCategory($id_category, $context);
}
return -1;
}
public static function getFirstSubCategory($id_category, $context = null)
{
if(!$context) {
$context = Context::getContext();
}
$id_sub_category = Db::getInstance()->getValue(
'SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON cs.`id_category` = c.`id_category`
WHERE c.`id_parent` = '.(int)$id_category.'
AND c.`active` = 1
AND cs.`id_shop` = '.(int)$context->shop->id.'
ORDER BY cs.`position` ASC'
);
if (empty($id_sub_category)) {
$id_sub_category = -1;
}
return $id_sub_category;
}
public static function getCategoriesTree($id_parent, $currentDepth = 0, $depth = 3, $context = null)
{
if(!$context)
@ -17,7 +72,7 @@ class Category extends CategoryCore
if($currentDepth >= $depth)
{
return false;
return array();
}
$query = '
@ -37,7 +92,7 @@ class Category extends CategoryCore
if(!$categories)
{
return false;
return array();
}
foreach($categories as $key => $category)

View File

@ -60,7 +60,7 @@ class AddressController extends AddressControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -7,7 +7,7 @@ class AddressesController extends AddressesControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -375,7 +375,7 @@ class AuthController extends AuthControllerCore
CartRule::autoAddToCart($this->context);
if (!$this->ajax) {
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -2,7 +2,6 @@
class CategoryController extends CategoryControllerCore
{
public function initContent()
{
if(Tools::getIsset('emptyCart'))
@ -15,13 +14,11 @@ class CategoryController extends CategoryControllerCore
Tools::redirect($this->context->link->getCategoryLink($this->category->id));
}
if($this->category->id == Category::CATEGORY_COLLECTION)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
}
elseif ($this->category->id == Category::CATEGORY_SAVEUR)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_SAVEUR_ALL));
if ($this->category->level_depth == Category::CATEGORY_LEVEL_BRANDS) {
$id_sub_category = Category::getDefaultSubCategory($this->category->id);
if ($id_sub_category != -1) {
Tools::redirect($this->context->link->getCategoryLink($id_sub_category));
}
}
$this->category->hasBanner = file_exists(_PS_CAT_IMG_DIR_ . 'banners/' . $this->category->id_category . '.jpg');
@ -30,42 +27,34 @@ class CategoryController extends CategoryControllerCore
protected function assignSubcategories()
{
$parent = new Category($this->category->id_parent);
$id_selected = array();
$families = Category::getCategoriesTree(Category::CATEGORY_HOME, 0, 3);
// Si on est sur une catégorie enfant direct des familles
if(in_array($this->category->id_parent, array(Category::CATEGORY_COLLECTION, Category::CATEGORY_SAVEUR))) {
$categoriesTree = Category::getCategoriesTree($this->category->id_parent, 0, 2);
$children = Category::getCategoriesTree($this->category->id_category, 0, 1);
foreach($families as $key => $category)
{
$families[$key]['active'] = $category['id_category'] == $this->category->id_parent;
}
// case : the current category is a brand (nothing above in the menu)
if ($this->category->level_depth == Category::CATEGORY_LEVEL_BRANDS) {
$id_selected['level_1'] = $this->category->id_category;
$id_selected['level_2'] = Category::getDefaultSubCategory($this->category->id_category, true);
}
// case : the current category is a brand subcategory
else {
$id_selected['level_1'] = $parent->id_category;
$id_selected['level_2'] = $this->category->id_category;
}
// Sinon si on est sur un sous-enfant (tabacs, menthe, autres...). On remonte d'un niveau avant de générer l'arbo
else
{
$categoryParent = new Category($this->category->id_parent);
$categoriesTree = Category::getCategoriesTree($categoryParent->id_parent, 0, 2);
$children = Category::getCategoriesTree($categoryParent->id_category, 0, 1);
$brands = Category::getCategoriesTree(Category::CATEGORY_HOME, 0, 3);
$subcategories = Category::getCategoriesTree($id_selected['level_1'], 0, 2);
foreach($families as $key => $category)
{
$families[$key]['active'] = $category['id_category'] == $categoryParent->id_parent;
}
// brand selected
foreach($brands as $index => $c) {
$brands[$index]['active'] = ($c['id_category'] == $id_selected['level_1']);
}
foreach($categoriesTree as $key => $category)
{
$categoriesTree[$key]['active'] = $category['id_category'] == $this->category->id_parent;
// brand subcategory selected
foreach($subcategories as $index => $c) {
$subcategories[$index]['active'] = ($c['id_category'] == $id_selected['level_2']);
}
$this->context->smarty->assign(array(
'families' => $families,
'children' => $children,
'categoriesTree' => $categoriesTree
));
$this->context->smarty->assign('families', $brands);
$this->context->smarty->assign('categoriesTree', $subcategories);
}
}

View File

@ -8,7 +8,7 @@ class ContactController extends ContactControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}

View File

@ -7,7 +7,7 @@ class DiscountController extends DiscountControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -1,3 +1,4 @@
<?php
class IdentityController extends IdentityControllerCore
@ -7,7 +8,7 @@ class IdentityController extends IdentityControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -8,7 +8,7 @@ class IndexController extends IndexControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}

View File

@ -7,7 +7,7 @@ class MyAccountController extends MyAccountControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -7,7 +7,7 @@ class OrderFollowController extends OrderFollowControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -7,7 +7,7 @@ class OrderSlipController extends OrderSlipControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -8,7 +8,7 @@ class SearchController extends SearchControllerCore
parent::initContent();
$families = Category::getCategoriesTree(Category::CATEGORY_HOME, 0, 1);
$categoriesTree = Category::getCategoriesTree(Category::CATEGORY_COLLECTION, 0, 1);
$categoriesTree = Category::getCategoriesTree(Category::getDefaultSubCategory(Category::CATEGORY_HOME), 0, 1);
$this->context->smarty->assign(array(
'families' => $families,

View File

@ -7,7 +7,7 @@ class SitemapController extends SitemapControllerCore
parent::initContent();
if($this->context->customer->logged)
{
Tools::redirect($this->context->link->getCategoryLink(Category::CATEGORY_COLLECTION_ALL));
Tools::redirect($this->context->link->getCategoryLink(Category::getDefault()));
}
}
}

View File

@ -27,15 +27,6 @@
{hook h="displaySearch"}
</li>
</ul>
{if $children}
<ul id="subchildren-categories">
{foreach from=$children item=child}
<li{if $child.id_category == $category->id} class="active"{/if}>
<a href="{$child.link}">{$child.name}</a>
</li>
{/foreach}
</ul>
{/if}
</nav>

View File

@ -243,7 +243,7 @@ body#index main, body#password main { background: #000 }
color: #202020;
}
#category .messages {
#category .messages, #search .messages {
background: #bfa56d;
/*background: -webkit-linear-gradient(top, #dec77f, #d0b878);
background: -o-linear-gradient(top, #dec77f, #d0b878);
@ -254,7 +254,7 @@ body#index main, body#password main { background: #000 }
position: relative;
z-index: 5;
}
#category .message {
#category .message, #search .message {
@ -278,7 +278,7 @@ body#index main, body#password main { background: #000 }
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
}
#category .message.open { opacity: 1; }
#category .message.open, #search .message.open { opacity: 1; }
#search .products-list,
.products-list {
margin-bottom: 205px;

View File

@ -43,7 +43,9 @@
</ul>
</nav>
{hook h="displayAlert"}
<div class="messages">
{hook h="displayAlert"}
</div>
<div class="ctn">
{if $products}