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.-------

======== 注意事项

  1. 当要 替换xml <block> 的 class 和 template 时,使用 referenceBlock + DI class 映射即可;应用于2.2.x以上; 
      <referenceBlock name="checkout.cart.form" template="包_模块::cart/form.phtml" />

     

  2. -

转载于:https://www.cnblogs.com/q1104460935/p/m2.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值