1

I created sitemap.xml by controller using core observer.php file which is inbuilt in magento.

Now I want sitemap.xml on screen by hitting my controller url, and also want to update the old sitemap.xml my controller ->

IndexController.php :

public function indexAction(){
$collection = Mage::getModel('sitemap/sitemap')->getCollection();
    foreach ($collection as $sitemap) {
    try {

      $sitemap->generateXml();
    }
    catch (Exception $e) {
        $errors[] = $e->getMessage();
    }
    }

}
0

You can use below solution:

$data =array();
$data['sitemap_path']= '/';
$data['sitemap_filename'] = 'sitemap.xml';
$model = Mage::getModel('sitemap/sitemap');
 $path = rtrim($data['sitemap_path'], '\\/')
                      . DS . $data['sitemap_filename'];

$validator = Mage::getModel('core/file_validator_availablePath');
/** @var $helper Mage_Adminhtml_Helper_Catalog */
$helper = Mage::helper('adminhtml/catalog');
$validator->setPaths($helper->getSitemapValidPaths());
if ($validator->isValid($path)) {
$model->setData($data);
$model->save();
}
0

Try following way:


header('Content-type: text/xml');

$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();

        if($sitemap->getSitemapPath() == '/') {
            $realPath = Mage::getBaseDir() . '/'.$sitemap->getSitemapFilename();
        } else {
            $realPath = Mage::getBaseDir() . '/' . $sitemap->getSitemapPath().$sitemap->getSitemapFilename();
        }

        if(file_exists($realPath)) {
            $xml = simplexml_load_file($realPath);
            echo $xml->asXML();
        }
    }
    catch (Exception $e) {

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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