Skip to content

Commit

Permalink
apphtml5 分类页面属性过滤,添加品牌过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Jul 21, 2020
1 parent ff296b2 commit 92d8ff3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 72 deletions.
60 changes: 9 additions & 51 deletions app/apphtml5/modules/Catalog/block/category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getLastData()
'products' => $products,
'query_item' => $query_item,
'refine_by_info' => $this->getRefineByInfo(),
'filter_info' => $this->getFilterInfo(),
'filter_info' => Yii::$service->category->getFilterInfo($this->_category, $this->_where),
'filter_price' => $this->getFilterPrice(),
'filter_category' => $this->getFilterCategoryHtml(),
'page_count' => $page_count,
Expand Down Expand Up @@ -260,20 +260,7 @@ protected function getQueryItem()
*/
protected function getFilterAttr()
{
if (!$this->_filter_attr) {
$appName = Yii::$service->helper->getAppName();
$filter_default = Yii::$app->store->get($appName.'_catalog','category_filter_attr');
$filter_default = explode(',',$filter_default);
$current_fileter_select = $this->_category['filter_product_attr_selected'];
$current_fileter_unselect = $this->_category['filter_product_attr_unselected'];
$current_fileter_select_arr = $this->getFilterArr($current_fileter_select);
$current_fileter_unselect_arr = $this->getFilterArr($current_fileter_unselect);
$filter_attrs = array_merge($filter_default, $current_fileter_select_arr);
$filter_attrs = array_diff($filter_attrs, $current_fileter_unselect_arr);
$this->_filter_attr = $filter_attrs;
}

return $this->_filter_attr;
return Yii::$service->category->getFilterAttr($this->_category);
}
/**
* 得到分类侧栏用于属性过滤的部分数据
Expand All @@ -291,11 +278,15 @@ protected function getRefineByInfo()
$attr = Yii::$service->url->category->urlStrConvertAttrVal($k);
//echo $attr;
if (in_array($attr, $filter_attrs)) {
$refine_attr_str = '';
if ($attr == 'price') {
$refine_attr_str = $this->getFormatFilterPrice($v);
//$refine_attr_str = Yii::$service->url->category->urlStrConvertAttrVal($v);
} else {
$refine_attr_str = Yii::$service->url->category->urlStrConvertAttrVal($v);
$refine_attr_str = Yii::$service->category->getCustomCategoryFilterAttrItemLabel($k, $v);
if (!$refine_attr_str) {
$refine_attr_str = Yii::$service->url->category->urlStrConvertAttrVal($v);
}
}
$removeUrlParamStr = $k.'='.$v;
$refine_attr_url = Yii::$service->url->removeUrlParamVal($currentUrl, $removeUrlParamStr);
Expand All @@ -317,21 +308,7 @@ protected function getRefineByInfo()

return $refineInfo;
}
/**
* 侧栏除价格外的其他属性过滤部分
*/
protected function getFilterInfo()
{
$filter_info = [];
$filter_attrs = $this->getFilterAttr();
foreach ($filter_attrs as $attr) {
if ($attr != 'price') {
$filter_info[$attr] = Yii::$service->product->getFrontCategoryFilter($attr, $this->_where);
}
}

return $filter_info;
}

/**
* 侧栏价格过滤部分
*/
Expand Down Expand Up @@ -371,26 +348,7 @@ protected function getFormatFilterPrice($price_item)

return $str;
}
/**
* @param $str | String
* 字符串转换成数组。
*/
protected function getFilterArr($str)
{
$arr = [];
if ($str) {
$str = str_replace('', ',', $str);
$str_arr = explode(',', $str);
foreach ($str_arr as $a) {
$a = trim($a);
if ($a) {
$arr[] = trim($a);
}
}
}

return $arr;
}

/**
* 用于搜索条件的排序部分
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,37 @@
<?php
if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($parentThis['filters'])):
foreach($parentThis['filters'] as $attr => $filter):
$attrUrlStr = Yii::$service->url->category->attrValConvertUrlStr($attr);
if(is_array($filter) && !empty($filter)):
$attrLabel = $filter['label'];
$attrName = $filter['name'];
if(is_array($filter['items']) && !empty($filter['items'])):
$i = 0;
foreach($filter as $item):
$val = $item['_id'];
$count = $item['count'];
if($val):
foreach($filter['items'] as $item):
//var_dump($item);exit;
$itemName = $item['_id'];
$itemLabel = $item['label'];
$itemCount = $item['count'];
$itemUrl = $item['url'];
$selected = $item['selected'];
if($itemName):
$i++;
if($i == 1):
?>
<div class="filter_attr">
<div class="filter_attr_title">
<?= Yii::$service->page->translate->__($attr); ?>
<?= Yii::$service->page->translate->__($attrLabel); ?>
</div>
<div class="filter_attr_info">
<?php
endif;
$urlInfo = Yii::$service->url->category->getFilterChooseAttrUrl($attrUrlStr,$val,'p');
$url = $urlInfo['url'];
$selected = $urlInfo['selected'] ? 'class="checked"' : '';
?>
<a external <?= $selected ?> href="<?= $url ?>"><?= Yii::$service->page->translate->__($val); ?>(<?= $count ?>)</a><br/>

<?php endif; ?>
<a external <?= $selected ? 'class="checked"' : '';?> href="<?= $itemUrl;?>">
<?= $itemLabel; ?>(<?= $itemCount; ?>)
</a><br/>
<?php endif; ?>
<?php endforeach; ?>
<?php if($i >= 1): ?>
</div>
</div>
<?php
endif;
endif;
endforeach;
endif;
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</div>

0 comments on commit 92d8ff3

Please sign in to comment.