zoukankan      html  css  js  c++  java
  • Magento多级分类URL去掉父目录

    在Magento模板开发中,有时候需要将多级分类的url简化,Magento的URL默认是显示多级分类的

    http://www.a.com/分类1/分类2/分类3

    现在需要简化为:

    分类2的URL为:http://www.a.com/分类2

    分类3的URL为:http://www.a.com/分类3

    具体修改方法如下:

    打开app/code/core/Mage/Catalog/Model/Url.php这个php文件,找到

    if (null === $parentPath) {
    $parentPath = $this->getResource()->getCategoryParentPath($category);
    }
    elseif ($parentPath == '/') {
    $parentPath = '';
    }

    把上面的代码修改为:

    //if (null === $parentPath) {
    //$parentPath = $this->getResource()->getCategoryParentPath($category);
    //}
    //elseif ($parentPath == '/') {
    $parentPath = '';
    //}

    其实就是把这段代码屏蔽掉了。
    其中

    $parentPath = $this->getResource()->getCategoryParentPath($category);

    是获取分类的父级分类,下面将父级分类设置为空则在生成的URL中屏蔽掉父级
    仔细观察core_url_rewrite表里面的数据 就会发现

  • 相关阅读:
    13-17读后感
    读10 11 12章
    读书作业
    5.2.3
    测试与封装
    作业四
    作业三
    实验四 主存空间的分配和回收模拟
    评论
    实验三 进程调度模拟程序
  • 原文地址:https://www.cnblogs.com/liuxgnu/p/3535414.html
Copyright © 2011-2022 走看看