I was looking for a module that creates a sitemap for Google. I found one for free at xcartmod.com .
It is a nice mod but it has some downsides:
1. It looks the db and creates the urls the following way:
www.site.com//product.php?productid=xx
which is bad when you use clean urls.
2. Doesn't include the manufacturer urls
So I made some modifications to fix the above mentioned problems and, since it is a free module, I thought I could post the modifications so someone else can use them.
If for any reason you think that is wrong, please tell me and I will remove everything from this post.
So I opened the ../modules/xCartMod_Google_Sitemap/sitemap_xml.php and made the following changes:
1. Replaced
Code:
$cats = func_query("SELECT * FROM $sql_tbl[categories] WHERE avail='Y'");
if (is_array($cats[0]))
foreach($cats as $ca) {
$xml .= '<url>
<loc>'.$http_location.'/home.php?cat='.$ca["categoryid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
}
with
Code:
$cats = func_query("SELECT * FROM $sql_tbl[categories], $sql_tbl[clean_urls] WHERE resource_type = 'C' AND categoryid = resource_id AND avail = 'Y'");
if (is_array($cats[0]))
foreach($cats as $ca) {
$xml .= '<url>
<loc>'.$http_location.'/'.$ca["clean_url"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>';
}
2. Replaced
Code:
$prods = func_query("SELECT * FROM $sql_tbl[products] WHERE forsale='Y'");
if (is_array($prods[0]))
foreach($prods as $pr) {
$xml .= '<url>
<loc>'.$http_location.'/product.php?productid='.$pr["productid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
with
Code:
$prods = func_query("SELECT * FROM $sql_tbl[products], $sql_tbl[clean_urls] WHERE resource_type = 'P' AND productid = resource_id AND forsale = 'Y'");
if (is_array($prods[0]))
foreach($prods as $pr) {
$xml .= '<url>
<loc>'.$http_location.'/'.$pr["clean_url"].'.html</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
3. Replaced
Code:
$pages = func_query("SELECT * FROM $sql_tbl[pages] WHERE active='Y'");
if (is_array($pages[0]))
foreach($pages as $pa) {
$xml .= '<url>
<loc>'.$http_location.'/pages.php?pageid='.$pa["pageid"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
with
Code:
$pages = func_query("SELECT * FROM $sql_tbl[pages], $sql_tbl[clean_urls] WHERE resource_type = 'S' AND pageid = resource_id AND active = 'Y'");
if (is_array($pages[0]))
foreach($pages as $pa) {
$xml .= '<url>
<loc>'.$http_location.'/'.$pa["clean_url"].'.html</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
4. Added
Code:
$manufacturers = func_query("SELECT * FROM $sql_tbl[manufacturers], $sql_tbl[clean_urls] WHERE resource_type = 'M' AND manufacturerid = resource_id AND avail = 'Y'");
if (is_array($manufacturers[0]))
foreach($manufacturers as $manuf) {
$xml .= '<url>
<loc>'.$http_location.'/'.$manuf["clean_url"].'</loc>
<lastmod>'.$today.'</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>';
}
before
Code:
$xml .= '<url>
<loc>'.$http_location.'/help.php?section=business</loc>
<lastmod>'.$today.'</lastmod>
You are ready! Your sitemap.xml contains your products,categories, manufacturer and static pages clean urls. It is updated once a day (if you visit the admin side of your shop) and is stored in
www.yoursite.com/sitemap.xml .
I made the changes on my 4.3.0 test installation (I'm now on 4.2.3 and want to upgrade to 4.3.0) and seems to work perfectly. It will work and on previous versions if the database tables maintain the same structure with 4.3.0.
Please test before you do anything on your live shop!!!
Best regards,
Andreas