Hope this helps a bit .... in this expample we exclude all products with color
attribute red
:
app\etc\modules\My_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<My_Module>
<active>true</active>
<codePool>community</codePool>
</My_Module>
</modules>
</config>
app\code\community\My\Module\etc\config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<My_Module>
<version>0.0.1</version>
</My_Module>
</modules>
<global>
<models>
<My_Module>
<class>My_Module_Model</class>
</My_Module>
</models>
<events>
<!-- product sitemap -->
<sitemap_products_generating_before>
<observers>
<sitemap_products>
<class>My_Module/observer</class>
<method>excludeProductsFromSitemap</method>
</sitemap_products>
</observers>
</sitemap_products_generating_before>
<!-- category sitemap -->
<sitemap_categories_generating_before>
<observers>
<sitemap_products>
<class>My_Module/observer</class>
<method>excludeCategoriesFromSitemap</method>
</sitemap_products>
</observers>
</sitemap_categories_generating_before>
</events>
</global>
</config>
app\code\community\My\Module\Model\Observer.php
<?php
class My_Module_Model_Observer extends Mage_Core_Model_Observer
{
public function excludeProductsFromSitemap(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$collection = $event->getCollection();
$items = $collection->getItems();
$excludeIds = Mage::getModel('catalog/product')
->getCollection()
->setStoreId($event->getStoreId())
// example filter
->addAttributeToFilter('color', 'red')
->getAllIds();
foreach ($excludeIds as $id) {
unset($items[$id]);
}
$collection->setItems($items);
}
public function excludeCategoriesFromSitemap(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$collection = $event->getCollection();
$items = $collection->getItems();
// your logic to filter categories here
$collection->setItems($items);
}
}
<core_sitemap_generating_before>
or maybe something else?