Skip to content

Instantly share code, notes, and snippets.

@fballiano
Created June 26, 2014 12:21
Show Gist options
  • Save fballiano/090aa60bd4983adba35b to your computer and use it in GitHub Desktop.
Save fballiano/090aa60bd4983adba35b to your computer and use it in GitHub Desktop.
Magento EE 1.13 does not use suffix in sitemap.xml generation => all urls go 404
diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
index 5c82f40..63ecf21 100644
--- a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
+++ b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
@@ -102,7 +102,22 @@ class Mage_Sitemap_Model_Resource_Catalog_Category extends Mage_Sitemap_Model_Re
*/
protected function _getEntityUrl($row, $entity)
{
- return !empty($row['request_path']) ? $row['request_path'] : 'catalog/category/view/id/' . $entity->getId();
+ $suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
+ if (!$suffix) {
+ return parent::_getEntityUrl($row, $entity);
+ }
+
+ if (!empty($row['request_path'])) {
+ $url = $row['request_path'];
+ // Add suffix if not already present
+ if (!preg_match('%\.[^/]+$%', $url)) {
+ $url .= '.' . $suffix;
+ }
+ } else {
+ // Don't append suffix to default URL paths
+ $url = 'catalog/category/view/id/' . $entity->getId();
+ }
+ return $url;
}
/**
diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php
index 76479f1..9eeb035 100644
--- a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php
+++ b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Product.php
@@ -103,7 +103,22 @@ class Mage_Sitemap_Model_Resource_Catalog_Product extends Mage_Sitemap_Model_Res
*/
protected function _getEntityUrl($row, $entity)
{
- return !empty($row['request_path']) ? $row['request_path'] : 'catalog/product/view/id/' . $entity->getId();
+ $suffix = Mage::helper('catalog/product')->getProductUrlSuffix();
+ if (!$suffix) {
+ return parent::_getEntityUrl($row, $entity);
+ }
+
+ if (!empty($row['request_path'])) {
+ $url = $row['request_path'];
+ // Add suffix if not already present
+ if (!preg_match('%\.[^/]+$%', $url)) {
+ $url .= '.' . $suffix;
+ }
+ } else {
+ // Don't append suffix to default URL paths
+ $url = 'catalog/category/view/id/' . $entity->getId();
+ }
+ return $url;
}
/**
@domeglic
Copy link

domeglic commented Dec 8, 2014

There is a mistake on line 51, it should be "catalog/product/view/id".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment