Magento2 常见错误 ----- 定期更新
1.静态文件有版本号,静态文件不能读取,页面无法显示。如下图:
解决方案:其实URL里的版本号对于magento来说是合法的,这是因为我们缺少了一个文件\pub\static\.htaccess;导致路由重写不能成功进行,或其 .htaccess 书写错误导致的;处理方法如下:
创建并写入.htaccess 文件到pub/static:
#正则路由
RewriteRule ^version.+?/(.+)$ $1 [L]
#重定向目录
##==========
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l RewriteRule .* ../static.php?resource=$0 [L]
2,安装分销插件 Amasty_Affiliate 报错如下:
Notice: Undefined index: id in /home/staging/vendor/magento/module-config/Model/Config/Structure/Element/Iterator.php on line xx
---------------
问题是因为我在system.xml中有不正确的标签ID匹配。
参考下方语法:<tab>customtab</tab>
#改为
<tab>custom_tab</tab>我通过添加定义如下:解决问题
<tab id="amasty_affiliate" translate="label" sortOrder="2000">
<label>Amasty Affiliate</label>
</tab>
<tab>amasty_affiliate</tab>
3,%7B%7BMEDIA_URL%7D%7D 解码:{{MEDIA_URL}} 错误连接问题。
问题如下:
解决方案:
CONTENT > Design > Configuration > Edit > HTML Head,<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" /> 修改: <link rel="stylesheet" type="text/css" media="all" href="/pub/media/styles.css" />
4.报错: (Magento\Framework\Exception\LocalizedException): Invalid Document Element 'add', attribute 'title':
1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid Document
Element 'add', attribute 'title':解决方案 :通常这种错误表示代码中的XML文件无效;只需要修复它们以与XSD相关联。
5.重建索引错误
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5580-299-10-137-5580' for key 'PRIMARY', query was: INSERT INTO `catalog_product_index_eav_temp` (`entity_id`,`attribute_id`,`store_id`,`value`,`source_id`) VALUES (?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?
解决方案:
查询记录》找到 value_id 清除;
查询
SELECT * FROM catalog_product_entity_varchar where attribute_id = 299 and entity_id = 5580;
结果:删除:delete FROM catalog_product_entity_varchar where value_id = 58753;
6. 解决 - 前端requireJs 引入外部有依赖Jquery的 modal 插件
require(["jquery"],function($){
/**
* body add class
*/
$("body").addClass('page-measurements');
require(
["jquery",'Mc_Size/plugins/jquery.modal.min'],
function ($,modal) {
//。。。。。
})})
7.解决Setup:Upgrade 更新数据表不成功。
在更新了UpdateSchema.php后,修改Module.xml 的版本后。再执行 php bin/magento setup:upgrade 命令时,发生数据库没有更新的问题。
解决问题的原理是:UpdateSchema.php 代码里 有写数据库表存在时,不创建表。所以不能被更新 。
解决办法:一是修改 UpdateSchema.php 代码,让更新时如愿以偿(具体请看相关的语法。)。二是删除表后,修改版本号了,再执行更新命令 (简单粗暴).。
8.php bin/magento setup:static-content:deploy -f 生成静态不成功。
/../vendor/magento/framework/Filesystem/Directory/Read.php(210): Megento\Framework\Filesystem\Driver\File->fileGetContents('/...',NULL,NULL);
问题原因: Zip文件无法读取;
经过命令:
php bin/magento setup:static-content:deploy -f -vvv打印详细过程,找到对应目录;修复某些模块的差异文件。
问题得到解决。
9.错误 :There has been an error processing your request Exception printing is disabled by default for security reasons.

