1.每个store对应一个语言,这个是一一对应的,切换到store,语言就会变成相应的语言。
2.每个store有一个默认的货币,网站第一次访问,货币默认使用的是该货币
3.如果访问后,切换成其他的store,语言会改变,货币不会改变,因为,我在中文store下,我同样可以查看美元,欧元等其他语言的货币,而不仅仅RMB
4.对于你的 www.fecshoptest.com/cn
, 你如果把session cookie清空,然后访问,就会发现货币是RMB
对于这部分的代码可以参看
https://github.com/fecshop/yii2_fecshop/blob/master/services/Store.php
/*
* init store currency.
*/
if (isset($store['currency']) && !empty($store['currency'])) {
$currency = $store['currency'];
} else {
$currency = '';
}
Yii::$service->page->currency->initCurrency($currency);
https://github.com/fecshop/yii2_fecshop/blob/master/services/page/Currency.php
/**
* @property $currencyCode | 货币简码
* 初始化货币信息,在service Store bootstrap(Yii::$app->store->bootstrap()), 中会被调用
* 1. 如果 $this->defaultCurrency 和 $this->baseCurrecy 没有设置,将会报错。
* 2. 如果 传递参数$currencyCode为空,则会使用默认货币
*/
protected function actionInitCurrency($currencyCode = '')
{
if (!$this->defaultCurrency) {
throw new InvalidConfigException('defautlt currency must config');
}
if (!$this->baseCurrecy) {
throw new InvalidConfigException('base currency must config');
}
if (!$this->getCurrentCurrency()) {
if (!$currencyCode) {
$currencyCode = $this->defaultCurrency;
}
$this->setCurrentCurrency($currencyCode);
}
}