I've developed a bespoke module which lists a series of people on the site. Each person has their own URL (a bespoke Magento controller, which does basic CRUD on Person models) and I need to feed these public URLs into a Google Sitemap XML file.
I want to use Magento's own sitemap generation and the cron if I can.
The Mage_Sitemap_Model_Observer
already pulls all the Sitemap records from the sitemaps
table and one-by-one calls their generateXml()
methods.
$collection = Mage::getModel('sitemap/sitemap')->getCollection();
/* @var $collection Mage_Sitemap_Model_Mysql4_Sitemap_Collection */
foreach ($collection as $sitemap) {
/* @var $sitemap Mage_Sitemap_Model_Sitemap */
try {
$sitemap->generateXml();
}
catch (Exception $e) {
$errors[] = $e->getMessage();
}
}
I think I need to add my new Sitemap in the sitemaps
table which will then be called to generate my (separate) XML file for my custom model records. However, I don't know how to tell Magento to use my extended My_Module_Model_Sitemap
instead of just Mage_Sitemap_Model_Sitemap
, the latter of which will just give me an XML file listing all the same categories, products, and CMS pages as the main sitemaps.
The sitemaps
table has a sitemap_type
column, but this is never referenced in the Magento codebase as far as I can tell.
How can I use Magento's inbuilt sitemap engine while overwriting the Mage_Sitemap_Model_Sitemap
to have my own generateXml()
method? Or must I build an alternative sitemap system just for my own purposes here?
Best Answer
The steps I ended up using were as follows, and the comments and answers so far got me started in the right direction.
First I added a row to the "sitemap" table. Since we have multi-store set up, and because I want to keep my module store agnostic, I didn't hard code this INSERT into a MySQL migration, but just ran it on the store manually:
Then I overwrote the
Mage_Sitemap_Model_Sitemap
model inside the global/models section in my own module's config.xml file:This overwrites any calls to
Mage_Sitemap_Model_Sitemap
site-wide with my custom model, but I didn't want to copy and paste too much code there. Using Petar Dzhambazov's suggestion, I used a conditional to defer to the parent class unless thesitemap_type
is "people".Is there a better way, that avoids copying and pasting so much from the parent class?