Magento 如何去掉分类URL中的父目录
来源:互联网 发布:c语言标准库函数有多少 编辑:程序博客网 时间:2024/05/29 08:47
问题:
目前使用的是Magento1.4.2,现希望把Magento中所有产品分类的父类URL去掉。
如该分类名:http://www.abc.com/style/aaa.html 需要修改成 http://www.abc.com/aaa.html
解决方法:
为了不破坏源码,需要在Local中写一个小小的插件
1.在Local目录下创建Mage/Catalog/Model的目录结构
2.将app/code/core/Mage/Catalog/Model/URL.php 复制到Local/Mage/Catalog/Model/中,并做如下处理即可。
public function generatePath($type = 'target', $product = null, $category = null, $parentPath = null) { if (!$product && !$category) { Mage::throwException(Mage::helper('core')->__('Please specify either a category or a product, or both.')); } // generate id_path if ('id' === $type) { if (!$product) { return 'category/' . $category->getId(); } if ($category && $category->getLevel() > 1) { return 'product/' . $product->getId() . '/' . $category->getId(); } return 'product/' . $product->getId(); } // generate request_path if ('request' === $type) { // for category if (!$product) { if ($category->getUrlKey() == '') { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName()); } else { $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey()); } $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());// 注释以下语句// if (null === $parentPath) {// $parentPath = $this->getResource()->getCategoryParentPath($category);// }// elseif ($parentPath == '/') {// $parentPath = '';// } $parentPath = ''; //新增加语句; $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath, true, $category->getStoreId()); return $this->getUnusedPath($category->getStoreId(), $parentPath . $urlKey . $categoryUrlSuffix, $this->generatePath('id', null, $category) ); } // for product & category if (!$category) { Mage::throwException(Mage::helper('core')->__('A category object is required for determining the product request path.')); // why? } if ($product->getUrlKey() == '') { $urlKey = $this->getProductModel()->formatUrlKey($product->getName()); } else { $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey()); } $productUrlSuffix = $this->getProductUrlSuffix($category->getStoreId()); if ($category->getLevel() > 1) { $this->_addCategoryUrlPath($category); // To ensure, that category has url path either from attribute or generated now $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $category->getStoreId()); return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix, $this->generatePath('id', $product, $category) ); } // for product only return $this->getUnusedPath($category->getStoreId(), $urlKey . $productUrlSuffix, $this->generatePath('id', $product) ); } // generate target_path if (!$product) { return 'catalog/category/view/id/' . $category->getId(); } if ($category && $category->getLevel() > 1) { return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId(); } return 'catalog/product/view/id/' . $product->getId(); }
3.重新生成一下目录URL的索引
- magento如何去掉分类url中的父目录
- Magento 如何去掉分类URL中的父目录
- Magento中如何去掉子分类的url地址中带有父分类的url key?
- 如何去掉Magento默认URL中的index.php
- magento 所有产品的url去掉分类,分类url不变
- Magento二级三级分类URL去除父目录名
- magento 去掉网址 url 中的 index.php
- magento 去掉网址url中的index.php
- Liferay如何去掉url中的国际化信息
- thinkPHP如何去掉url中的index.php
- 去掉angularjs url中的#
- Magento如何调用子分类
- joomla中如何去掉分类文章列表中的文章序号?
- 如何去掉CI (codeigniter)url中的index.php
- 解析如何去掉CodeIgniter URL中的index.php
- struts2中如何去掉请求url中的.action
- PHP CI(CodeIgniter) 如何去掉url中的index.php
- 解析如何去掉CodeIgniter URL中的index.php
- C++ 加载PNG资源图片
- C++变量的初始化规则
- 进程同步机制
- 十招教你从程序员转向企业家
- 霍內演算法(Horner’s Algorithm)
- Magento 如何去掉分类URL中的父目录
- Hudson 之旅(一)
- Win7 Windows XP 下载提示框
- 浅谈制作
- 《算法导论》笔记--红黑树(一)
- 动态实现杨辉三角(C语言)
- “必需的资源无法得到”
- unix find & xargs 详解
- SQL注入专题--整理帖