# 常見問題 三
## 38,js報錯 Uncaught ReferenceError: Base64 is not defined
2.2.6升級到2.3.0后,后臺主題編輯頁面 打不開 js有報錯
> Uncaught ReferenceError: Base64 is not defined
解決辦法:
找到下面這幾個文件
~~~
> /vendor/magento/module-email/view/adminhtml/ui_component/design_config_form.xml
> /vendor/magento/module-catalog/view/adminhtml/ui_component/design_config_form.xml
> /vendor/magento/module-backend/view/adminhtml/ui_component/design_config_form.xml
> /vendor/magento/module-swatches/view/adminhtml/ui_component/design_config_form.xml
> /vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml
~~~
把
```
formElement="fileUploader"
```
替換成
```
formElement="imageUploader"
```
都保存后,再重新deploy下 就好了。
參考
https://github.com/magento/magento2/issues/19549
## 39,js報錯 Uncaught Error: Script error for: tinymce
2.2.6升級到2.3.0后,后臺第三方插件頁面打不開,js報錯
```
Uncaught Error: Script error for: tinymce
```
這是因為2.3.0里,升級tinymce了,升級到tinymce4了。之前舊的tinymce廢棄了,所以需要把`tinymce`的改成`tinymce4`就行。
比如
```
define([
"jquery",
"tinymce",
```
改成
```
define([
"jquery",
"tinymce4",
```
## 40,Unique constraint violation found
> Unique constraint violation found {"exception":"[object] (Magento\\Framework\\Exception\\AlreadyExistsException(code: 0): Unique constraint violation found at /www/wwwroot/newbestyle.com/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php:426, Magento\\Framework\\DB\\Adapter\\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-8144-product' for key 'GOOGLEOPTIMIZER_CODE_STORE_ID_ENTITY_ID_ENTITY_TYPE', query was: INSERT INTO `googleoptimizer_code` (`entity_id`, `entity_type`, `store_id`, `experiment_script`) VALUES (?, ?, ?, ?) at
解決辦法:
1, Go to admin -> Stores -> Configuration -> Sales -> Google API section
2, Change the configuration Enable Content Experiments to "No"
## 41,Argument 4 passed to Magento\Developer\Model\View\Asset\PreProcessor\FrontendCompilation
> FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: Argument 4 passed to Magento\De
veloper\Model\View\Asset\PreProcessor\FrontendCompilation::processContent() must be an instance of Magento\Framework\View\Asset\File\FallbackContext, in
stance of Magento\Framework\View\Asset\File\Context given, called in /home/www/magento2/vendor/magento/module-developer/Model/View/Asset/Pr
eProcessor/FrontendCompilation.php on line 90 and defined in /home/www/magento2/vendor/magento/module-developer/Model/View/Asset/PreProcess
or/FrontendCompilation.php:107
Stack trace:
#0 /home/www/magento2/vendor/magento/module-developer/Model/View/Asset/PreProcessor/FrontendCompilation.php(90): Magento\Developer\Model\Vi
ew\Asset\PreProcessor\FrontendCompilation->processContent('e3054c302a868e8...', '@import 'source...', '', Object(Magento\Framework\View\Asset\File\Conte
xt))
這是因為你在developer模式下,并且開啟了merge css/js功能,導致出問題了。
解決辦法有2種:
1,改成production模式,保留merge css/js功能
2,或者在developer模式下,把`dev/js/merge_files`和`dev/css/merge_css_files`設為0,也就是不merge css/js。
## 42,main.CRITICAL: No linked stock found
2.3.1才有這問題,需要設置多源庫存。
常見于分類頁面或者產品頁面報錯 甚至不顯示。
解決辦法:
1,Try going into Stores > Inventory > Sources and adding in a source. Maybe call it your business name, then fill in a country and zip value.
2,Then, try going into Stores > Inventory > Stocks. Call it "Default Stock" and apply it to all websites (if multi store) and hit save.
設置個默認倉庫就行了。
## 43,Fatal error: Uncaught TypeError: Return value of Magento\\Framework\\Encryption\\Adapter\\SodiumChachaIetf::decrypt() must be of the type string
這是m2的一個bug,在2.3.0里特殊環境下會發生。
解決辦法:
修改 `vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php`
~~~
$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
$payload,
$nonce,
$nonce,
$this->key
);
if ($plainText == false)
{
return "";
}
return $plainText;
~~~
參考:[https://github.com/magento/magento2/issues/19590](https://github.com/magento/magento2/issues/19590)
## 44, 2.3.1后臺產品列表里無法更新所有產品的屬性
2.3.1里產品列表 `Select All`,再 `Update Attributes`,發現只更新了20個(當前一頁)的產品。而不是所有的產品。
這是2.3.1的一個bug,2.3.2里還沒修復。
[https://github.com/magento/magento2/issues/22004](https://github.com/magento/magento2/issues/22004)
[https://github.com/magento/magento2/commit/0f29a266256cca24cd7dd1082aa4aa31a3a9eacd](https://github.com/magento/magento2/commit/0f29a266256cca24cd7dd1082aa4aa31a3a9eacd)
直接修改`vendor/magento/module-ui/view/base/web/js/grid/massactions.js`
把
```
if (itemsType === 'excluded' && data.selected && data.selected.length) {
itemsType = 'selected';
data[itemsType] = _.difference(data.selected, data.excluded);
}
```
這幾段代碼注釋掉就行了。
## 45, 2.2.6/2.2.7版本后臺上傳 placeholder圖片,不能保存

這是m2的一個bug,在2.2.6和2.2.7里出現,在2.3.0里修復了。
如果可以升級版本的話,就直接升級到最新版本。
如果不能升級版本的話,就修改下源代碼:
把`vendor/magento/module-config/Model/Config.php`內容替換為:
[https://raw.githubusercontent.com/magento/magento2/be9fa4a73b85022565db991f11dfceeecf40edae/app/code/Magento/Config/Model/Config.php](https://raw.githubusercontent.com/magento/magento2/be9fa4a73b85022565db991f11dfceeecf40edae/app/code/Magento/Config/Model/Config.php)
參考
[https://magento.stackexchange.com/questions/247775/cant-upload-product-placeholder-images-in-magento-2](https://magento.stackexchange.com/questions/247775/cant-upload-product-placeholder-images-in-magento-2)
## 46, bundle產品和簡單(可配置)產品一起購買下單,創建invoice時簡單(可配置)產品會丟失,導致支付的金額不對。
這是2.3.1的bug。在2.3.2里修復了。
[https://github.com/magento/magento2/issues/22246](https://github.com/magento/magento2/issues/22246)
[https://github.com/magento/magento2/commit/ec2c6ca7df68de9aaccecfb899b102a2a3eaa631](https://github.com/magento/magento2/commit/ec2c6ca7df68de9aaccecfb899b102a2a3eaa631)
## 47, Type Error occurred when creating object: Magento\\Framework\\Locale\\Resolver
這是2.3.1的bug。在2.3.2里修復了。
```
Type Error occurred when creating object: Magento\\Framework\\Locale\\Resolver, Return value of Magento\\Framework\\Encrypt
ion\\Adapter\\SodiumChachaIetf::decrypt() must be of the type string, boolean returned \[\]
```
見
https://github.com/magento/magento2/issues/19590
修改了 `vendor/magento/framework/Encryption/Adapter/SodiumChachaIetf.php`
```
public function decrypt(string $data): string
{
$nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
$payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');
try {
$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
$payload,
$nonce,
$nonce,
$this->key
);
} catch (\SodiumException $e) {
$plainText = '';
}
return $plainText !== false ? $plainText : '';
}
```
## 48, Front controller reached 100 router match iterations
~~~
Exception #0 (LogicException): Front controller reached 100 router match iterations
~~~
這一般是2個插件同名,導致沖突了。
比如2個blog插件,`Magefan_Blog`和`MGS_Blog`,這2個的frontend/routes.xml 都是`blog`。
并且都重寫了前臺路由:
```
MGS\Blog\Controller\Router
Magefan\Blog\Controller\Router
```
導致沖突了。禁用一個,保留一個就行。
[https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html](https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html)
[https://github.com/magento/magento2/issues/21580](https://github.com/magento/magento2/issues/21580)
## 49, Session data file is not created by your uid
```
Warning: SessionHandler::read(): Session data file is not created by your uid
```
這個是權限問題,php的session默認放在/tmp下的,給/tmp權限即可。
或者m2里可以指定session存放路徑,在app/etc/env.php里添加:
```
'session' => [
'save' => 'files',
'save_path' => '/var/www/toncen-test/var/session'
],
```
## 50,Elasticsearch pagination 分頁有問題
這是2.3.3的一個bug。
見
[https://github.com/magento/magento2/issues/25038](https://github.com/magento/magento2/issues/25038)
里面有解決方案
## 51,apache下403 Forbidden
> Forbidden
>
> You don't have permission to access /webfiles on this server. Server unable to read htaccess file, denying access to be safe
這是權限問題,需要給magento2根目錄755的權限
`sudo chmod 755 /var/www/magento2`
[https://stackoverflow.com/questions/27890751/magento-new-host-403-forbidden-server-unable-to-read-htaccess-file](https://stackoverflow.com/questions/27890751/magento-new-host-403-forbidden-server-unable-to-read-htaccess-file)
## 52,Magento\Framework\View\Page\Config\Renderer::canTypeBeFont() must be of the type string, null given
> PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to Ma
gento\Framework\View\Page\Config\Renderer::canTypeBeFont() must be of the type string, null given, called in /home/www/magento2/vendor/magento/framework/View/Page/Config/Renderer.php on line 347 and defined in /home/www/magento2/vendor/magento/framewor
k/View/Page/Config/Renderer.php:426
這是因為layout渲染html的時候發現沒有找到對應的css或者js文件。一般多發生于新安裝的插件。
需要deploy下。
## 53,Call to a member function getIsResizeEnabled() on null
> PHP message: PHP Fatal error: Uncaught Error: Call to a member function getIsResizeEnabled() on null in vendor/magento/module-backend/view/adminhtml/templates/media/uploader.phtml:16
這個在v2.3.x版本里會出現,是因為你安裝的某個插件有調用上傳圖片的類,少傳了一個參數。
你肯定首先要找到插件的代碼,一般類似這樣
```
$this->addChild('uploader', 'Magento\Backend\Block\Media\Uploader');
```
你改成
```
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$imageUploadConfigDataProvider = $_objectManager->get(\Magento\Backend\Block\DataProviders\ImageUploadConfig::class);
$this->addChild(
'uploader',
\Magento\Backend\Block\Media\Uploader::class,
['image_upload_config_data' => $imageUploadConfigDataProvider]
);
```
這樣就行了。
參考
[https://github.com/magento/magento2/issues/22394](https://github.com/magento/magento2/issues/22394)
- 序言
- 全面解讀Magento2
- Magento2簡介
- Magento2特點
- Magento2目錄結構
- Magento2語法講解
- 運行原理剖析
- 開啟Magento2之旅
- 安裝Magnto2
- 購買阿里云服務器(Ubuntu系統)
- 安裝和配置Nginx/PHP/PHP-FPM
- 配置Mysql并創建數據庫
- 配置Nginx虛擬主機
- 安裝和配置Magento2
- 導入演示數據
- 手把手教你創建git代碼庫
- 續外篇-購買AWS服務器
- 續外篇-Mac下安裝LNMP
- 續外篇-安裝phpmyadmin
- 如何升級php版本
- 使用Magento2
- 創建多網店多域名以及安裝中文語言包
- 創建獨立cms頁面
- 創建分類和產品
- 創建產品屬性
- 創建優惠券
- 導入產品csv
- 下單/發票/發貨/退貨
- M2常用命令
- 如何安裝主題
- 如何安裝插件
- 如何使用API
- 常見問題
- 常見問題 二
- 常見問題 三
- 常見問題 四
- 常見問題 五
- Magento2主題
- 主題框架詳解
- Layout文件詳解
- M2里的JS
- 主題實戰
- 前期準備工作
- 完成首頁
- 重寫分類頁面
- 錦囊妙計
- 產品詳情頁面講解
- 購物車頁面講解
- 支付頁面講解
- 主題修改記錄
- 關于主題的一些學員問答
- Magento2插件
- 插件框架詳解
- XML配置說明
- 插件實戰
- 準備工作
- 寫代碼
- 調試
- 難點解析
- 插件升級
- 插件修改記錄
- 擴展閱讀
- 如何創建cron任務和功能
- 發送郵件(帶附件)
- 如何在代碼里創建屬性
- Magento2線上部署
- 基本流程
- 配置Redis
- 配置Varnish+SSL
- Varnish配置教程(2020年修訂版)
- Paypal設置
- 一些優化
- Magento2 版本升級
- v2.3.0版本填坑指南
- v2.4.x升級指南
- 配置nginx pagespeed模塊進行加速
- M1數據庫遷移到M2指南
- 安裝配置Elasticsearch
- Magento2常用工具
- 網站測速分析工具
- 在線創建插件模塊
- M2后臺可視化編輯器里的標簽變量
- 遇到問題,我該怎么做
- 常用代碼
- SEO在線分析工具
- 本地用xdebug遠程調試mgtdev2服務器的項目
- 后續之路