提交 b584613e 编写于 作者: R root

category left fileter sub category

上级 d030e8d4
...@@ -53,10 +53,54 @@ class Index { ...@@ -53,10 +53,54 @@ class Index {
'query_item' => $this->getQueryItem(), 'query_item' => $this->getQueryItem(),
'product_page' => $this->getProductPage(), 'product_page' => $this->getProductPage(),
'filter_price' => $this->getFilterPrice(), 'filter_price' => $this->getFilterPrice(),
'filter_category'=> $this->getFilterCategoryHtml(),
//'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'), //'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'),
//'created_at' => $this->_category['created_at'], //'created_at' => $this->_category['created_at'],
]; ];
} }
/**
* 得到子分类,如果子分类不存在,则返回同级分类。
*/
protected function getFilterCategory(){
$category_id = $this->_primaryVal;
$parent_id = $this->_category['parent_id'];
$filter_category = Yii::$service->category->getFilterCategory($category_id,$parent_id);
return $filter_category;
}
protected function getFilterCategoryHtml($filter_category=''){
$str = '';
if(!$filter_category){
$filter_category = $this->getFilterCategory();
}
//var_dump($filter_category);
//exit;
if(is_array($filter_category) && !empty($filter_category)){
$str .= '<ul>';
foreach($filter_category as $cate){
//var_dump($cate);
//echo '<br><br>';
//continue;
$name = Yii::$service->store->getStoreAttrVal($cate['name'],'name');
$url = Yii::$service->url->getUrl($cate['url_key']);
$current = '';
if(isset($cate['current']) && $cate['current']){
$current = 'class="current"';
}
$str .= '<li '.$current.'><a href="'.$url.'">'.$name.'</a>';
if(isset($cate['child']) && is_array($cate['child'] ) && !empty($cate['child'])){
$str .= $this->getFilterCategoryHtml($cate['child']);
}
$str .= '</li>';
}
$str .= '</ul>';
}
//exit;
return $str;
}
protected function getProductPage(){ protected function getProductPage(){
$spaceShowNum = 4; $spaceShowNum = 4;
......
...@@ -3,7 +3,7 @@ body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, ...@@ -3,7 +3,7 @@ body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset,
body {color: #333;font: 1em/1.55 Verdana,Arial,Helvetica,sans-serif;} body {color: #333;font: 1em/1.55 Verdana,Arial,Helvetica,sans-serif;}
a{color: #666;text-decoration: none;} a{color: #666;text-decoration: none;}
ol, ul {list-style: outside none none;} ol, ul {list-style: outside none none;}
ul li{height:32px;}
#top_nav {background-color: #000;font-size: 0.75em;height: 40px;line-height: 40px;width: 100%;} #top_nav {background-color: #000;font-size: 0.75em;height: 40px;line-height: 40px;width: 100%;}
.top_nav_inner {height: 100%;width:1200px;} .top_nav_inner {height: 100%;width:1200px;}
...@@ -185,7 +185,7 @@ a:active, a:link { ...@@ -185,7 +185,7 @@ a:active, a:link {
position: relative; position: relative;
} }
.main.container{width: 1200px;margin:auto;min-height:500px;} .main.container{width: 1200px;margin:auto;min-height:400px;}
.t_hidden { .t_hidden {
font: 0px/0 Verdana; font: 0px/0 Verdana;
...@@ -194,7 +194,7 @@ a:active, a:link { ...@@ -194,7 +194,7 @@ a:active, a:link {
.topSeachForm .seachBtn { .topSeachForm .seachBtn {
cursor: pointer; cursor: pointer;
} }
.col-main .site-error h1{font-size:22px;margin-bottom:20px;}
#nav { #nav {
margin: 0 auto; margin: 0 auto;
...@@ -650,8 +650,19 @@ input.input-text { ...@@ -650,8 +650,19 @@ input.input-text {
.breadcrumbs span{font-size:0.85em;} .breadcrumbs span{font-size:0.85em;}
.breadcrumbs {margin:0 0 10px 0} .breadcrumbs {margin:0 0 10px 0}
.filter_attr_info a{
background: rgba(0, 0, 0, 0) url("../images/checkbox.png") no-repeat scroll -69px 3px;
padding: 0 0 0 16px;
font-size:0.8em;
}
.filter_attr_info a.checked{
background-position: -50px -17px;
}
.filter_attr_title {
font-size:0.9em;
text-transform: uppercase;
}
.filter_attr{margin:0 0 20px 0}
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<?= $description ?> <?= $description ?>
</div> </div>
<div class="panelBar"> <div class="panelBar">
<?php if(is_array($products) && !empty($products)){ ?>
<?php <?php
$parentThis = [ $parentThis = [
'query_item' => $query_item, 'query_item' => $query_item,
...@@ -32,9 +33,10 @@ ...@@ -32,9 +33,10 @@
$toolbar = Yii::$service->page->widget->renderContent('category_toolbar',$config,$parentThis); $toolbar = Yii::$service->page->widget->renderContent('category_toolbar',$config,$parentThis);
echo $toolbar; echo $toolbar;
?> ?>
<?php } ?>
</div> </div>
<div class="category_product"> <div class="category_product">
<?php if(is_array($products)){ ?> <?php if(is_array($products) && !empty($products)){ ?>
<?php $i = 0; foreach($products as $product){ ?> <?php $i = 0; foreach($products as $product){ ?>
<?php if($i%$count == 0){ ?> <?php if($i%$count == 0){ ?>
<ul> <ul>
...@@ -72,12 +74,22 @@ ...@@ -72,12 +74,22 @@
</div> </div>
<div class="clear"></div> <div class="clear"></div>
<div class="panelBar"> <div class="panelBar">
<?php if(is_array($products) && !empty($products)){ ?>
<?php echo $toolbar; ?> <?php echo $toolbar; ?>
<?php } ?>
</div> </div>
</div> </div>
</div> </div>
<div class="col-left "> <div class="col-left ">
<?php
$parentThis = [
'filter_category' => $filter_category,
];
$config = [
'view' => 'catalog/category/index/filter/subcategory.php',
];
echo Yii::$service->page->widget->renderContent('category_product_filter_sub_category',$config,$parentThis);
?>
<?php <?php
$parentThis = [ $parentThis = [
'filters' => $filter_info, 'filters' => $filter_info,
...@@ -88,7 +100,6 @@ ...@@ -88,7 +100,6 @@
echo Yii::$service->page->widget->renderContent('category_product_filter_attr',$config,$parentThis); echo Yii::$service->page->widget->renderContent('category_product_filter_attr',$config,$parentThis);
?> ?>
<?php <?php
$parentThis = [ $parentThis = [
'filter_price' => $filter_price, 'filter_price' => $filter_price,
]; ];
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/ * @license http://www.fecshop.com/license/
*/ */
?> ?>
<div class="category_left_filter">
<?php <?php
//var_dump($parentThis); //var_dump($parentThis);
//echo 1; //echo 1;
...@@ -15,16 +16,21 @@ if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($ ...@@ -15,16 +16,21 @@ if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($
foreach($parentThis['filters'] as $attr => $filter){ foreach($parentThis['filters'] as $attr => $filter){
$attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr); $attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr);
if(is_array($filter) && !empty($filter)){ if(is_array($filter) && !empty($filter)){
echo $attr.'<br/>'; echo '<div class="filter_attr">';
echo '<div class="filter_attr_title">'.$attr.'</div>';
echo '<div class="filter_attr_info">';
foreach($filter as $item){ foreach($filter as $item){
$val = $item['_id']; $val = $item['_id'];
$count = $item['count']; $count = $item['count'];
$urlInfo = Yii::$service->url->category->getFilterChooseAttrUrl($attrUrlStr,$val,'p'); $urlInfo = Yii::$service->url->category->getFilterChooseAttrUrl($attrUrlStr,$val,'p');
$url = $urlInfo['url']; $url = $urlInfo['url'];
$selected = $urlInfo['selected']; $selected = $urlInfo['selected'] ? 'class="checked"' : '';
echo '<a href="'.$url.'">'.$val.'('.$count.')</a><br/>'; echo '<a '.$selected.' href="'.$url.'">'.$val.'('.$count.')</a><br/>';
} }
echo '</div>';
echo '</div>';
} }
} }
} }
?> ?>
</div>
\ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/ * @license http://www.fecshop.com/license/
*/ */
?> ?>
<div class="category_left_filter">
<?php <?php
//var_dump($parentThis['filter_price']); //var_dump($parentThis['filter_price']);
//echo 1; //echo 1;
...@@ -14,17 +15,23 @@ ...@@ -14,17 +15,23 @@
if(isset($parentThis['filter_price']) && !empty($parentThis['filter_price']) && is_array($parentThis['filter_price'])){ if(isset($parentThis['filter_price']) && !empty($parentThis['filter_price']) && is_array($parentThis['filter_price'])){
foreach($parentThis['filter_price'] as $attr => $filter){ foreach($parentThis['filter_price'] as $attr => $filter){
//var_dump($filter);
echo $attr.'<br/>';
$attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr); $attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr);
if(is_array($filter) && !empty($filter)){ if(is_array($filter) && !empty($filter)){
echo '<div class="filter_attr">';
echo '<div class="filter_attr_title">'.$attr.'</div>';
echo '<div class="filter_attr_info">';
foreach($filter as $item){ foreach($filter as $item){
$val = $item['val']; $val = $item['val'];
$url = $item['url']; $url = $item['url'];
$selected = $item['selected'] ? 'class="checked"' : ''; $selected = $item['selected'] ? 'class="checked"' : '';
if($val && $url){
echo '<a '.$selected.' href="'.$url.'">'.$val.'</a><br/>'; echo '<a '.$selected.' href="'.$url.'">'.$val.'</a><br/>';
} }
} }
echo '</div>';
echo '</div>';
}
} }
} }
?> ?>
</div>
\ No newline at end of file
<style>
.category_left_filter_category ul li {
}
.category_left_filter_category ul li.current > a{
color:#cc0000;
}
.category_left_filter_category ul{
margin-left:20px;
}
</style>
<div class="category_left_filter_category">
<?php echo $parentThis['filter_category']; ?>
<?php
//exit;
?>
</div>
<div class="clear"></div>
\ No newline at end of file
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
* @license http://www.fecshop.com/license/ * @license http://www.fecshop.com/license/
*/ */
?> ?>
<h1><?= $title ?></h1> <div class="main container one-column">
<div> <div class="col-main">
<?= $content ?> <h1><?= $title ?></h1>
<div>
<?= $content ?>
</div>
</div>
</div> </div>
\ No newline at end of file
...@@ -9,7 +9,9 @@ use yii\helpers\Html; ...@@ -9,7 +9,9 @@ use yii\helpers\Html;
$this->title = $name; $this->title = $name;
?> ?>
<div class="site-error"> <div class="main container one-column">
<div class="col-main">
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
...@@ -24,4 +26,5 @@ $this->title = $name; ...@@ -24,4 +26,5 @@ $this->title = $name;
Please contact us if you think this is a server error. Thank you. Please contact us if you think this is a server error. Thank you.
</p> </p>
</div>
</div> </div>
\ No newline at end of file
...@@ -98,7 +98,9 @@ class Category extends Service ...@@ -98,7 +98,9 @@ class Category extends Service
} }
protected function actionGetFilterCategory($category_id,$parent_id){
return $this->_category->getFilterCategory($category_id,$parent_id);
}
......
...@@ -195,6 +195,199 @@ class CategoryMongodb implements CategoryInterface ...@@ -195,6 +195,199 @@ class CategoryMongodb implements CategoryInterface
return $parent_category; return $parent_category;
} }
} }
/**
* 得到分类的侧栏过滤信息
*/
/*
[
['name' => 'xxx','url_key'=>'xxx'],
[
'name' => 'xxx',
'url_key'=>'xxx',
'child' => [
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
[
'name' => 'xxx',
'url_key'=>'xxx',
'current' => true,
'child' => [
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
]
],
]
],
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
]
*/
public function getParentCategory($parent_id){
if($parent_id === '0'){
return [];
}
$category = Category::find()->asArray()->where(['_id' => new \mongoId($parent_id)])->one();
if(isset($category['_id']) && !empty($category['_id']) ){
$currentUrlKey = $category['url_key'];
$currentName = $category['name'];
$currentId = $category['_id']->{'$id'};
$currentCategory[] = [
'_id' => $currentId,
'name' => $currentName,
'url_key' => $currentUrlKey,
'parent_id' => $category['parent_id'],
];
$parentCategory = $this->getParentCategory($category['parent_id']);
return array_merge($parentCategory,$currentCategory);
}else{
return [];
}
}
public function getFilterCategory($category_id,$parent_id){
# 1.如果level为一级,那么title部分为当前的分类,子分类位一级分类下的二级分类
# 2.如果level为二级,那么将所有的二级分类列出,当前的二级分类,列出来子分类
# 3.如果level为三级,那么将所有的二级分类列出。
# 当前二级分类的所有子分类列出,当前三级分类如果有子分类,则列出
//echo $category_id.'##';
//echo $parent_id;
$returnData = [];
$primaryKey = $this->getPrimaryKey();
$currentCategory = Category::findOne($category_id);
$currentUrlKey = $currentCategory['url_key'];
$currentName = $currentCategory['name'];
$currentId = $currentCategory['_id']->{'$id'};
//var_dump($currentCategory);exit;
$returnData['current'] = [
'_id' => $currentId,
'name' => $currentName,
'url_key' => $currentUrlKey,
'parent_id' => $currentCategory['parent_id'],
];
//echo $currentCategory['parent_id'];
//exit;
if($currentCategory['parent_id']){
$allParent = $this->getParentCategory($currentCategory['parent_id']);
$allParent[] = $returnData['current'];
$data = $this->getAllParentCate($allParent);
}else{
// 点击的是一级分类的时候
$data = $this->getOneLevelCateChild($returnData['current']);
}
//$data = $this->getChildCate($currentId);
//var_dump($data);exit;
return $data;
}
public function getOneLevelCateChild($category){
//'_id' => $currentId,
//'name' => $currentName,
//'url_key' => $currentUrlKey,
$data[0] = $category;
$_id = $category['_id'];
$name = $category['name'];
$url_key = $category['url_key'];
$cate = Category::find()->asArray()->where([
'parent_id' => $_id,
])->all();
if(is_array($cate) && !empty($cate)){
foreach($cate as $one){
$c_id = $one['_id']->{'$id'};
$data[0]['child'][$c_id] = [
'name' => $one['name'],
'url_key' => $one['url_key'],
'parent_id' => $one['parent_id'],
];
}
}
return $data;
}
public function getAllParentCate($allParent){
//var_dump($allParent);exit;
$d = $allParent;
$data = [];
if(is_array($allParent) && !empty($allParent)){
foreach($allParent as $k => $category){
unset($d[$k]);
$category_id = $category['_id'];
$parent_id = $category['parent_id'];
if($parent_id){
$cate = Category::find()->asArray()->where([
'parent_id' => $parent_id,
])->all();
//var_dump($cate);
//echo '$$$$$$$$$$';
if(is_array($cate) && !empty($cate)){
//echo '**********';
foreach($cate as $one){
$c_id = $one['_id']->{'$id'};
$data[$c_id] = [
'name' => $one['name'],
'url_key' => $one['url_key'],
'parent_id' => $one['parent_id'],
];
//echo $category_id;
//echo '&&&'.$c_id;
if(($c_id == $category_id) && !empty($d)){
$data[$c_id]['child'] = $this->getAllParentCate($d);
}
if(($c_id == $category_id) && empty($d)){
$child_cate = $this->getChildCate($c_id);
$data[$c_id]['current'] = true;
if(!empty($child_cate)){
$data[$c_id]['child'] = $child_cate;
}
}
}
}
break;
}
}
}
return $data;
}
public function getChildCate($category_id){
//echo $category_id;
$data = Category::find()->asArray()->where([
'parent_id' => $category_id,
])->all();
$arr = [];
if(is_array($data) && !empty($data)){
foreach($data as $one){
$currentUrlKey = $one['url_key'];
$currentName = $one['name'];
$currentId = $one['_id']->{'$id'};
$arr[$currentId] = [
//'_id' => $currentId,
'name' => $currentName,
'url_key' => $currentUrlKey,
'parent_id' => $one['parent_id'],
];
}
}
return $arr;
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册