给Magento网址URL添加SKU属性的方法

作者: zenglihunter 分类: Magento 发布时间: 2015-07-20 08:25 ė11,271 Views 6没有评论

Url添加SKU值可以保证url的唯一性,避免Magento重新索引时会对复制产品的url进行重写(url后面的数值索引一次变一次)。

Magento给URL添加SKU属性值得方法

1.打开app\code\local\Mage\Catalog\Model\Url.php,添加$sku = $product->getSku();和. $sku红色部分

public function getProductRequestPath($product, $category)
{
if ($product->getUrlKey() == ”) {
$urlKey = $this->getProductModel()->formatUrlKey($product->getName());
} else {
$urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
}
$storeId = $category->getStoreId();
$suffix = $this->getProductUrlSuffix($storeId);
$idPath = $this->generatePath(‘id’, $product, $category);
$sku = $product->getSku();
/**
* Prepare product base request path
*/
if ($category->getLevel() > 1) {
// To ensure, that category has path either from attribute or generated now
$this->_addCategoryUrlPath($category);
$categoryUrl = Mage::helper(‘catalog/category’)->getCategoryUrlPath($category->getUrlPath(),
false, $storeId);
$requestPath = ‘p/’ . $categoryUrl . ‘/’ . $urlKey . ‘-‘ . $sku;
} else {
$requestPath = ‘p/’ . $urlKey . ‘-‘ . $sku;

2.新建打开app\code\local\Mage\Catalog\Model\Resource\Url.php,添加sku以便调用。

$select = $adapter->select()
->useStraightJoin(true)
->from(array(‘e’ => $this->getTable(‘catalog/product’)), array(‘entity_id’, ‘sku’))
->join(
array(‘w’ => $this->getTable(‘catalog/product_website’)),
‘e.entity_id = w.product_id AND w.website_id = :website_id’,
array()
)
->where(‘e.entity_id > :entity_id’)
->order(‘e.entity_id’)
->limit($this->_productLimit);

3.刷新索引,大功告成:)

参考来源:http://stackoverflow.com/questions/23987445/how-to-customize-product-url

❤再看看呗❤

给Magento目录和产品URL加前缀,更利于SEO和统计 Magento默认的URL效果 产品:www.yuyuhunter.com/product-name.html 目录:www.yuyuhunter.com/catalog-name/ 优化后的URL效果 产品:www.yuyuhunter.com/p/product-name.h...

本文出自 幽游网,转载时请注明出处及相应链接。

本文永久链接: http://www.yuyuhunter.com/post/magento-url-add-sku.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

必须启用javascript才能看到验证图案!
Ɣ回顶部