# 常见问题 四 ## 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 ``` ## 70,Please enter a valid date 2.3.5-p1里用户注册页面开启显示`dob`(生日)后,选择不了,总是报错Please enter a valid date 这是2.3.5的bug,升级到2.3.6即可解决。 如果你不想升级,直接改源码可以这样改: https://github.com/chandu-pinpoint/magento2/blob/d3f8e5407403f78f3b09fe5af3e7a9222d19ba39/Customer-Registraion-Dob-validation-fix.patch 参考: https://github.com/magento/magento2/issues/28482 ## 71,升级到`2.4.2-p1`后,会覆盖`.gitignore`文件 升级到`2.4.2-p1`后,`composer install`会自动覆盖`.gitignore`文件,导致`git`同步到线上会出现数据丢失的情况。 这是`2.4.2-p1`的bug。 https://github.com/magento/magento2/issues/32888 暂时的解决办法就是修改`composer.json`,添加下面几行: ``` "extra": { "magento-force": "override", "magento-deploy-ignore": { "*": [ "/.gitignore" ] } } ``` ## 72,inventory_stock_1 doest exist ``` Product Price index exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'inventory_stock_1' doesn't exist, query was: INSERT INTO `catalog_product_index_price_cfg_opt_temp` SELECT `le`.`entity_id`, `i`.`customer_group_id`, `i`.`website_id`, MIN(final_price), MAX(final_price), MIN(tier_price) FROM `catalog_product_index_price_replica` AS `i` ``` 需要手动创建下 ``` CREATE OR REPLACE VIEW `inventory_stock_1` AS select distinct `legacy_stock_status`.`product_id` AS `product_id`, `legacy_stock_status`.`website_id` AS `website_id`, `legacy_stock_status`.`stock_id` AS `stock_id`, `legacy_stock_status`.`qty` AS `quantity`, `legacy_stock_status`.`stock_status` AS `is_salable`, `product`.`sku` AS `sku` from ( `cataloginventory_stock_status` `legacy_stock_status` join `catalog_product_entity` `product` on (( `legacy_stock_status`.`product_id` = `product`.`entity_id` ))); ``` ## 73, Circular dependency 从2.4.2-p1升级到2.4.3的时候,有这种报错 > PHP Fatal error: Uncaught LogicException: Circular dependency: customRemoteFilesystem depends on Magento\RemoteStorage\Driver\Cache\CacheFactory and vice versa. in /var/www/www.xxx.com/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:55 一般是redis的问题,需要刷新下redis ``` redis-cli FLUSHALL ``` ## 74,禁用Page Builder 2.4.3版本自动开启了`Page Builder`功能,但是会与以前的html内容冲突,导致不好用,可以手动关掉这个功能。 ![](https://img.kancloud.cn/07/87/0787ed5a6768fb9585729d3e4c8c4afe_1108x651.png) https://devdocs.magento.com/page-builder/docs/administration/deactivate-pagebuilder.html ## 75,Constant name is expected 在命令行deploy的时候会有这个报错 ``` Constant name is expected ``` 这是你的XML文件语法有问题,需要检查下你的插件。 主要是插件/etc下面的xml文件。是不是加载的类不存在或者插件名没写对。 如果还检查不出来的话,就需要自己debug下。 可以调试 `vendor/magento/framework/Data/Argument/Interpreter/Constant.php `这个类。 把 ``` public function evaluate(array $data) { if(!isset($data['value']) || !defined($data['value'])) { throw new \InvalidArgumentException('Constant name is expected.'); } return constant($data['value']); } ``` 改成 ``` public function evaluate(array $data) { if(!isset($data['value']) || !defined($data['value'])) { print_r($data);exit; // <<<<<<<<<<<< throw new \InvalidArgumentException('Constant name is expected.'); } return constant($data['value']); } ``` 再执行deploy命令后,就会有提示具体哪个文件有问题。 **改完后 记得还原Constant.php文件。** ## 76,Fatal error: During inheritance of Countable `2.4.3-p1`升级到`2.4.4`后报这个错误。 这一般是composer.json文件的问题,需要把composer.json里的`require-dev`部分替换成下面的: ``` "require-dev": { "allure-framework/allure-phpunit": "~1.5.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "friendsofphp/php-cs-fixer": "~3.3.0", "lusitanian/oauth": "~0.8.10", "magento/magento-coding-standard": "*", "magento/magento2-functional-testing-framework": "^3.7", "pdepend/pdepend": "~2.10.0", "phpmd/phpmd": "^2.9.1", "phpstan/phpstan": "~1.2.0", "phpunit/phpunit": "~9.5.0", "sebastian/phpcpd": "^6.0.3", "squizlabs/php_codesniffer": "~3.6.0", "symfony/finder": "^5.2" }, ``` 参考: https://github.com/magento/magento2/issues/35306 https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/implementation/perform-upgrade.html ## 77,The requested store cannot be found. Please check the request and try again 2.4.x里前台页面切换store url后,会报错 ``` The requested store cannot be found. Please check the request and try again ``` 这是个m2的bug, [https://github.com/magento/magento2/issues/33042](https://github.com/magento/magento2/issues/33042) **解决办法:** 需要把 `vendor/module-store/Model/StoreSwitcher/RedirectDataValidator.php`这个文件里的: ``` const TIMEOUT = 5; ``` 改成 ``` const TIMEOUT = 10; ``` ## 78,(Magento\Framework\Exception\NoSuchEntityException): Invalid customer address id 加入购物车/checkout页面报错,客户地址不对。 这应该是数据库导入导出后触发的一个bug。可能是改了数据库后 网站前台客户没有退出登录。导致这个quote的customer为guest。 去数据库里执行 ``` SELECT entity_id, customer_id FROM quote WHERE customer_id != 0 AND customer_is_guest = 1; ``` 找出`customer_id`不为0,但是`customer_is_guest`=1的记录出来。然后把这个记录的`customer_is_guest`改成0就行了。 参考 https://github.com/magento/magento2/issues/23618 ## 79, rtrim() expects parameter 1 to be string, bool given vendor/magento/framework/Encryption/Adapter/Mcrypt.php(171): rtrim() 升级到`2.4.3-p2`/`2.4.3-p3`后 登录会报错 > # rtrim() expects parameter 1 to be string, bool given vendor/magento/framework/Encryption/Adapter/Mcrypt.php(171): rtrim() 解决办法: 安装`mcrypt`模块 `apt install php7.4-mcrypt`