- 解决:
- 首先找出文件位置: find 指定目录 -name 错误号
- 按对应报错解决即可。(如何需要内容查找参考: grep -r 查询内容 指定目录)
10. 大部分后台的配置 为操作数据表 core_config_data 内。当发现在后台更改配置不成功时,更改Store view 即可解决。
Store view 位置为:Stores->settings->Configuration->左上角下拉菜单;
#注意:如果没有 “Stores->settings->Configuration->左上角下拉菜单” ;则在Stores->settings->Configuration->General->Enable Single-Store Mode=No;即可;
10. 在订单 View 里的商品列表。当我们要修改订单列表的商品时,会遇到如如下代码:
-1.1 , $block->getItemHtml($item); ( \Magento\Sales\Block\Items\AbstractItems ) ;
-1.1.1 ,方法调用 getItemRenderer 获取别名为 renderer.list 的子Block;
/** @var \Magento\Framework\View\Element\RendererList $rendererList */
$rendererList = $this->getRendererListName() ? $this->getLayout()->getBlock(
$this->getRendererListName()
) : $this->getChildBlock(
'renderer.list'
);
-1.1.1.1 ,子block定义如下:
<block class="Magento\Framework\View\Element\RendererList" name="sales.order.items.renderers" as="renderer.list"/>
- 1.1.1.1.1 , getItemRenderer 调用了 $renderer = $rendererList->getRenderer($type, self::DEFAULT_TYPE, $template);
类 Magento\Framework\View\Element\RendererList 继承自 所有块的基类( abstract class AbstractBlock )。RendererList 使用了 setTemplate 设置了模板;
结果:产品的.PHTML 在sales_order_item_renderers.xml.XML 里。
11, 如何启用或禁用静态内容签名?
1, Stores» → «Configuration» 3 → «Advanced» → «Developer» → «Static Files Settings» → «Sign Static Files 设置为YES\NO;
2, 更新 core_config_data 数据表的PATH = "dev/static/sign" 设置value为0\1 。删除缓存更新后完成。
12.根据产品ID查询对应标题:
$_connection = $this->mc_get_obj(\Magento\Framework\App\ResourceConnection::class);//get class
$db_connection = $_connection->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);//connection
$category = $db_connection->fetchAll('select * from '.'`catalog_product_entity_varchar` '.'left join '.'`eav_attribute` '.'on '.
'`eav_attribute`.'.'`attribute_id`='.'`catalog_product_entity_varchar`.'.'`attribute_id` '.
'where '.'`eav_attribute`.'.'`attribute_code`='.'"name" '.'and '. '`catalog_product_entity_varchar`.'.'`entity_id`='.$vi['product_id']);
var_dump($category[0]['value']);die;
13.找不到magento 2 block 的 template 属性:如:<block class="Amasty\Affiliate\Block\Account\Setting" name="amasty_affiliate.account.setting" cacheable="false"></block>;真实目录以编程方式获取为:app/code/Amasty/Affiliate/view/frontend/templates/account/setting.phtml
14,magento 2 开启打印全部数据库查询日志:
以 app/etc/di.xml
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Quiet"/> # 替换如下:(无Quiet 类直接添加即可;) <!--#fixme Add xu-->
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
<type name="Magento\Framework\DB\Logger\File">
<arguments>
<argument name="logAllQueries" xsi:type="boolean">true</argument>
</arguments>
</type>
<!--end xu-->
15, 切换数据库后,后台无法登陆( ERR_TOO_MANY_REDIRECTS );其中原因是cookie数据库缓存;使用数据库查询:select * from core_config_data where path like 'web/cookie%'; 查看其中的 web/cookie/cookie_domain 的 value 为更改后的域名“.m223:8890”(magento 2.2.3前面需要加个点)。
bin/magento config:set web/cookie/cookie_domain xxxx.com。
16,切换数据库后,如主题已经不再用提示错误:Required parameter 'theme_dir' was not passed 。
a,转到 theme 表,然后删除创建的主题的条目。
b,转到您的core_config_data表并搜索 theme ,您将获得路径记录,把 design/theme/theme_id,替换其中的 theme 表主题ID。
17,MAGENTO 2主题不显示在前端时该怎么办?( 如:切换数据库后,拷贝主题代码后; )
a, 第一步:检测主题 是/否 添加 “Theme” 表中;
b, 第二步:找到该行,更新该列 Type 属性从 1 改为 0;c, 第三步:php bin/magento setup:upgrade --keep-generated && php bin/magento setup:static-content:deploy -f && php bin/magento cache:clean && php bin/magento cache:flush
18,无法将产品添加到购物车 这个问题比较复杂,我在谷歌浏览器问题存在。切换Safari 浏览器 加入购物车正常;
19, 更换SSL,无论你是从HTTP切换为HTTPS,或是HTTPS切换到HTTP;当网站可以访问,无论如何清理缴存&重建索引,静态内容的加载连接始终是相反的HTTP协议时。请检查数据 core_config_data 表,path 使用前端的网络安全 (web/secure/use_in_frontend) 的值是否为 0(关闭HTTPS)或 1 (开启HTTPS) ;试着修改它,然后更新缓存。 我通过这个办法修复了; 执行命令(bin/magento config:set web/secure/use_in_frontend 0|1);常见SSL问题
20, Unknown or bad timezone (时区未知或错误):删除core_config_data 表 path 列为 general 为 Null 的行; 我在 magento.stackexchange.com 有正确回答。
21,当发生不可以加入购物车时,尝试一下是否可以用于登录; 都不可以?那么试过用了很长的时间寻找问题是什么?最后解决的办法是使用ip地址作为域名是可以了。这并不算一个解决办法,但是也记录一下;
22,【非一定要解决】 Unable to send the cookie. Maximum number of cookies would be exceeded. 无法发送Cookie。将超过Cookie的最大数量; 参考。
23, Warning: SessionHandler::read(): Unable to clear session lock record in ..vendor/magento/framework/Session/SaveHandler/Native.php on line 22
Session Handler 处理查看函数无法工作;最好的解决办法是配置redis;
24,使用 Cpanel 安装Mangento2 时,php版本已经修改为正确的版本,但仍然不能composer install。 原因是ocmposer 默认了php的版本。
解决办法:
重新下载 composer.phar : wget https://getcomposer.org/download/1.9.0/composer.phar ; 下载完成以后执行 php <path>/composer.phar install .
25,-------
——————
======== 注意事项
- 当要 替换xml <block> 的 class 和 template 时,使用 referenceBlock + DI class 映射即可;应用于2.2.x以上;
<referenceBlock name="checkout.cart.form" template="包_模块::cart/form.phtml" />
- -
Magento2 常见错误 ----- 定期更新的更多相关文章
- SVN中的常见错误(长期更新)
一 svn中的简写含义. A:add,新增 C:conflict,冲突 D:delete,删除 M:modify,本地已经修改 G:modify and merGed,本地文件修改并且和服务器的进行合 ...
- CPP相关的常见错误(更新ing)
01.只允许在C99模式下使用 for 循环初始化申明 解决:指定下即可 gcc -o xxx -std=c99 02.
- Python:常见错误集锦(持续更新ing)
初学Python,很容易与各种错误不断的遭遇.通过集锦,可以快速的找到错误的原因和解决方法. 1.IndentationError:expected an indented block 说明此处需要缩 ...
- python的多版本安装以及常见错误(长期更新)
(此文长期更新)Python安装常见错误汇总 注:本教程以python3.6为基准 既然是总结安装过程中遇到的错误,就顺便记录一下我的安装过程好了. 先来列举一下安装python3.6过程中可能需要的 ...
- 修复 Elasticsearch 集群的常见错误和问题
文章转载自:https://mp.weixin.qq.com/s/8nWV5b8bJyTLqSv62JdcAw 第一篇:Elasticsearch 磁盘使用率超过警戒水位线 从磁盘常见错误说下去 当客 ...
- 初识JAVA(二)(送给Java和安卓初学者)----常见错误
博主接着上篇的来讲哦,以后的更新中,博主会出一些练习题,有兴趣的可以做做然后吧代码粘贴到下面,大家可以一起研究学习,一起进步,本篇文章主要讲的是: 一.常见错误 二.连接上篇一起的训练 无论是什么方向 ...
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock 通过终端安装程序sudo apt-get install xxx时出错:E: Could not ...
- 【ubuntu 】常见错误--Could not get lock /var/lib/dpkg/lock
ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock 通过终端安装程序sudo apt-get install xxx时出错: E: Could not ...
- SVN常见错误和版本冲突解决
之前在Eclipse下面误删除了svn的一些插件包,后来重装了就问题重重,在这里还是建议, Windows下SVN最好使用桌面版,在文件管理器下面更新和提交. 1.常见错误整理 #, c-format ...
随机推荐
- arcgis api 3.x for js 入门开发系列六地图分屏对比(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
- c或c++利用scanf无限输入并进行简单操作如比大小等
#include <iostream> using namespace std; int main() { ; ) //scanf返回值为int类型表示成功输入的数据数量个数 { if(n ...
- c/c++ llinux epoll系列5 解除epoll_wait状态
linux epoll系列5 解除epoll_wait状态 有时候会有解除epoll_wait状态的需求. 实现方法: 1,给执行epoll_wait的程序发signal. 2,使用sockpair. ...
- Linux 下 C# Mono P/Invoke .so 动态链接库。
linux 的动态链接库 libgw.so 的函数 如下: struct lbt_chan { uint32_t freq_hz; uint16_t scan_time_us; }; struct l ...
- Checkpoint 和Breakpoint
参考:http://www.cnblogs.com/qiangshu/p/5241699.htmlhttp://www.cnblogs.com/biwork/p/3366724.html 1. Che ...
- python import详解
1.import作用 引入模块 2.import的特点 一个程序中,import的模块不会重复被引用,如: # test1.py import test2 print test2.attr # tes ...
- PostgreSQL:Java使用CopyManager实现客户端文件COPY导入
在MySQL中,可以使用LOAD DATA INFILE和LOAD DATA LOCAL INFILE两种方式导入文本文件中的数据到数据库表中,速度非常快.其中LOAD DATA INFILE使用的文 ...
- MySQL之记录相关操作
一 介绍 MySQL数据操作: DML ======================================================== 在MySQL管理软件中,可以通过SQL语句中的 ...
- 返回数组中指定的一列,将键值作为元素键名array_column
array_column() 函数 从记录集中取出 last_name 列: <?php // 表示由数据库返回的可能记录集的数组 $a = array( array( 'id' => 5 ...
- 通过Excel生成PowerDesigner表结构设计
说明:近期做部分表结构设计,在word里设计调整好了,需要整理到PowerDesigner中,但是手工录入太麻烦. 找了个工具(地址:http://www.cnblogs.com/hwaggLee/p ...


