Skip to content

Instantly share code, notes, and snippets.

@dinhkhanh
Created June 18, 2014 14:11
Show Gist options
  • Save dinhkhanh/5a7224c95d661fe29e37 to your computer and use it in GitHub Desktop.
Save dinhkhanh/5a7224c95d661fe29e37 to your computer and use it in GitHub Desktop.
Always include catalog in product url
Index: app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
===================================================================
--- app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php (revision 2102)
+++ app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php (working copy)
@@ -553,7 +553,11 @@
->from($this->getTable('core/url_rewrite'), array('product_id', 'request_path'))
->where('store_id=?', Mage::app()->getStore()->getId())
->where('is_system=?', 1)
- ->where('category_id=? OR category_id is NULL', $this->_urlRewriteCategory)
+// excluding this clause to facilitate one URL per product, and one that includes the category
+// if a product has multiple categories, the first one (by category_id) will be used
+// in most cases you'll probably only have one category because you only want one page per product for SEO reasons
+// for maximum link juice, no possibility of duplicate content, and a less confusing store
+// ->where('category_id=? OR category_id is NULL', $this->_urlRewriteCategory)
->where('product_id IN(?)', $productIds)
->order('category_id DESC'); // more priority is data with category id
$urlRewrites = array();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment