Browse Source

zuo ce shai xuan

NoteStar 5 years ago
parent
commit
9ff457886e
1 changed files with 17 additions and 12 deletions
  1. 17 12
      vendor/fancyecommerce/fecshop/services/product/ProductMysqldb.php

+ 17 - 12
vendor/fancyecommerce/fecshop/services/product/ProductMysqldb.php

@@ -955,6 +955,8 @@ class ProductMysqldb extends Service implements ProductInterface
             $whereArr = [
             $whereArr = [
                 ['in', 'id', $productIds]
                 ['in', 'id', $productIds]
             ];
             ];
+            $appName = Yii::$service->helper->getAppName();
+            $category_query_priceRange = Yii::$app->store->get($appName.'_catalog','category_filter_attr');
             foreach ($where as $k=>$v) {
             foreach ($where as $k=>$v) {
                 if ($k == 'price' && is_array($v)) {  // 价格数据处理。
                 if ($k == 'price' && is_array($v)) {  // 价格数据处理。
                     foreach ($v as $k1=>$v1) {
                     foreach ($v as $k1=>$v1) {
@@ -965,7 +967,7 @@ class ProductMysqldb extends Service implements ProductInterface
                         if ($k1 == '$lt') $fh = '<' ;
                         if ($k1 == '$lt') $fh = '<' ;
                         $whereArr[] = [$fh, 'price', $v1];
                         $whereArr[] = [$fh, 'price', $v1];
                     }
                     }
-                }elseif( $k == 'color' ){
+                }elseif( strpos($category_query_priceRange,$k) !== FALSE   ){
                     $whereArr[] = ['like','attr_group_info',$v];
                     $whereArr[] = ['like','attr_group_info',$v];
                 } else {
                 } else {
                     $whereArr[] = [$k =>$v];
                     $whereArr[] = [$k =>$v];
@@ -1040,8 +1042,7 @@ class ProductMysqldb extends Service implements ProductInterface
                 ['in', 'id', $productIds]
                 ['in', 'id', $productIds]
             ];
             ];
             $appName = Yii::$service->helper->getAppName();
             $appName = Yii::$service->helper->getAppName();
-            $category_query_priceRange = Yii::$app->store->get($appName.'_catalog','category_query_priceRange');
-            //print_r($ca)
+            $category_query_priceRange = Yii::$app->store->get($appName.'_catalog','category_filter_attr');
             foreach ($where as $k=>$v) {
             foreach ($where as $k=>$v) {
                 if ($k == 'price' && is_array($v)) {  // 价格数据处理。
                 if ($k == 'price' && is_array($v)) {  // 价格数据处理。
                     foreach ($v as $k1=>$v1) {
                     foreach ($v as $k1=>$v1) {
@@ -1052,7 +1053,7 @@ class ProductMysqldb extends Service implements ProductInterface
                         if ($k1 == '$lt') $fh = '<' ;
                         if ($k1 == '$lt') $fh = '<' ;
                         $whereArr[] = [$fh, 'price', $v1];
                         $whereArr[] = [$fh, 'price', $v1];
                     }
                     }
-                }elseif( strpos('colorsize',$k) !== FALSE   ){
+                }elseif( strpos($category_query_priceRange,$k) !== FALSE   ){
                     $whereArr[] = ['like','attr_group_info',$v];
                     $whereArr[] = ['like','attr_group_info',$v];
                 } else {
                 } else {
                     $whereArr[] = [$k =>$v];
                     $whereArr[] = [$k =>$v];
@@ -1116,12 +1117,16 @@ class ProductMysqldb extends Service implements ProductInterface
             $where['status'] = $this->getEnableStatus();
             $where['status'] = $this->getEnableStatus();
         }
         }
 
 
-        if($filter_attr != 'color'){
+        $appName = Yii::$service->helper->getAppName();
+        $category_query_priceRange = Yii::$app->store->get($appName.'_catalog','category_filter_attr');
+
+        if(strpos("0".$category_query_priceRange,$filter_attr) == FALSE  ){
+
             if (!$this->_productModel->hasAttribute($filter_attr)) {
             if (!$this->_productModel->hasAttribute($filter_attr)) {
             return [];
             return [];
             }
             }
         }
         }
-
+        //print_r($filter_attr);exit;
         // where条件处理
         // where条件处理
         if ($categoryId = $where['category']) {
         if ($categoryId = $where['category']) {
             $productIds = $this->getProductIdsByCategoryId($categoryId);
             $productIds = $this->getProductIdsByCategoryId($categoryId);
@@ -1132,7 +1137,7 @@ class ProductMysqldb extends Service implements ProductInterface
                 ['in', 'id', $productIds]
                 ['in', 'id', $productIds]
             ];
             ];
             foreach ($where as $k=>$v) {
             foreach ($where as $k=>$v) {
-                if($k == 'color'){
+                if(strpos($category_query_priceRange,$k) !== FALSE ){
                     $whereArr[] = ['like','attr_group_info',$v];
                     $whereArr[] = ['like','attr_group_info',$v];
                 }else{
                 }else{
                     $whereArr[] = [$k =>$v];
                     $whereArr[] = [$k =>$v];
@@ -1151,11 +1156,11 @@ class ProductMysqldb extends Service implements ProductInterface
 
 
         foreach ($product_attrs as $key => $value) {
         foreach ($product_attrs as $key => $value) {
             $product_attr = unserialize($value['attr_group_info']);
             $product_attr = unserialize($value['attr_group_info']);
-            if(isset($product_attr['color'])){
-                if(isset($filter_attr_array[$product_attr['color']])){
-                    $filter_attr_array[$product_attr['color']] += 1;
+            if(isset($product_attr[$filter_attr])){
+                if(isset($filter_attr_array[$product_attr[$filter_attr]])){
+                    $filter_attr_array[$product_attr[$filter_attr]] += 1;
                 }else{
                 }else{
-                    $filter_attr_array[$product_attr['color']] = 1;
+                    $filter_attr_array[$product_attr[$filter_attr]] = 1;
                 }   
                 }   
             }
             }
         }
         }
@@ -1177,7 +1182,7 @@ class ProductMysqldb extends Service implements ProductInterface
         //            ->where($where)
         //            ->where($where)
         //            ->groupBy($filter_attr)
         //            ->groupBy($filter_attr)
         //            ->all();
         //            ->all();
-        
+
         return $filter_data;
         return $filter_data;
     }
     }