~J~ wrote:Old URIs are used when no cache data are available (they are created on first page visit).
Gotcha. This does in fact seem to be the case. Thanks for the tip. Seems to have only cropped up because disabled categories were being shown (for which no cache data had ever been created).
~J~ wrote:If pagenation does not correspond to the reality it is likely caused by some hard coding you have made to Zen Cart installation (it does affect MSU, only MSU Sitemaps).
I don't think so. After reviewing the code in sitemaps/categories.php, it seems the pagination count is being determined by retrieving the max number of results for
search results pages (MAX_DISPLAY_SEARCH_RESULTS)...which is NOT (necessarily, though it could be coincidentally) the same as the max number of products on a
category page (MAX_DISPLAY_PRODUCTS_LISTING). Thus the pagination breaks for category pages are being determined incorrectly by dividing by the wrong constant.
Additionally, retrieving the number of total products in a category is not the same as retrieving the number of
ACTIVE products. This discrepancy could also affect pagination if disabled products exist. (Also, getting a product count would be more rigorous by doing a join back to the products table, rather than relying on the data in the TABLE_PRODUCTS_TO_CATEGORIES.)
~J~ wrote:It is the best when Sitemaps contain all pages of your web even if they don't show any useful content yet.
I disagree—it's illogical to tell a search engine to index pages that are intentionally disabled (and would be a waste of time for a visitor to follow these links from a search engine to a page that has products).
I was wrong in my previous post is assuming that the existence of (enabled) products in a category is what "enables" the category; ZenCart actually has an explicit field for this: categories_status. If set to 0, ZenCart never shows the category...but MSU Sitemaps does because it doesn't check this field, thus showing all categories, including explicitly disabled ones.
A final note: it seems like you could modify this loop:
Code: Select all
do {
$result2 = $db->Execute("SELECT categories_id, parent_id FROM ".TABLE_CATEGORIES." WHERE categories_id = '".$parentId."'");
$cPath = $result2->fields['categories_id'].'_'.$cPath;
$parentId = $result2->fields['parent_id'];
if(empty($result2->fields['parent_id'])) break;
} while(true);
to replace all the redundant queries to the database by instead just looping back through the original recordset and finding the parent ids from it, since you already have a full array of all category and parent ids there. (This is obviously a pretty minor performance gain since this page would only ever be hit periodically by search engines...but hey, every little bit helps.)
Applying all these changes to sitemaps/categories.php fixes the problems I mentioned:
Code: Select all
<?php
/**
* MSU Sitemaps - Magic SEO URL URL for ZenCart
* http://www.magic-seo-url.com/zencart/
*
* 2007, (c) Jiri Stavinoha
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
**/
if(!defined('SM_IN_SITEMAPS')) exit();
global $cache, $sm, $db;
$result = $db->Execute("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'MAX_DISPLAY_PRODUCTS_LISTING'");
$perPage = $result->fields['configuration_value'];
foreach($GLOBALS['smInstalledLang'] as $langId => $langCode) {
$result = $db->Execute("SELECT c.categories_id, c.parent_id, COUNT(p.products_id) AS products_in_cat FROM ".TABLE_CATEGORIES." c LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON pc.categories_id = c.categories_id LEFT JOIN ".TABLE_PRODUCTS." p ON pc.products_id = p.products_id AND p.products_status = 1 WHERE c.categories_status = 1 GROUP BY c.categories_id, c.parent_id ORDER BY c.categories_id DESC");
$r1 = 0;
while ($r1 < $result->RecordCount()) {
$result->Move($r1++);
$categoryId = $result->fields['categories_id'];
$cPath = $categoryId;
$parentId = $result->fields['parent_id'];
$products_in_cat = $result->fields['products_in_cat'];
if(!empty($parentId)) {
do {
$r2 = 0;
while ($r2 < $result->RecordCount() ) {
$result->Move($r2++);
if ($result->fields['categories_id'] == $parentId) {
$cPath = $result->fields['categories_id'].'_'.$cPath;
$parentId = $result->fields['parent_id'];
if(empty($parentId)) break 2;
else break 1;
}
}
} while(true);
}
$url = '';
$fail = false;
if(strpos($cPath, '_') === false) {
$niceData = $cache->read('categories-parents', $categoryId, $langId);
if(!$niceData) {
$fail = true;
} else {
$url = $niceData[1].'-'.$categoryId.'/';
}
} else {
$cPathAr = explode('_', $cPath);
if(count($cPathAr) > 3) {
$fail = true;
} else {
foreach($cPathAr as $cPathId) {
$niceData = $cache->read('categories', $cPathId, $langId);
if(!$niceData) {
$fail = true;
break;
} else {
$url .= $niceData[1].'-'.$cPathId.'/';
}
}
}
}
if($GLOBALS['smMultilang']) {
$url = $langCode.'/'.$url;
}
if($fail) {
$url = UN_ZENCART_MAINFILE.'?main_page='.FILENAME_DEFAULT.'&cPath='.$cPath.(($GLOBALS['smMultilang']) ? '&language='.$langCode : '');
$pagination = '&page=__PAGE__';
} else {
$pagination = 'index-__PAGE__.html';
}
$sm->addUrlToSiteMap($url, 'weekly', '0.8');
$pages = ceil($products_in_cat / $perPage);
for ($i = 2; $i <= $pages; $i++) {
$sm->addUrlToSiteMap($url.str_replace('__PAGE__', $i, $pagination), 'weekly', '0.8');
}
}
}
?>