I want to include category path for products inside my sitemap.xml.

Currently I am using Atwix Sitemap module, to split sitemap in multiple sitemaps. See: https://github.com/Atwix/Sitemap

How can I edit this module or the default Magento code, to include full product url's?

1 Answer 1


To include full category path, you can create a small extension and try this:




public function extendProductXmlSitemap(Varien_Event_Observer $observer)
    $collection = $observer->getCollection();
    $items      = $collection->getItems();
    $pathes     = array();

    $categoryIds = Mage::getResourceModel('sitemap/catalog_category')->getCollection($observer->getStoreId());
    $categoryIds = array_keys($categoryIds);
    $categories  = Mage::getResourceModel('catalog/category_collection')

    foreach ($categories as $category) {
        $productsIds = $category->getProductCollection()->getAllIds();
        $func = function($categoryId, $productsId) {
            return sprintf('catalog/product/view/id/%d/category/%d', $productsId, $categoryId);
        $pathes[] = array_map($func, array_fill(0, count($productsIds), $category->getId()), $productsIds);

    $rewrites = Mage::getResourceModel('core/url_rewrite_collection')
        ->addFieldToFilter('target_path', array('in' => $pathes));

    foreach ($rewrites as $rewrite) {
        $item = new Varien_Object;
        $items[$itemId] = $item;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.