File: /var/www/vhosts/paiskincare.com/httpdocs/sitemaps/categories.php
<?php
/**
* MSU Sitemaps - Magic SEO URL URL for ZenCart
* http://www.magic-seo-url.com/zencart/
*
* 2009, (c) Inveo s.r.o.
*
* 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'");
//$result = $db->Execute("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'MAX_DISPLAY_SEARCH_RESULTS'");
$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");
//$result = $db->Execute("SELECT c.categories_id, c.parent_id, COUNT(pc.products_id) AS products_in_cat FROM ".TABLE_CATEGORIES." c LEFT JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." pc ON pc.categories_id = c.categories_id GROUP BY c.categories_id, c.parent_id ORDER BY c.categories_id DESC");
while(!$result->EOF) {
if(!empty($result->fields['parent_id'])) {
$cPath = $result->fields['categories_id'];
$parentId = $result->fields['parent_id'];
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);
} else {
$cPath = $result->fields['categories_id'];
}
$url = '';
$fail = false;
if(strpos($cPath, '_') === false) {
$niceData = $cache->read('categories-parents', $result->fields['categories_id'], $langId);
if(!$niceData) {
$fail = true;
} else {
$url = $niceData[1].URI_DELIMETER.$result->fields['categories_id'].'/';
}
} else {
$cPathAr = explode('_', $cPath);
if(count($cPathAr) > CATEGORY_DEPTH) {
$fail = true;
} else {
foreach($cPathAr as $cPathId) {
$niceData = $cache->read('categories', $cPathId, $langId);
if(!$niceData) {
$fail = true;
break;
} else {
$url .= $niceData[1].URI_DELIMETER.$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__'.URI_EXTENSION;
}
//$sm->addUrlToSiteMap($url, 'weekly', '0.8');
$sm->addUrlToSiteMap($url, 'weekly');
$pages = ceil($result->fields['products_in_cat'] / $perPage);
for ($i = 2; $i <= $pages; $i++) {
//$sm->addUrlToSiteMap($url.str_replace('__PAGE__', $i, $pagination), 'weekly', '0.8');
$sm->addUrlToSiteMap($url.str_replace('__PAGE__', $i, $pagination), 'weekly');
}
$result->MoveNext();
}
}
?>