0%

Magento 问题集

magento 2.3.2 + theme
lnmp 1.6
centos 7.2 + nginx + php 7.2.29 + mysql 5.7.29 + redis

nexcess 权限:

文件权限:find code -type f -exec chmod 0600 {} ;
文件夹权限:find code -type d -exec chmod 0711 {} ;

常用命令:

php bin/magento indexer:reindex 重建缓存
php bin/magento cache:clean && php bin/magento cache:flush 清除缓存
php bin/magento setup:static-content:deploy -f 编译资源
bin/magento deploy:mode:show 查看当前运行模式
bin/magento deploy:mode:set {mode} [-s|–skip-compilation] 设置运行模式
bin/magento deploy:mode:set default
bin/magento deploy:mode:set developer
bin/magento deploy:mode:set production
php bin/magento admin:user:unlock ADMINUSERNAME

问题一:

error 详细错误:
“There has been an error processing your request. Exception printing is disabled by default for security reasons.”
修改#app/bootstrap.php#

1
2
3
4
5
6
/**
* Environment initialization
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
$_SERVER['MAGE_MODE'] = 'developer';

问题二:

setup 403 错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
location /setup {
root $MAGE_ROOT;
location ~ ^/setup/index.php {

### This fixes the problem:
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
################################

fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ ^/setup/(?!pub/). {
deny all;
}

location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}

问题三:

In developer Magento mode Warning is shown on the Search Terms page:

Warning: natcasesort() expects parameter 1 to be array, null given in /var/www/html/deployer/instances/i-25245-2-3-develop/app/code/Magento/Search/Block/Term.php on line 102 [] []

文件位置不同:/home/wwwroot/www.test.develop/vendor/magento/module-search/Block/Term.php

1
2
3
4
+   $termKeys = []; //add
$this->_maxPopularity = reset($terms)->getPopularity();
$this->_minPopularity = end($terms)->getPopularity();
$range = $this->_maxPopularity - $this->_minPopularity;

问题四:

Consumer “async.operations.all” skipped as required connection “amqp” is not configured. Unknown connection name amqp

If you don’t want to use the Magento Message Queues, you can just disable it.

1
php bin/magento module:disable Magento_Amqp

If you want to use it, you might modify your app/etc/env.php

1
2
3
4
5
6
7
8
9
10
11
<?php
return [
// ...
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 1000,
'consumers' => [
'async.operations.all',
]
]
]; // return closing

问题五:

主题安装完后台缺少js文件,Magetique 2.2 主题

https://www.xxx.com/admin/filmslider/slider/
查看 pub/staic 文件夹为空,重新生成pub/static文件夹中的CSS文件

1
php bin/magento setup:static-content:deploy

问题六:

添加自定义js
在Magento 2添加自定义JS文件的步骤:
创建文件 /app/design/frontend/TemplateMonster/theme007/Magento_Theme/web/js/main.js,主题目录

1
2
3
4
5
6
7
8
9
define([
'jquery',
"jquery.countdown"
], function ($) {
'use strict';
$(function () {
alert("Page loaded.");
});
});

修改文件 /home/wwwroot/www.test.develop/app/design/frontend/TemplateMonster/theme007/Magento_Theme/requirejs-config.js:

1
2
3
4
5
6
7
8
var config = {
    paths: {
"main": 'js/main',
},
shim: {
'main': ['jquery']
},
};

控制台清空缓存,清空浏览器缓存。

执行命令:

1
2
php bin/magento cache:clean && php bin/magento cache:flush
php bin/magento setup:static-content:deploy -f

#本地安装2.3.2+theme 没有问题。在服务器 2.3.3 + theme 出现requirejs-config.js 已经包含自定义js文件并编译成功,但是没加载自定js文件。直接在theme.js文件添加js…
#解决方法:直接在theme自带的theme.js文件添加js…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// custom js start
// alert("page loaded!");
var $date = $("#clock").html();
var $current = new Date().;
var $old = new Date($date);
if($currentd1.getTime()>$old.getTime()){
$('#clock').countdown($date, function(event) {
$(this).html(event.strftime('%D days %H:%M:%S'));
});
}else{
$("#clock").css("display","none");
}

// custom js end

问题七:

产品比较 magento 2.3.3 点击compare不显示对比内容,bug 为处理,删除该功能

1
2
3
4
5
6
<!-- remove 20191129 -->
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true" />
<referenceBlock name="category.product.addto.compare" remove="true"/>
<referenceBlock name="view.addto.compare" remove="true" />
<referenceBlock name="view.addto.wishlist" remove="true" />

问题八:

当前激活的导航栏项目没有active 激活状态,只能激活一次就被缓存,只能关闭full page cache,但是会影响性能。magento 2.3.3 bug 未修复,暂时关闭该效果。

Magento\Theme\Block\Html\Topmenu::_getMenuItemClasses()
注释这几行:

1
2
3
4
5
// if ($item->getIsActive()) {
// $classes[] = 'active';
// } elseif ($item->getHasActive()) {
// $classes[] = 'has-active';
// }

问题九

遍历 referenceBlock的name属性 可以关闭部分magento 的不需要显示的功能模块。

/app/design/frontend/TemplateMonster/theme007/Magento_Theme/layout
关闭对比功能和愿望清单

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- remove 20191129 -->
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true" />
<referenceBlock name="category.product.addto.compare" remove="true"/>
<referenceBlock name="view.addto.compare" remove="true" />
<referenceBlock name="view.addto.wishlist" remove="true" />
<referenceBlock name="product.info.review" remove="true" />
<!-- Remove compare -->
<referenceBlock name="catalog.compare.link" remove="true" />
<referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
<referenceBlock name="crosssell.product.addto.compare" remove="true" />
<referenceBlock name="related.product.addto.compare" remove="true" />
<referenceBlock name="upsell.product.addto.compare" remove="true" />

问题10

更改product detail 里的 short description 位置:
修改文件:app\design\frontend\TemplateMonster\theme007\Magento_Catalog\layout\catalog_product_view.xml
修改 after=”product.info.price” 属性 after=”product.info.options.wrapper”,属性值可以用 referenceBlock的遍历程序遍历出的列表里查找。

1
<move element="product.info.overview" destination="product.info.main" after="product.info.options.wrapper"/>

问题11

在定义表格时,width(整个表格的宽度)不要设置为固定数值,定义为百分比类型,例如90%或者95%;再追加style=”table-layout:fixed;”,这样做可以使半角连续字符强制换行,不至于撑破列宽。需要注意的是,使用此参数后,不要轻易在tr(行)或td(列)中加入height属性,会使table不再被内容撑出适合的高度。

1
<table style="table-layout: fixed;" border="1" width="100%" cellspacing="0" cellpadding="2">

问题12

nexcess 主机迁移到本地做开发环境,注意mysql版本,nexcess 文件和文件夹权限。

Set Unsecure URL

1
bin/magento setup:store-config:set --base-url="http://www.magento2.com/"

Set Secure URL

1
bin/magento setup:store-config:set --base-url-secure="https://www.magento2.com/"

Clear Cache

1
bin/magento cache:flush

权限:

1
2
find /var/www/my_website -type d -exec chmod 0755 {} \;
find /var/www/my_website -type f -exec chmod 0644 {} \;

迁移后可能遇到:vendor\magento\framework\Encryption\Encryptor.php
加密方式问题,注释掉:

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Gets latest hash algorithm version.
*
* @return int
*/
public function getLatestHashVersion(): int
{
// if (extension_loaded('sodium') && defined('SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13')) {
// return self::HASH_VERSION_ARGON2ID13;
// }

return self::HASH_VERSION_SHA256;
}

创建新用户

1
php bin/magento admin:user:create

复制新用户密码给原有用户。