magento 所有產品的url去掉分類,分類url不變
阿新 • • 發佈:2019-02-16
1.後臺system -> configuration -> catalog -> Search Engine Optimizations
中Use Categories Path for Product URLs 這個設為No
如果沒有下面的步驟,有的產品頁面的關聯產品的url還是存在分類名。2.app/code/core/mage/catalog/model/product/url.php
修改getUrl函式
if (empty($requestPath) && $requestPath !== false) { $idPath = sprintf('product/%d', $product->getEntityId()); //以下程式碼註釋 //if ($categoryId) { // $idPath = sprintf('%s/%d', $idPath, $categoryId); //} $rewrite = $this->getUrlRewrite(); $rewrite->setStoreId($storeId) ->loadByIdPath($idPath); if ($rewrite->getId()) { $requestPath = $rewrite->getRequestPath(); $product->setRequestPath($requestPath); } else { $product->setRequestPath(false); } }