提交 b584613e 编写于 作者: R root

category left fileter sub category

上级 d030e8d4
......@@ -53,10 +53,54 @@ class Index {
'query_item' => $this->getQueryItem(),
'product_page' => $this->getProductPage(),
'filter_price' => $this->getFilterPrice(),
'filter_category'=> $this->getFilterCategoryHtml(),
//'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'),
//'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(){
$spaceShowNum = 4;
......
......@@ -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;}
a{color: #666;text-decoration: 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_inner {height: 100%;width:1200px;}
......@@ -185,7 +185,7 @@ a:active, a:link {
position: relative;
}
.main.container{width: 1200px;margin:auto;min-height:500px;}
.main.container{width: 1200px;margin:auto;min-height:400px;}
.t_hidden {
font: 0px/0 Verdana;
......@@ -194,7 +194,7 @@ a:active, a:link {
.topSeachForm .seachBtn {
cursor: pointer;
}
.col-main .site-error h1{font-size:22px;margin-bottom:20px;}
#nav {
margin: 0 auto;
......@@ -650,8 +650,19 @@ input.input-text {
.breadcrumbs span{font-size:0.85em;}
.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,20 +21,22 @@
<?= $description ?>
</div>
<div class="panelBar">
<?php
$parentThis = [
'query_item' => $query_item,
'product_page'=>$product_page,
];
$config = [
'view' => 'catalog/category/index/toolbar.php',
];
$toolbar = Yii::$service->page->widget->renderContent('category_toolbar',$config,$parentThis);
echo $toolbar;
?>
<?php if(is_array($products) && !empty($products)){ ?>
<?php
$parentThis = [
'query_item' => $query_item,
'product_page'=>$product_page,
];
$config = [
'view' => 'catalog/category/index/toolbar.php',
];
$toolbar = Yii::$service->page->widget->renderContent('category_toolbar',$config,$parentThis);
echo $toolbar;
?>
<?php } ?>
</div>
<div class="category_product">
<?php if(is_array($products)){ ?>
<?php if(is_array($products) && !empty($products)){ ?>
<?php $i = 0; foreach($products as $product){ ?>
<?php if($i%$count == 0){ ?>
<ul>
......@@ -72,12 +74,22 @@
</div>
<div class="clear"></div>
<div class="panelBar">
<?php echo $toolbar; ?>
<?php if(is_array($products) && !empty($products)){ ?>
<?php echo $toolbar; ?>
<?php } ?>
</div>
</div>
</div>
<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
$parentThis = [
'filters' => $filter_info,
......@@ -88,7 +100,6 @@
echo Yii::$service->page->widget->renderContent('category_product_filter_attr',$config,$parentThis);
?>
<?php
$parentThis = [
'filter_price' => $filter_price,
];
......
......@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/
*/
?>
<div class="category_left_filter">
<?php
//var_dump($parentThis);
//echo 1;
......@@ -15,16 +16,21 @@ if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($
foreach($parentThis['filters'] as $attr => $filter){
$attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr);
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){
$val = $item['_id'];
$count = $item['count'];
$urlInfo = Yii::$service->url->category->getFilterChooseAttrUrl($attrUrlStr,$val,'p');
$url = $urlInfo['url'];
$selected = $urlInfo['selected'];
echo '<a href="'.$url.'">'.$val.'('.$count.')</a><br/>';
$selected = $urlInfo['selected'] ? 'class="checked"' : '';
echo '<a '.$selected.' href="'.$url.'">'.$val.'('.$count.')</a><br/>';
}
echo '</div>';
echo '</div>';
}
}
}
?>
\ No newline at end of file
?>
</div>
\ No newline at end of file
......@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/
*/
?>
<div class="category_left_filter">
<?php
//var_dump($parentThis['filter_price']);
//echo 1;
......@@ -14,17 +15,23 @@
if(isset($parentThis['filter_price']) && !empty($parentThis['filter_price']) && is_array($parentThis['filter_price'])){
foreach($parentThis['filter_price'] as $attr => $filter){
//var_dump($filter);
echo $attr.'<br/>';
$attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr);
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){
$val = $item['val'];
$url = $item['url'];
$selected = $item['selected'] ? 'class="checked"' : '';
echo '<a '.$selected.' href="'.$url.'">'.$val.'</a><br/>';
if($val && $url){
echo '<a '.$selected.' href="'.$url.'">'.$val.'</a><br/>';
}
}
echo '</div>';
echo '</div>';
}
}
}
?>
\ No newline at end of file
?>
</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 @@
* @license http://www.fecshop.com/license/
*/
?>
<h1><?= $title ?></h1>
<div>
<?= $content ?>
<div class="main container one-column">
<div class="col-main">
<h1><?= $title ?></h1>
<div>
<?= $content ?>
</div>
</div>
</div>
\ No newline at end of file
......@@ -9,19 +9,22 @@ use yii\helpers\Html;
$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>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>
</div>
</div>
\ No newline at end of file
......@@ -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
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.
先完成此消息的编辑!
想要评论请 注册