【问题标题】:Remove parent categories from subcategory in URLs in Magento 1.9.2.3从 Magento 1.9.2.3 中 URL 的子类别中删除父类别
【发布时间】:2016-08-11 03:56:14
【问题描述】:

Magento 版本是 1.9.2.3。

我尝试了以下对我不起作用的解决方案。

步骤 1:转到 app/code/core/Mage/Catalog/Model/Url.php 将此文件复制到 app/code/local/Mage/Catalog/Model/Url.php 因为它是核心 Magento 文件,这样我们必须将该文件复制到 app/code/local。

第 2 步:现在在 Magento 版本的第 698 行附近搜索 getCategoryRequestPath($category, $parentPath)。 1.9.1.0

第 3 步:在第 717 行附近搜索 if (null === $parentPath) 并将该行注释如下:

/* if (null === $parentPath) {
$parentPath = $this->getResource()->getCategoryParentPath($category);
}
elseif ($parentPath == '/'){*/
$parentPath = ''; //DO NOT Comment this line
//} 

第 4 步:现在转到 Magento 管理员并清除缓存系统->缓存管理和重新索引系统->索引管理数据。

第 5 步:刷新浏览器缓存并再次导航,现在您将在 Url 中看到子类别,而不是父类别,就像 http://www.abcxyz.com/test-category-level-1-3.html - 查看更多信息:http://www.expertwebadvisor.com/remove-parent-category-path-from-sub-category-url-in-magento/#sthash.cy3HvxwW.dpuf

我也试过这个对我不起作用的解决方案。

假设要从url中去掉父类路径如Url-> www.domain.com/cat1/cat2 到 www.domain.com/cat2

用法:

Go to the Magento Admin Panel -> System -> Configuration -> Catalog -> Seo Options
Select yes or no from "Use Parent Category Path for Category URLs"
Refresh category url index.

选项 YES => www.domain.com/cat1/cat2

选项 NO => www.domain.com/cat2

如果您有其他解决方案,请帮助我

【问题讨论】:

    标签: magento url-rewriting categories


    【解决方案1】:

    您的第一个替代方案需要奏效。检查您对“Mage_Catalog_Model_Url”的覆盖是否工作正常。在方法中尝试 die()。

    我已经为一个特定的类别 ID 这样做了。我需要从每个类别 URL 中删除 id 为“4”的类别。下面是它的代码:

    public function getCategoryRequestPath($category, $parentPath)
    {
        $storeId = $category->getStoreId();
        $idPath  = $this->generatePath('id', null, $category);
        $suffix  = $this->getCategoryUrlSuffix($storeId);
    
        if (isset($this->_rewrites[$idPath])) {
            $this->_rewrite = $this->_rewrites[$idPath];
            $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
        }
    
        if ($category->getUrlKey() == '') {
            $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
        }
        else {
            $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
        }
    
        $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
        if (null === $parentPath && $category->getParentId() != 4) {
            $parentPath = $this->getResource()->getCategoryParentPath($category);
        }
        elseif($category->getParentId() == 4){
            $parentPath = '';
        }
        elseif ($parentPath == '/') {
            $parentPath = '';
        }
        $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath,
            true, $category->getStoreId());
    
        $requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
        if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) {
            return $existingRequestPath;
        }
    
        if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) {
            return $requestPath;
        }
    
        return $this->getUnusedPath($category->getStoreId(), $requestPath,
            $this->generatePath('id', null, $category)
        );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      相关资源
      最近更新 更多