提交 e6201d83 编写于 作者: R root

yii2-mongodb升级成2版本带来的问题处理

上级 eb212e26
......@@ -54,11 +54,12 @@ class Index {
$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'],
];
}
# 得到产品的信息
......@@ -78,7 +79,7 @@ class Index {
$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;
......@@ -109,4 +110,4 @@ class Index {
];
return Yii::$service->page->widget->renderContent('category_product_page',$config);
}
}
\ No newline at end of file
}
......@@ -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": "*",
......
......@@ -297,7 +297,7 @@ class Product extends Service
$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'];
}
}
}
......
......@@ -205,7 +205,7 @@ class QuoteItem extends Service
$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){
......@@ -324,4 +324,4 @@ class QuoteItem extends Service
}
}
\ No newline at end of file
}
......@@ -141,7 +141,7 @@ class CategoryMongodb implements CategoryInterface
$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);
}
......@@ -171,7 +171,7 @@ class CategoryMongodb implements CategoryInterface
$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),
......@@ -228,7 +228,7 @@ class CategoryMongodb implements CategoryInterface
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,
......@@ -260,7 +260,7 @@ class CategoryMongodb implements CategoryInterface
$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,
......@@ -291,7 +291,7 @@ class CategoryMongodb implements CategoryInterface
])->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'],
......@@ -321,7 +321,7 @@ class CategoryMongodb implements CategoryInterface
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'],
......@@ -358,7 +358,7 @@ class CategoryMongodb implements CategoryInterface
foreach($data as $one){
$currentUrlKey = $one['url_key'];
$currentName = $one['name'];
$currentId = $one['_id']->{'$id'};
$currentId = (string)$one['_id'];
$arr[$currentId] = [
//'_id' => $currentId,
......
......@@ -39,12 +39,12 @@ class Menu extends Service
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;
}
......@@ -67,4 +67,4 @@ class Menu extends Service
return true;
return false;
}
}
\ No newline at end of file
}
......@@ -115,7 +115,7 @@ class Item extends Service
$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){
......@@ -183,4 +183,4 @@ class Item extends Service
}
}
\ No newline at end of file
}
......@@ -258,12 +258,12 @@ class MongoSearch extends Service implements SearchInterface
*/
$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 ,
......
......@@ -52,7 +52,7 @@ class XunSearch extends Service implements SearchInterface
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);
......@@ -165,12 +165,12 @@ class XunSearch extends Service implements SearchInterface
*/
$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 ,
......@@ -229,7 +229,7 @@ class XunSearch extends Service implements SearchInterface
*/
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();
}
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册