很多第一次接触fecmall的用户,在安装fecmall的时候,会出现报错:this domain is not config in store service, you must config it in admin store config
问题分析:
这个是因为在安装步骤填写的域名
和访问的域名
(nginx配置的域名
)不一致造成的。
在界面安装之前,您需要先看一下文档:Fecmall界面安装
1.在fecmall界面安装步骤,如图:
原因:以Pc站域名
为例子
1.域名不一致导致的问题,您在nginx配置解析到appfront/web
的域名,如果是 pc.xxx.com
,但是,如果您在安装界面Pc站域名
里面填写的 www.xxx.com
,安装完成后访问pc就会报错.
2.域名填写格式不对,譬如填写 http://pc.xxx.com
, http://pc.xxx.com/
, pc.xxx.com/
,等都是错误的,必须按照格式pc.xxx.com
填写
3.对于手机H5
等其他域名同样原理,必须和nginx配置的访问的域名一致,也就是严格按照上面的格式
填写
问题修复
1.如果访问pc域名(Appfront)报该错误,可以进入网站后台,打开后台菜单: 网站配置
--> Appfront配置
--> Store配置
打开激活状态的store(一般为id=1的条目)进行编辑,将Store Key
改为正确的格式,譬如格式:pc.xxx.com
(改为您nginx
配置的对应appfront/web
的域名)
2.如果访问H5域名(Apphtml5)报该错误,可以进入网站后台,打开后台菜单: 网站配置
--> Apphtml5配置
--> Store配置
打开激活状态的store(一般为id=1的条目)进行编辑,将Store Key
改为正确的格式,譬如格式:h5.xxx.com
(改为您nginx
配置的对应apphtml5/web
的域名)
3.如果访问前后端分离Api(Appserver)报该错误,可以进入网站后台,打开后台菜单: 网站配置
--> Appserver配置
--> Store配置
进入菜单后进行编辑,将Store Key
改为正确的格式,譬如格式:appserver.xxx.com
(改为您nginx
配置的对应appserver/web
的域名)
4.如果访问图片(Appimage)报该错误,可以进入网站后台,打开后台菜单: 网站配置
--> 基础配置
--> 基础配置
进入菜单后进行编辑,将图片域名
改为正确的格式,譬如格式:http://img.fancyecommerce.com
(改为您nginx
配置的对应appimage/common
的域名,如果您使用https,那么将其改为https开头即可).
最后:
可能会有童鞋问,为什么搞这么多域名,这个是为了安全,性能,等多方面的考量,虽然对小白用户不友好,但是,这样设计在框架层面有很高的优势,因此,这个不可妥协,必须用这种多域名的方式。
案例debug代码分析实例:
因为遇到这个问题的童鞋有点多,这里说一下debug代码诊断的方法(线上服务器,调试了一个遇到这个问题的童鞋,特将调试方法步骤写一下)
1.进入fecmall根目录,打开文件:vendor/fancyecommerce/fecshop/services/Store.php
226行左右找到函数bootstrap($app)
添加一下断点输出,更改如下
public function bootstrap($app)
{
$host = explode('//', $app->getHomeUrl());
$stores = $this->stores;
$init_complete = 0;
var_dump($host[1]);
$storeArr = [];
if (is_array($stores) && !empty($stores)) {
foreach ($stores as $store_code => $store) {
$storeArr[] = $store_code;
if ($host[1] == $store_code) {
$this->html5DeviceCheckAndRedirect($store_code, $store);
Yii::$service->store->currentStore = $store_code;
$this->store = $store;
if (isset($store['language']) && !empty($store['language'])) {
Yii::$service->store->currentLang = $store['language'];
Yii::$service->store->currentLangCode = Yii::$service->fecshoplang->getLangCodeByLanguage($store['language']);
Yii::$service->store->currentLangName = $store['languageName'];
Yii::$service->page->translate->setLanguage($store['language']);
}
// set local theme dir.
if (isset($store['localThemeDir']) && $store['localThemeDir']) {
Yii::$service->page->theme->setLocalThemeDir($store['localThemeDir']);
}
// set third theme dir.
if (isset($store['thirdThemeDir']) && $store['thirdThemeDir']) {
Yii::$service->page->theme->setThirdThemeDir($store['thirdThemeDir']);
}
// init store currency.
if (isset($store['currency']) && !empty($store['currency'])) {
$currency = $store['currency'];
} else {
$currency = '';
}
Yii::$service->page->currency->initCurrency($currency);
/**
* current domain is config is store config.
*/
$init_complete = 1;
$this->thirdLogin = isset($store['thirdLogin']) ? $store['thirdLogin'] : [];
/**
* appserver 部分
*/
if (isset($store['serverLangs']) && !empty($store['serverLangs'])) {
$this->serverLangs = $store['serverLangs'];
}
$headers = Yii::$app->request->getHeaders();
if (isset($headers['fecshop-lang']) && $headers['fecshop-lang']) {
$h_lang = $headers['fecshop-lang'];
if (is_array($this->serverLangs)) {
foreach ($this->serverLangs as $one) {
if ($one['code'] == $h_lang) {
Yii::$service->store->currentLangCode = $h_lang;
Yii::$service->store->currentLang = $one['language'];
Yii::$service->store->currentLangName = $one['languageName'];
Yii::$service->page->translate->setLanguage($one['language']);
break;
}
}
}
}
break;
}
}
}
var_dump($storeArr);exit;
if (!$init_complete) {
throw new InvalidValueException('this domain is not config in store service, you must config it in admin store config');
}
}
将$host[1]
进行打印输出,同时打印$storeArr
,如果$host[1]
在数组$storeArr
中不存在就会报错抛出异常。
打印结果如下:
string(17) "m.rabbit-xxx.com" array(6) { [0]=> string(15) "rabbit-xxx.com" [1]=> string(18) "rabbit-xxx.com/fr" [2]=> string(18) "rabbit-xxx.com/es" [3]=> string(18) "rabbitxxx.com/cn" [4]=> string(18) "rabbit-xxx.com/it" [5]=> string(18) "rabbit-xxx.com/de" }
结果: $host[1] m.rabbit-xxx.com
在后面的数组$storeArr
中不存在,而$storeArr
数组的打印结果,是appfront部分的store配置,因此初步判定,nginx配置的apphtml5部分,nginx将h5域名 m.rabbit-xxx.com
指向了文件路径appfront/web
,而不是apphtml5/web
论证判断:打开apphtml5/web/index.php,在第一行代码中加入断点输出
<?php
echo 1;exit;
...
访问m.rabbit-xxx.com
没有反应,而在appfront/web/index.php中加入断点输出,继续访问m.rabbit-xxx.com
,输出了结果1
。
因此这个问题,原因就是nginx配置有问题,将 h5域名m.rabbit-xxx.com
解析到了pc的appfront入口导致的错误
您也可以参考上面步骤打断点输出,debug代码调试找原因