From 05be1d6dc097a693261d564fa00fcb2deaa05f28 Mon Sep 17 00:00:00 2001 From: Terry <2358269014@qq.com> Date: Wed, 22 Jul 2020 13:10:45 +0800 Subject: [PATCH] category services --- config/services/Category.php | 12 +++++++++++ services/Category.php | 39 ++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/config/services/Category.php b/config/services/Category.php index b2932db9d..e27f7c78b 100644 --- a/config/services/Category.php +++ b/config/services/Category.php @@ -8,6 +8,18 @@ return [ 'category' => [ 'class' => 'fecshop\services\Category', + 'customCategoryFilterAttr' => [ + /* + 'brand_id' => [ + 'label' => 'Brand', + 'items' => [ + 1 => '华为', + 3 => '小米', + 4 => '大华', + ], + ], + */ + ], // 子服务 'childService' => [ 'product' => [ diff --git a/services/Category.php b/services/Category.php index d59712e22..0b61e400b 100644 --- a/services/Category.php +++ b/services/Category.php @@ -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 */ @@ -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;