• Magento2 常见错误 ----- 定期更新


    1.静态文件有版本号,静态文件不能读取,页面无法显示。如下图:

    解决方案:其实URL里的版本号对于magento来说是合法的,这是因为我们缺少了一个文件pubstatic.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.报错: (MagentoFrameworkExceptionLocalizedException): Invalid Document Element 'add', attribute 'title': 

    1 exception(s):
    Exception #0 (MagentoFrameworkExceptionLocalizedException): 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): MegentoFrameworkFilesystemDriverFile->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); ( MagentoSalesBlockItemsAbstractItems ) ;     

        -1.1.1 ,方法调用 getItemRenderer 获取别名为 renderer.list 的子Block;

       /** @var MagentoFrameworkViewElementRendererList $rendererList */
            $rendererList = $this->getRendererListName() ? $this->getLayout()->getBlock(
                $this->getRendererListName()
            ) : $this->getChildBlock(
                'renderer.list'
            );

          -1.1.1.1 ,子block定义如下:

     <block class="MagentoFrameworkViewElementRendererList" name="sales.order.items.renderers" as="renderer.list"/>

            - 1.1.1.1.1 , getItemRenderer 调用了  $renderer = $rendererList->getRenderer($type, self::DEFAULT_TYPE, $template); 

      类 MagentoFrameworkViewElementRendererList 继承自 所有块的基类( 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 设置为YESNO;

      2, 更新 core_config_data 数据表的PATH = "dev/static/sign" 设置value为01 。删除缓存更新后完成。

    12.根据产品ID查询对应标题:

      
                $_connection = $this->mc_get_obj(MagentoFrameworkAppResourceConnection::class);//get class
                $db_connection = $_connection->getConnection(MagentoFrameworkAppResourceConnection::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="AmastyAffiliateBlockAccountSetting" 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="MagentoFrameworkDBLoggerInterface" type="MagentoFrameworkDBLoggerQuiet"/>
    
    # 替换如下:(无Quiet 类直接添加即可;)
    
       <!--#fixme Add xu-->
        <preference for="MagentoFrameworkDBLoggerInterface" type="MagentoFrameworkDBLoggerFile"/>
        <type name="MagentoFrameworkDBLoggerFile">
            <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,Magento admin 报重复重定向 ERR_TOO_MANY_REDIRECTS

    在“ core_config_data”表中,删除“ web/cookie/cookie_domain”的值,并将“ web/cookie/cookie_httponly”设置为“ 0”。通过删除“ var/cache”中的文件来清除缓存。

    26,-------

    ——————

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

    1. 当要 替换xml <block> 的 class 和 template 时,使用 referenceBlock + DI class 映射即可;应用于2.2.x以上; 
        <referenceBlock name="checkout.cart.form" template="包_模块::cart/form.phtml" />
    2. -
  • 相关阅读:
    运输计划[二分答案 LCA 树上差分]
    树的重心与树的直径
    约瑟夫问题
    [The 2019 Asia Yinchuan First Round Online Programming] D Take Your Seat
    CF858F Wizard's Tour
    当那一天来临
    NOI2000 青蛙过河[递推]
    BZOJ4305 数列的GCD
    中国剩余定理和扩展中国剩余定理
    重写select
  • 原文地址:https://www.cnblogs.com/q1104460935/p/m2.html
Copyright © 2020-2023  润新知