为什么我的收藏 不显示收藏产品? 后台收藏有收藏数据, var_dump($coll); 数据是空的?
请问哪里出现问题了呢?
还有我想添加个用户产品浏览器记录 足迹,请问有没有好的方法做?
本文由 happysunzone 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。
显示文件:https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/theme/base/front/customer/productfavorite/index.php
提供数据的文件:https://github.com/fecshop/yii2_fecshop/blob/master/app/appfront/modules/Customer/block/productfavorite/Index.php
public function getLastData() { $this->initFavoriteParam(); $identity = Yii::$app->user->identity; $user_id = $identity->id; if (!$user_id) { Yii::$service->helper->errors->add('current user id is empty'); return; } $filter = [ 'pageNum' => $this->pageNum, 'numPerPage'=> $this->numPerPage, 'orderBy' => ['updated_at' => SORT_DESC], 'where' => [ ['user_id' => $user_id], ], 'asArray' => true, ]; $data = Yii::$service->product->favorite->list($filter); $coll = $data['coll']; $count = $data['count']; $pageToolBar = $this->getProductPage($count); $product_arr = $this->getProductInfo($coll); return [ 'coll' => $product_arr, 'pageToolBar' => $pageToolBar, ]; }
数据是由这里 $data = Yii::$service->product->favorite->list($filter); 获取的,这个函数是service函数,也就是文件: https://github.com/fecshop/yii2_fecshop/blob/master/services/product/Favorite.php
$data = Yii::$service->product->favorite->list($filter);
protected function actionList($filter) { $query = $this->_favoriteModel->find(); $query = Yii::$service->helper->ar->getCollByFilter($query, $filter); return [ 'coll' => $query->all(), 'count'=> $query->limit(null)->offset(null)->count(), ]; }
发现一个bug 收藏的产品,是根据$user_id,从mongodb里查询出来的,需要把$user_id数据类型强制转换成int,才可以把数据查询出来。 上面是我的开发环境。
@lincond #2楼
多谢,找时间处理一下。