Created
February 25, 2014 19:54
-
-
Save deniscsz/9216430 to your computer and use it in GitHub Desktop.
Magento Sitemap.xml 301 Maker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('MAGENTO', realpath(dirname(__FILE__))); | |
| set_time_limit (0); | |
| require_once MAGENTO . '/app/Mage.php'; | |
| Mage::app(); | |
| $sitemap = simplexml_load_file('http://www.cpaps.com.br/sitemap.xml'); | |
| foreach($sitemap->url as $url_list) { | |
| $_url = $url_list->loc; | |
| $date = new DateTime(); | |
| $timestamp = $date->getTimestamp(); | |
| $Durl = ''; | |
| $Burl = ''; | |
| $Burl = substr($_url,24); | |
| if($_pro = strpos($_url,'/produto/')) { | |
| $Durl = explode('/',$_url); | |
| } elseif($_dep = strpos($_url,'/departamento/')) { | |
| $Durl = explode('/',$_url); | |
| } | |
| if($Durl) { | |
| //print_r($Durl); | |
| echo $Burl . ' | '; | |
| echo end($Durl).'<br/>'; | |
| Mage::getModel('core/url_rewrite') | |
| ->setIsSystem(0) | |
| ->setOptions('RP') | |
| ->setIdPath('cpaps-old-'.strtolower($Burl).'-'.$timestamp) //ID na tabela de URL reescrita | |
| ->setTargetPath(strtolower(end($Durl))) //URL NO MAGENTO | |
| ->setRequestPath($Burl) //URL ANTIGA | |
| ->save(); | |
| } | |
| unset($date); | |
| unset($timestamp); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment