# 常见问题 三 ## 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图片,不能保存 ![](https://box.kancloud.cn/c95a29d41429ef0920b15837306bc84b_1640x550.png) 这是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/helakauppa.mgtdev2.iggo.f i/vendor/magento/framework/View/Page/Config/Renderer.php on line 347 and defined in /home/www/helakauppa.mgtdev2.iggo.fi/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)