Magento缓存操作命令

后台缓存操作

后台菜单 system > tools > Cache Management 可以直接管理magento的缓存

查看Magento的缓存状态

$ bin/magento cache:status
Current status:
                        config: 1
                        layout: 1
                    block_html: 1
                   collections: 1
                    reflection: 1
                        db_ddl: 1
               compiled_config: 1
                           eav: 1
         customer_notification: 1
            config_integration: 1
        config_integration_api: 1
                     full_page: 1
             config_webservice: 1
                     translate: 1
                        vertex: 1

上面列出了当前magento系统里全部的缓存类型和对应的状态, 0关闭/1开启

阅读详情

初识Magento2.3的GraphQl API

Magento2.3开始,Magento全面引入GraphQl构建API

什么是 GraphQl

本文假设已经了解了GraphQl.

网上描述最多的是一种用于 API 的查询语言

简单提取了如下特点:
– 语法易于理解
– 准确获取数据
– 数据没有冗余
– 能应对业务变化
– 减少API请求次数

Magento2.3增加的GraphQl相关模块

BundleGraphQl
CatalogGraphQl
CatalogInventoryGraphQl
CatalogUrlRewriteGraphQl
CmsGraphQl
CmsUrlRewriteGraphQl
ConfigurableProductGraphQl
CustomerGraphQl
DirectoryGraphQl
DownloadableGraphQl
EavGraphQl
GraphQl
GroupedProductGraphQl
QuoteGraphQl
SalesGraphQl
SendFriendGraphQl
StoreGraphQl
SwatchesGraphQl
TaxGraphQl
ThemeGraphQl
UrlRewriteGraphQl
WeeeGraphQl
WishlistGraphQl

阅读详情

windows安装magento2.3出现的问题和解决办法

前言:

最近看网站的搜索引擎关键词记录,发现一个问题搜索的特别多,就是Windows安装magento2.3。
搜索指定版本是2.3的。

一直在虚拟机里面测试magento,所以都没碰到过这个问题。自己亲自测试了下,安装过程中一切正常,操作跟magento2其他版本一样。但打开首页就开始报如下错误:

阅读详情

Magento2.3忽略Action的Csrf验证

最近在开发一个magento支付接口插件,支付平台需要异步地把支付结果POST到magento网站.原来以为很简单的事情,只需要添加一个控制器,接收POST过来的数据,再修改订单状态即可。

在magento1.9 2.1 2.2 都很顺利地实现了。但magento2.3版本,模拟POST操作的时候一直都自动跳转到了首页,发现是Csrf验证不通过问题。

后来查了官方文档,在2.3版本,所有的控制器都默认了Csrf验证。

知道原因解决起来也简单了,官方也给出了方法,方法如下:

阅读详情

Magento2自定义路由实现URL重写

最近在写个magento2的blog插件,需要实现URL伪静态。
更多可以参考magento2自带的CMS 模块
代码如下:

先定义di文件,app/code/Mageoo/MyBlog/etc/frontend/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\App\RouterList">
        <arguments>
            <argument name="routerList" xsi:type="array">
                <item name="cms" xsi:type="array">
                    <item name="class" xsi:type="string">Mageoo\MyBlog\Controller\Router</item>
                    <item name="disable" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">70</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

di.xml配置对应的Router class文件 app/code/Mageoo/MyBlog/Controller/Router.php

    public function match(\Magento\Framework\App\RequestInterface request)
    {identifier = trim(request->getPathInfo(), '/');condition = new \Magento\Framework\DataObject(['identifier' => identifier, 'continue' => true]);this->_eventManager->dispatch(
            'cms_controller_router_match_before',
            ['router' => this, 'condition' =>condition]
        );
        identifier =condition->getIdentifier();

        if (condition->getRedirectUrl()) {this->_response->setRedirect(condition->getRedirectUrl());request->setDispatched(true);
            return this->actionFactory->create('Magento\Framework\App\Action\Redirect');
        }

        if (!condition->getContinue()) {
            return null;
        }

        //identifier 获取到了identifier 后,就可以查找具体blogid,然后把参数分发到具体的Action处理。

        request->setModuleName('myblog')->setControllerName('index')->setActionName('index')->setParam('blogid',blogid);
        request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS,identifier);

        return $this->actionFactory->create('Magento\Framework\App\Action\Forward');
    }

Magento2 static/version 资源文件404 NOT FOUND问题

Magento2 static/version 资源文件404 NOT FOUND问题。

例如下面的链接 xxxx.com/static/version1483410588/frontend/……

version1483410588这个文件夹服务器里面压根就找不到。

这个其实也不是问题,是伪静态没配置好。

查看magento2根目录下的nginx.conf.sample文件,里面的配置就可以看出问题所在。

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version {
    rewrite ^/static/(version\d*/)?(.*)/static/2 last;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2){
    add_header Cache-Control "public";
    add_header X-Frame-Options "SAMEORIGIN";
    expires +1y;

    if (!-frequest_filename) {
        rewrite ^/static/(version\d*/)?(.*)/static.php?resource=2 last;
    }
}
location ~* \.(zip|gz|gzip|bz2|csv|xml){
    add_header Cache-Control "no-store";
    add_header X-Frame-Options "SAMEORIGIN";
    expires    off;

    if (!-frequest_filename) {
       rewrite ^/static/(version\d*/)?(.*)/static.php?resource=2 last;
    }
}
if (!-f request_filename) {
    rewrite ^/static/(version\d*/)?(.*) /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}

想去掉这个数字 在后台设置

Configuration/Developer/Static Files Settings/Sign Static Files/ 设置为NO

新安装的magento2后台错乱运行下面的SQL后清理缓存。

INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`) VALUES (NULL, 'default', '0', 'dev/static/sign', '0')

好吧,这又是一篇废话文章……

Magento2.x中文语言包及安装使用

本站版本的 Magento2.x中文语言包 还在整理中,先把一份[作者:木瓜]的共享出来。 如果需要最新Magento1.x中文语言包请到这里 magento1.x中文语言包下载地址

下载

magento2中文语言包

安装

上传到mage2.store/app/i18n/Magento/zh_Hans_CN文件夹 【备注:mage2.store/vendor/magento/language-zh_hans_cn】 运行脚本命令:

bin/magento setup:static-content:deploy zh_Hans_CN

使用

后台显示中文界面

编辑后台用户账号,把Interface Locale 设为中文。如下图: magento2-chinese-lang-1 magento2-chinese-lang-2  

前台使用中文

修改店铺配置,把Locale Options 下面的locale 设为中文,如下图: magento2-chinese-lang-4 magento2-chinese-lang-3