Skip to content

Commit

Permalink
yii2-mongodb升级成2版本带来的问题处理
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Mar 7, 2017
1 parent eb212e2 commit e6201d8
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 32 deletions.
7 changes: 4 additions & 3 deletions app/appfront/modules/Customer/block/productfavorite/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ public function getProductInfo($coll){
$product_ids = [];
$favorites = [];
foreach($coll as $one){

$p_id = $one['product_id'];
$product_ids[] = new \MongoId($p_id) ;
$favorites[$p_id] = [
'updated_at' => $one['updated_at'],
'favorite_id' => $one['_id']->{'$id'},
'favorite_id' => (string)$one['_id'],
];
}
# 得到产品的信息
Expand All @@ -78,7 +79,7 @@ public function getProductInfo($coll){
$product_arr = [];
if(is_array($data['coll']) && !empty($data['coll'])){
foreach($data['coll'] as $one){
$p_id = $one['_id']->{'$id'};
$p_id = (string)$one['_id'];
$one['updated_at'] = $favorites[$p_id]['updated_at'];
$one['favorite_id'] = $favorites[$p_id]['favorite_id'];
$product_arr[] = $one;
Expand Down Expand Up @@ -109,4 +110,4 @@ protected function getProductPage($countTotal){
];
return Yii::$service->page->widget->renderContent('category_product_page',$config);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.9" ,
"yiisoft/yii2": ">=2.0.11" ,
"fancyecommerce/fec_admin":"~1.3.6.3",
"yiisoft/yii2-mongodb": "~2.1.0" ,
"skeeks/yii2-assets-auto-compress": "*",
Expand Down
2 changes: 1 addition & 1 deletion services/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected function actionGetSkusByIds($ids){
$data = $coll['coll'];
if(!empty($data) && is_array($data)){
foreach($data as $one){
$skus[$one[$_id]->{'$id'}] = $one['sku'];
$skus[(string)$one[$_id]] = $one['sku'];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions services/cart/QuoteItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function getProductSpuOptions($productOb){
$attrs = array_keys($attrInfo);
\fecshop\models\mongodb\Product::addCustomProductAttrs($attrs);
}
$productOb = Yii::$service->product->getByPrimaryKey($productOb['_id']->{'$id'});
$productOb = Yii::$service->product->getByPrimaryKey((string)$productOb['_id']);
$spuArr = Yii::$service->product->getSpuAttr($productAttrGroup);
if(is_array($spuArr) && !empty($spuArr)){
foreach($spuArr as $spu_attr){
Expand Down Expand Up @@ -324,4 +324,4 @@ public function updateCartId($new_cart_id,$cart_id){
}


}
}
14 changes: 7 additions & 7 deletions services/category/CategoryMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function removeChildCate($id){
$data = Category::find()->where(['parent_id'=>$id])->all();
if(!empty($data)){
foreach($data as $one){
$idVal = $one['_id']->{'$id'};
$idVal = (string)$one['_id'];
if($this->hasChildCategory($idVal)){
$this->removeChildCate($idVal);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getTreeArr($rootCategoryId = '',$lang=''){
$idKey= $this->getPrimaryKey();
if(!empty($categorys)){
foreach($categorys as $cate){
$idVal = $cate[$idKey]->{'$id'};
$idVal = (string)$cate[$idKey];
$arr[$idVal] = [
$idKey => $idVal,
'name' => Yii::$service->fecshoplang->getLangAttrVal($cate['name'],'name',$lang),
Expand Down Expand Up @@ -228,7 +228,7 @@ protected function getParentCategory($parent_id){
if(isset($category['_id']) && !empty($category['_id']) ){
$currentUrlKey = $category['url_key'];
$currentName = $category['name'];
$currentId = $category['_id']->{'$id'};
$currentId = (string)$category['_id'];

$currentCategory[] = [
'_id' => $currentId,
Expand Down Expand Up @@ -260,7 +260,7 @@ public function getFilterCategory($category_id,$parent_id){
$currentCategory = Category::findOne($category_id);
$currentUrlKey = $currentCategory['url_key'];
$currentName = $currentCategory['name'];
$currentId = $currentCategory['_id']->{'$id'};
$currentId = (string)$currentCategory['_id'];
$returnData['current'] = [
'_id' => $currentId,
'name' => $currentName,
Expand Down Expand Up @@ -291,7 +291,7 @@ protected function getOneLevelCateChild($category){
])->all();
if(is_array($cate) && !empty($cate)){
foreach($cate as $one){
$c_id = $one['_id']->{'$id'};
$c_id = (string)$one['_id'];
$data[$c_id] = [
'name' => $one['name'],
'url_key' => $one['url_key'],
Expand Down Expand Up @@ -321,7 +321,7 @@ protected function getAllParentCate($allParent){
if(is_array($cate) && !empty($cate)){
//echo '**********';
foreach($cate as $one){
$c_id = $one['_id']->{'$id'};
$c_id = (string)$one['_id'];
$data[$c_id] = [
'name' => $one['name'],
'url_key' => $one['url_key'],
Expand Down Expand Up @@ -358,7 +358,7 @@ protected function getChildCate($category_id){
foreach($data as $one){
$currentUrlKey = $one['url_key'];
$currentName = $one['name'];
$currentId = $one['_id']->{'$id'};
$currentId = (string)$one['_id'];

$arr[$currentId] = [
//'_id' => $currentId,
Expand Down
6 changes: 3 additions & 3 deletions services/category/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ protected function actionGetCategoryMenuArr($parentId=''){
if(is_array($data) && !empty($data)){
foreach($data as $category){
$categoryOne = [
'_id' => $category['_id']->{'$id'},
'_id' => (string)$category['_id'],
'name' => Yii::$service->store->getStoreAttrVal($category['name'],'name'),
'menu_custom'=> Yii::$service->store->getStoreAttrVal($category['menu_custom'],'menu_custom'),
'url' => Yii::$service->url->getUrl($category['url_key']),
];
$childMenu = $this->getCategoryMenuArr($category['_id']->{'$id'});
$childMenu = $this->getCategoryMenuArr((string)$category['_id']);
if($childMenu){
$categoryOne['childMenu'] = $childMenu;
}
Expand All @@ -67,4 +67,4 @@ protected function hasChild($categoryId){
return true;
return false;
}
}
}
4 changes: 2 additions & 2 deletions services/order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function getProductSpuOptions($productOb){
$attrs = array_keys($attrInfo);
\fecshop\models\mongodb\Product::addCustomProductAttrs($attrs);
}
$productOb = Yii::$service->product->getByPrimaryKey($productOb['_id']->{'$id'});
$productOb = Yii::$service->product->getByPrimaryKey((string)$productOb['_id']);
$spuArr = Yii::$service->product->getSpuAttr($productAttrGroup);
if(is_array($spuArr) && !empty($spuArr)){
foreach($spuArr as $spu_attr){
Expand Down Expand Up @@ -183,4 +183,4 @@ protected function actionSaveOrderItems($items,$order_id,$store){
}


}
}
4 changes: 2 additions & 2 deletions services/search/MongoSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ protected function fullTearchText($filter){
*/
$s_data = [];
foreach($data as $one){
$_id = $one['_id']->{'$id'};
$_id = (string)$one['_id'];
$s_data[$_id] = $one;
}
$return_data = [];
foreach($productIds as $product_id){
$return_data[] = $s_data[$product_id->{'$id'}];
$return_data[] = $s_data[(string)$product_id];
}
return [
'coll' => $return_data ,
Expand Down
8 changes: 4 additions & 4 deletions services/search/XunSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function actionSyncProductInfo($product_ids,$numPerPage){
if(!empty($this->searchLang) && is_array($this->searchLang)){
foreach($this->searchLang as $langCode){
$XunSearchModel = new XunSearchModel();
$XunSearchModel->_id = $one['_id']->{'$id'};
$XunSearchModel->_id = (string)$one['_id'];
$one['name'] = Yii::$service->fecshoplang->getLangAttrVal($one_name,'name',$langCode);
$one['description'] = Yii::$service->fecshoplang->getLangAttrVal($one_description,'description',$langCode);
$one['short_description'] = Yii::$service->fecshoplang->getLangAttrVal($one_short_description,'short_description',$langCode);
Expand Down Expand Up @@ -165,12 +165,12 @@ protected function fullTearchText($select,$where,$pageNum,$numPerPage,$product_s
*/
$s_data = [];
foreach($data as $one){
$_id = $one['_id']->{'$id'};
$_id = (string)$one['_id'];
$s_data[$_id] = $one;
}
$return_data = [];
foreach($productIds as $product_id){
$return_data[] = $s_data[$product_id->{'$id'}];
$return_data[] = $s_data[(string)$product_id];
}
return [
'coll' => $return_data ,
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function actionGetFrontSearchFilter($filter_attr,$where){
*/
protected function actionRemoveByProductId($product_id){
if(is_object($product_id)){
$product_id = $product_id->{'$id'};
$product_id = (string)$product_id;
$model = XunSearchModel::findOne($product_id);
$model->delete();
}
Expand Down
9 changes: 2 additions & 7 deletions shell/initDb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
#processDate=$1
#Cur_Dir=$(pwd)
Cur_Dir=$(cd `dirname $0`; pwd)
#fec_admin
$Cur_Dir/../../../../yii migrate --migrationPath=@fecadmin/migrations

#db
$Cur_Dir/../../../../yii migrate --migrationPath=@fecshop/migrations/db/product/log

$Cur_Dir/../../../../yii migrate --interactive=0 --migrationPath=@fecshop/migrations/mysqldb
#mongodb
$Cur_Dir/../../../../yii mongodb-migrate --migrationPath=@fecshop/migrations/mongodb/urlwrite
$Cur_Dir/../../../../yii mongodb-migrate --migrationPath=@fecshop/migrations/mongodb/product/log

$Cur_Dir/../../../../yii mongodb-migrate --interactive=0 --migrationPath=@fecshop/migrations/mongodb


0 comments on commit e6201d8

Please sign in to comment.