tgy3300

第 644 位会员

会员
个人信息
  • 加入于 2018-09-08 12:02:19
  • 最后登录时间 2年前
个人成就
  • 发表文章次数 56
  • 发布回复次数 123
  • 个人主页浏览次数 37
appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

是的,我单独把我新增的@appserver\config\fecshop_local_modules\Catalog.php文件里的代码注释了,让我新增的接口失效,测试/catalog/category/index接口正常

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

@Fecshop [#10楼](#comment10) ,我的11楼问题,你看看,问题出在哪里,新增的 appserver 接口 和 /catalog/category/index 代码一样,结果测试就出现标题中的错误提示

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

我知道问题出在哪里了?不过有点不明白,为什么会出这个错误,特来咨询

出现这问题是因为我新增了接口 /catalog/category/zl-server ,我的做法是

1、新建 @appserver\config\fecshop_local_modules\Catalog.php 文件

2、在该文件里写入代码如下

return [
    'catalog' => [
        'controllerMap' => [
            'category'    => 'appserver\local\local_modules\Catalog\controllers\CategoryController',
        ]
    ]
];

3、新建 @appserver\local\local_modules\Catalog\controllers\CategoryController.php 文件

4、该文件代码如下

namespace appserver\local\local_modules\Catalog\controllers;
use Yii;

class CategoryController extends \fecshop\app\appserver\modules\Catalog\controllers\CategoryController
{
	public function actionZlServer(){
        
        if(Yii::$app->request->getMethod() === 'OPTIONS'){
            return [];
        }
        // 每页显示的产品个数,进行安全验证,如果个数不在预先设置的值内,则会报错。
        // 这样是为了防止恶意攻击,也就是发送很多不同的页面个数的链接,绕开缓存。
        $this->getNumPerPage();
        //echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
        if(!$this->initCategory()){
            $code = Yii::$service->helper->appserver->category_not_exist;
            $data = [];
            $responseData = Yii::$service->helper->appserver->getResponseData($code, $data);
            
            return $responseData;
        }
        
        // change current layout File.
        //Yii::$service->page->theme->layoutFile = 'home.php';

        $productCollInfo = $this->getCategoryProductColl();
        $products = $productCollInfo['coll'];
        $this->_productCount = $productCollInfo['count'];
        $p = Yii::$app->request->get('p');
        $p = (int)$p;
        $query_item = $this->getQueryItem();
        $page_count = $this->getProductPageCount();
        $this->category_name = Yii::$service->store->getStoreAttrVal($this->_category['name'], 'name');
        $code = Yii::$service->helper->appserver->status_success;
        $data = [
            'name'              => $this->category_name ,
            'name_default_lang' => Yii::$service->fecshoplang->getDefaultLangAttrVal($this->_category['name'], 'name'),
            'title'             => $this->_title,
            'image'             => $this->_category['image'] ? Yii::$service->category->image->getUrl($this->_category['image']) : '',
            'products'          => $products,
            'query_item'        => $query_item,
            'refine_by_info'    => $this->getRefineByInfo(),
            'filter_info'       => $this->getFilterInfo(),
            'filter_price'      => $this->getFilterPrice(),
            'filter_category'   => $this->getFilterCategory(),
            'page_count'        => $page_count,
        ];
        $responseData = Yii::$service->helper->appserver->getResponseData($code, $data);
        
        return $responseData;
    }
}

结果一测试就出现 the $sort key specification must be an object 错误了

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

fecshop版本是1.7.0.0

环境不会有问题,我之前不是发过

http://www.fecshop.com/topic/1726

这个帖子吗?

如果环境有问题,这个帖子中的内容就不存在 了

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

一如继往的没有解决问题,卡在这了,使用fecshop appserver 提供的 /catalog/category/index 也出现这问题,这接口我没动过

接口文档请求示例

{

categoryId:"57b6ac42f656f246653bf576",
sortColumn:"review_count",
filterAttrs:{"color":"multicolor","size":"M"},
filterPrice:"20-30"

}

我的请求

{

categoryId:"5c2f6c259dc6d61c134bf242",
sortColumn: "",
filterAttrs: {},
filterPrice: ""

}

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

代码跟踪调试了几遍,也找不到问题出在哪……………………

appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前
@fecshop\services\category\Product.php  文件中的 actionGetFrontList 函数

protected function actionGetFrontList($filter)
    {
        $filter['group'] = '$spu';
        $coll = Yii::$service->product->getFrontCategoryProducts($filter);
        $collection = $coll['coll'];
        $count = $coll['count'];
        $arr = $this->convertToCategoryInfo($collection);
        return [
            'coll' => $arr,
            'count'=> $count,
        ];
    }
	
	------------------------------------------------------------
	
	$filter['group'] = '$spu';     这个  $spu  从哪里来的,单引号下这个变量就是个字符串呀………………
	
	--------------------------------------------------
	
	@fecshop\services\product\ProductMongodb.php 文件的 getFrontCategoryProductsGroupBySpu()函数代码如下
	
	public function getFrontCategoryProductsGroupBySpu($filter)
    {
        ...
        $group['_id'] = $filter['group'];
        ...
	}
	
	
	这函数的  $group['_id'] = $filter['group'];
	
	$filter['group']  解析出来是字符串  '$spu'
	
	$group['_id'] = '$spu';     这是什么鬼:disappointed_relieved:
	
	
appserver 的 /catalog/category/index 接口出现 the $sort key specification must be an object 错误5年前

@Fecshop [[#2楼](#comment2)](#comment2) 我打印出来的 $filter 数据如下

Array
(
    [pageNum] => 1
    [numPerPage] => 
    [orderBy] => 
    [where] => Array
        (
            [category] => 5c2f6c259dc6d61c134bf242
        )

    [select] => Array
        (
            [0] => sku
            [1] => spu
            [2] => name
            [3] => image
            [4] => price
            [5] => special_price
            [6] => special_from
            [7] => special_to
            [8] => url_key
            [9] => score
        )

    [group] => $spu
)

这个 $filter 数据是 /catalog/category/getCategoryProductColl() 函数给的,代码如下,这个函数我没动过


$filter = [
            'pageNum'      => $this->getPageNum(),
            'numPerPage'   => $this->getNumPerPage(),
            'orderBy'      => $this->getOrderBy(),
            'where'        => $this->_where,
            'select'       => $select,
        ];

        $productList = Yii::$service->category->product->getFrontList($filter);

我的请求参数也是按文档的来的

接口文档请求示例

{
    categoryId:"57b6ac42f656f246653bf576",
    sortColumn:"review_count",
    filterAttrs:{"color":"multicolor","size":"M"},
    filterPrice:"20-30"
}

我的请求

{
    categoryId:"5c2f6c259dc6d61c134bf242",
    sortColumn: "",
    filterAttrs: {},
    filterPrice: ""
}
在分类下添加的产品,通过接口获取的数据好奇怪5年前

@Fecshop [#5楼](#comment5) 不重写了,我新增接口吧,万一以后还要用这接口呢

在分类下添加的产品,通过接口获取的数据好奇怪5年前

上面不是说了接口地址吗?

Fecshop-1.7.0.0 版本发布,全新后台模板样式5年前

@Fecshop [#7楼](#comment7)

http://www.fecshop.com/topic/1660

新版本考虑下这个帖子的建议呗:smile: :stuck_out_tongue_winking_eye:

Fecshop-1.7.0.0 版本发布,全新后台模板样式5年前

我升级了,可这后台我觉得不好看呀,

appserver 中的 /customer/login/account 接口无法识别fetch提交的post数据5年前

@Fecshop [#24楼](#comment24) 可以了,真是这个问题,我想问下,以后使用vue,通过form提交数据,不用把该配置取消吧?

appserver 中的 /customer/login/account 接口无法识别fetch提交的post数据5年前

@Fecshop [#16楼](#comment16)

'request' => [
            'class' => 'yii\web\Request',
            'parsers' => [
                 'application/json' => 'yii\web\JsonParser',
            ],
        ],

请问下这个是在哪里配置,是不是真的是这个没配置

appserver 中的 /customer/login/account 接口无法识别fetch提交的post数据5年前

@Fecshop #15楼 我打印 $this->parsers[$contentType] 为空,打印 $contentType 显示为 application/json

appserver 中的 /customer/login/account 接口无法识别fetch提交的post数据5年前

后端接口我是用的fecshop的appserver端,没做过二次开发,前端我是用react开发的一个单页应用,与appserver端接口交互是通过fetch封装的一个js函数,现在的问题的是我前端与接口交互时,fetch提交的数据是放在request payload 的,而不是form data,使用Yii::$app->request->post()时,\yii\web\Request.php 的 getBodyParams() 方法识别不了我的 request payload 数据,所以在getBodyParams() 方法中程序走了下面这一步

} elseif ($this->getMethod() === 'POST') {
	$this->_bodyParams = $_POST;
}
appserver 中的 /customer/login/account 接口无法识别fetch提交的post数据5年前

Yii::$app->request->post()一样不能获取到数据,我debug跟了一遍代码,并在3楼说明了原因,是 \yii\web\Request.php 的 getBodyParams() 方法没有兼顾到我的这种情况,需要改下getBodyParams() 方法,我暂时还不怎么改,先用 php://input

Your Site Analytics