2016-04-19 21 views
0

Magentoのバージョンは1.9.2.3です。Magento 1.9.2.3のURLのサブカテゴリから親カテゴリを削除します。

私は私のためにはうまくいかないソリューションを試してみました。

ステップ1:app/code/core/Mage/Catalog/Model/Url.phpに移動します。このファイルをapplication/code/local/Mage/Catalog/Model/Url.phpにコピーします。そのファイルをapp/code/localにコピーする必要があります。

ステップ2:マゼンタ版の698行目のgetCategoryRequestPath($ category、$ parentPath)を検索します。 1.9.1.0

ステップ3:(ヌル=== $ parentPath)場合はライン717の周りに検索すると、以下のように行をコメント:

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

ステップ4:今Magentoの管理に移動し、クリアキャッシュシステム - >キャッシュ管理と再インデックスシステム - >インデックス管理。

ステップ5:ブラウザのキャッシュを更新し、今はhttp://www.abcxyz.com/test-category-level-1-3.htmlと同じようにURLのみでサブカテゴリない親カテゴリが表示されます再びナビゲート - で詳細を参照してください。http://www.expertwebadvisor.com/remove-parent-category-path-from-sub-category-url-in-magento/#sthash.cy3HvxwW.dpuf

また、私はdoesnのこのソリューションを試してみました私のために働く。

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. 

オプション:

あなたは

USAGEをwww.domain.com/cat2するために、このようなURL - > www.domain.com/cat1/cat2としてURLから親カテゴリのパスを削除するとしますYES => www.domain.com/cat1/cat2

オプションNO => www.domain.com/cat2

あなたは別の解決策

を持っている場合は、私を助けて

答えて

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) 
    ); 
} 
関連する問題