# 常见问题 四 ## 54,'Vertex\\Tax\\Model\\Flexfield\\Processor\\InvoiceFlexFieldProcessorInterface' not found > PHP Fatal error: Interface 'Vertex\Tax\Model\Flexfield\Processor\InvoiceFlexFieldProcessorInterface' not found in vendor/vertex/module-tax/Model/FlexField/Processor/OrderCurrencyGetterProcessor.php on line 24 这是2.3.3的一个bug, [https://github.com/magento/magento2/issues/24930](https://github.com/magento/magento2/issues/24930) 解决办法: 打开 `/vendor/vertex/module-tax/Model/FlexField/Processor/OrderCurrencyGetterProcessor.php` 添加2个`use` ``` use Vertex\Tax\Model\FlexField\Processor\InvoiceFlexFieldProcessorInterface; use Vertex\Tax\Model\FlexField\Processor\TaxCalculationFlexFieldProcessorInterface; ``` ## 55,Invalid Form Key. Please refresh the page 后台产品保存的时候报错 `Invalid Form Key. Please refresh the page` 这是产品编辑页面的表单数据太大了,或者说是上传的产品图片太大了,超出了php限制。需要改下php.ini 找到 `max_input_vars`,改成: ``` max_input_vars 10000 ``` ## 56,Call to a member function getOptionsJson() on null in vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml:46 在2.3.3及以上版本会出现这种错误,是因为你的主题有重写gallery.phtml,缺少参数,需要加进去。 解决办法: ``` grep -irn 'View.Gallery' app/design ``` 找到catalog_product_view.xml文件里的 ``` <block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="product/view/gallery.phtml"> ``` 类似这样的代码,改成 ``` <block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="product/view/gallery.phtml"> <arguments> <argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument> </arguments> </block> ``` 也就是把 ``` <arguments> <argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument> </arguments> ``` 加进去就行了。 参考: [https://github.com/magento/magento2/issues/23432](https://github.com/magento/magento2/issues/23432) ## 57,禁用Temando_Shipping插件后 后台产品编辑页面打开报错 Uncaught Error: Cannot instantiate interface Temando\Shipping\Model\ResourceModel\Repository\PackagingR epositoryInterface in /var/www/magento2demo.com/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50 **解决办法:** 把产品属性source_model含有Temando相关的属性删掉 ``` DELETE FROM `eav_attribute` WHERE `source_model` LIKE '%Temando%' ``` 再编译清缓存 ``` php bin/magento setup:di:compile rm -rf var/cache/* var/page_cache/* generated/code/* ``` ## 58, Notice: Undefined offset: 2 in vendor/magento/framework/Encryption/Encryptor.php on line 591 在php7.2以上 / m2 2.3.3及以上版本会出现这问题。 解决办法有2种, 1),重新创建admin user 比如创建新用户test ``` php bin/magento admin:user:create --admin-user test --admin-password test123456 --admin-email =zouhongzhao@126.com --admin-firstname test --admin-lastname test ``` 2),安装php sodium扩展 具体的google ## 59,DateTimeZone::__construct(): Unknown or bad timezone () ~~~ 1 exception(s): Exception #0 (Exception): DateTimeZone::__construct(): Unknown or bad timezone () ~~~ 这应该是主题或者插件因为某种特殊原因在core_config_data表里创建了个value为null的记录,比如 ~~~ select * FROM `core_config_data` WHERE path = 'general' ~~~ 有`general`这条记录的话,就删掉试试 ~~~ DELETE FROM `core_config_data` WHERE path = 'general' ~~~ 然后 再刷新页面测试下看是不好了。 参考:[https://magento.stackexchange.com/questions/135188/my-magento-2-website-is-crashed-unknown-or-bad-timezone-error](https://magento.stackexchange.com/questions/135188/my-magento-2-website-is-crashed-unknown-or-bad-timezone-error) ## 60,PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice) 具有相同ID的发票多次发送到PayPal时,会发生此问题。 也就是说你在支付页面 反复点paypal 但是又不付款的话 就会出现这问题。 在多个Magento站点(甚至在本地和暂存环境中)使用相同的凭据时,可能会发生这种情况。特殊情况可能如下: * 多家商店将发票提交到PayPal,并使用相同的发票ID * 新商店会发送带有旧商店先前提交的ID的发票 默认情况下,PayPal不允许两次处理同一张发票。 解决办法: 更改您的PayPal个人资料,以允许每个发票ID进行多次付款。您需要通过PayPal进行这些更改。 1. 通过[https://www.paypal.com](https://www.paypal.com/)登录到您的帐户 。 2. 单击**配置文件**\>**配置文件和设置 **(右上角)。 3. 转到**我的销售工具**。 4. 导航到“ **收款并管理我的风险”**\>“**阻止付款”**,然后单击“**更新”**。 5. **在“销售首选项”中**,单击“ **付款接收首选项”**。 6. 在 **阻止意外付款下**,选择 **否,每个发票ID允许多次付款**。 ![paypal_allow_multiple_payments_per_invoice_id.png](https://support.magento.com/hc/article_attachments/115003047154/paypal_allow_multiple_payments_per_invoice_id.png) 7. 滚动到底部,然后单击 **保存**。 见: [https://support.magento.com/hc/en-us/articles/115002457473-PayPal-gateway-rejected-request-duplicate-invoice-issue](https://support.magento.com/hc/en-us/articles/115002457473-PayPal-gateway-rejected-request-duplicate-invoice-issue) ## 61, Elasticsearch: Types cannot be provided in put mapping requests, unless the include\_type\_name parameter is set to true. 执行reindex或者bin/magento indexer:reindex catalogsearch_fulltext后,报错: > Catalog Search indexer process unknown error: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."}],"type":"illegal_argument_exception","reason":"Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true."},"status":400} 这是因为你的m2版本低于2.3.5,并且安装的Elasticsearch服务端版本是7.x的,导致兼容性有问题,因为m2 2.3.5以下版本只支持es 5.x和6.x,不支持7.x。 解决办法有2种: 第1种:升级m2到最新的2.3.5版本 第2种:不升级m2,直接修改源码,修改 `vendor/magento/module-elasticsearch-6/Model/Client/Elasticsearch.php` 在大约252行的位置,addFieldsMapping这个function里,在$params数组里添加一行 `'include_type_name' => true,` 类似这样 ``` public function addFieldsMapping(array $fields, $index, $entityType) { $params = [ 'index' => $index, 'type' => $entityType, 'include_type_name' => true, .... ``` ## 62,upstream sent too big header while reading response header from upstream nginx报错 `upstream sent too big header while reading response header from upstream` **解决办法:** 在M2的`vhost`里,找到`location ~ (index|get|static|report|404|503|health_check`这一行,在里面添加: ``` fastcgi_buffers 1024 4k; fastcgi_buffer_size 128k; ``` 类似这样 ``` # PHP entry point for main application location ~ (index|get|static|report|404|503|health_check|test|dafo_importer|_intellij_phpdebug_validator)\.php$ { .... fastcgi_buffers 1024 4k; fastcgi_buffer_size 128k; .... } ``` ## 63,2.3.5以上版本报错 Nginx: 502 Bad Gateway > upstream sent too big header while reading response header from upstream. 这是网站响应头headers太大了(2.3.5/2.4.0一般是4k-5k左右),超出了nginx的限制,需要改下nginx的配置。 添加 ``` fastcgi_buffers 1024 16k; fastcgi_buffer_size 32k; ``` 比如 ``` location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ { ... fastcgi_buffers 1024 16k; fastcgi_buffer_size 32k; ... } ``` 如果用了反向代理的话 还得这样加 ``` proxy_buffers 4 16k; proxy_buffer_size 16k; ``` 比如 ``` server { listen 443 ssl http2; server_name magento2.texiaoyao.cn; # reverse proxy location / { proxy_buffers 4 16k; proxy_buffer_size 16k; .... } } ``` ## 64, You need to configure Two-Factor Authorization in order to proceed to your store's admin area 2.4.x版本为了安全,后台登录提示要加这个验证,如果不想用的话可以禁用这个模块。 ``` bin/magento module:disable Magento_TwoFactorAuth --clear-static-content ``` https://magento.stackexchange.com/questions/318485/you-need-to-configure-two-factor-authorization-in-order-to-proceed ## 65, select-payment-method-mixin.min.js:1 Uncaught TypeError: Cannot read property 'method' of null 在2.3.5里未登录下单,用free支付方式,有这个报错。 是个M2的bug, 2.4里修复了。 [https://github.com/magento/magento2/issues/28161](https://github.com/magento/magento2/issues/28161) **目前的解决办法:** 在主题里重写 select-payment-method-mixin.js 比如 app/design/frontend/Vender/Theme/Magento\_SalesRule/web/js/action/select-payment-method-mixin.js 在第22行前面添加 ``` if (paymentMethod === null) { return; } ``` ## 66,Unexpected token $ in JSON at position 308 注册页面或者支付页面,启用region id的话 不显示 有js报错。 ``` { "#country": { "regionUpdater": { "optionalRegionAllowed": true, "regionListId": "#region_id", "regionInputId": "#region", "postcodeId": "#zip", "form": "#form-validate", "regionJson": {$regionJson}, "defaultRegion": "{$regionId}", "countriesWithOptionalZip": {$countriesWithOptionalZip} } } } ``` 是m2的bug 还未解决。 https://github.com/magento/magento2/issues/30099 ## 67,An error has happened during application run. See exception log for details. Could not write error message to log. Please use developer mode to see the message. 在production(生产)模式下会遇到这种错误,想看到具体的报错 但又说无法写入log,明明是有权限的,给权限了也不行。 这种需要调试下代码,输出具体的报错。 具体的代码在`vendor/magento/framework/App/Bootstrap.php`的#429行的`terminate`方法里,我们加个调试语句: ``` protected function terminate(\Throwable $e) { if ($this->isDeveloperMode()) { echo $e; } else { //在这里加入调试语句 echo $e->getMessage();die; $message = "An error has happened during application run. See exception log for details.\n"; .... ``` 再刷新下页面,就会得到具体的报错,比如我的是: > The website with code base that was requested wasn't found. Verify the website and try again. 说明是nginx配置问题,没有找到默认的website code,需要指定个`$MAGE_RUN_CODE`。 比如默认的website code是`base`,我们自己有改成`base2`了,那么就需要手动指定下: ``` map $http_host $MAGE_RUN_CODE { default base; you-domain.con base2; } ``` 改后重启下nginx就好了。 ## 68,后台批量更新产品属性后,显示一直挂起,Pending, in queue 1. In Admin navigate to Catalog -> Products page. 2. Select all products. 3. In drop-down 'Actions' menu select "Update attributes" 4. Change desired value of any attribute (like description) and save. ![](https://img.kancloud.cn/b1/0d/b10d8ac41e9e0b7028a096b7bc42b6d7_576x206.png) 这是m2的bug。2.4.2里有修复。 https://github.com/magento/magento2/issues/29797 **临时解决办法参考:** https://github.com/magento/magento2/pull/29814 修改app/code/Magento/AsynchronousOperations/etc/db_schema.xml,把 ``` <column xsi:type="int" name="operation_key" padding="10" unsigned="true" nullable="false" ``` 改成 ``` <column xsi:type="int" name="operation_key" padding="10" unsigned="true" nullable="true" ``` ## 69,Something went wrong with processing the default view and we have restored the filter to its original state 后台产品列表页面,点击id排序或者搜索的时候,会报错 > Attention Something went wrong. > Something went wrong with processing the default view and we have restored the filter to its original state. **这是因为有些产品的sku为`Null`导致的,改成空就好了。** 先检查下有哪些产品sku为`Null`, ``` SELECT * FROM `catalog_product_entity` WHERE `sku` IS NULL ``` 再进行修改 ``` UPDATE catalog_product_entity SET sku='' WHERE sku IS NULL ```