Skip to content

Commit

Permalink
category services
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Jul 22, 2020
1 parent 92d8ff3 commit 05be1d6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
12 changes: 12 additions & 0 deletions config/services/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
return [
'category' => [
'class' => 'fecshop\services\Category',
'customCategoryFilterAttr' => [
/*
'brand_id' => [
'label' => 'Brand',
'items' => [
1 => '华为',
3 => '小米',
4 => '大华',
],
],
*/
],
// 子服务
'childService' => [
'product' => [
Expand Down
39 changes: 24 additions & 15 deletions services/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ class Category extends Service
* 如果设置了路径,则使用自定义的路径
*/
public $storagePath = '';


/**
* 自定义分类过滤属性信息,数据例子如下,您可以在配置中注入
* [
'brand_id' => [
'label' => 'Brand',
'items' => [
1 => '华为',
3 => '小米',
4 => '大华',
],
],
]
*/
public $customCategoryFilterAttr;

/**
* @var \fecshop\services\category\CategoryInterface
*/
Expand Down Expand Up @@ -256,28 +271,22 @@ public function getFilterAttr($categoryM)
return $this->_filter_attr;
}


protected $_customCategoryFilterAttrInfo;
/**
* 分类页面-属性过滤-自定义属性以及属性值。
*
*
*/
public function customCategoryFilterAttrInfo()
{
if (!$this->_customCategoryFilterAttrInfo) {
$this->_customCategoryFilterAttrInfo = [
'brand_id' => [
'label' => 'Brand',
'items' => Yii::$service->product->brand->getAllBrandIdAndNames(),
/*
[
1 => '华为',
3 => '小米',
4 => '大华',
],
*/
],
$customCategoryFilterAttr = $this->customCategoryFilterAttr;
// 加入品牌
$customCategoryFilterAttr['brand_id'] = [
'label' => 'Brand',
'items' => Yii::$service->product->brand->getAllBrandIdAndNames(),
];

$this->_customCategoryFilterAttrInfo = $customCategoryFilterAttr;
}

return $this->_customCategoryFilterAttrInfo;
Expand Down

0 comments on commit 05be1d6

Please sign in to comment.