Test with cat and products
This commit is contained in:
parent
0b451e2fc2
commit
25c1ae725b
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
if (!defined('_PS_VERSION_'))
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once dirname(__FILE__).'/../privatesales/Sale.php';
|
||||
|
||||
class GoogleSitemap extends Module
|
||||
{
|
||||
@ -72,6 +75,7 @@ class GoogleSitemap extends Module
|
||||
$langs = Language::getLanguages();
|
||||
$iso_code = Language::getIsoById((int) $cookie->id_lang);
|
||||
|
||||
|
||||
$xmlString = <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
@ -114,156 +118,58 @@ XML;
|
||||
|
||||
$cmss = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql_cms);
|
||||
foreach($cmss as $cms) {
|
||||
$tmpLink = Configuration::get('PS_REWRITING_SETTINGS')? $link->getCMSLink((int)$cms['id_cms'], $cms['link_rewrite'], FALSE, (int) $cms['id_lang']): $link->getCMSLink((int)$cms['id_cms']);
|
||||
$this->_addSitemapNode($xml, $tmpLink, '0.8', 'daily');
|
||||
$tmpLink = Configuration::get('PS_REWRITING_SETTINGS') ?
|
||||
$link->getCMSLink((int)$cms['id_cms'], $cms['link_rewrite'], FALSE, (int)$cms['id_lang']) :
|
||||
$link->getCMSLink((int)$cms['id_cms']);
|
||||
$this->_addSitemapNode($xml, $tmpLink, '0.8', 'weekly');
|
||||
}
|
||||
|
||||
/* Categories Generator */
|
||||
/*$exclude_categories = array();
|
||||
if (Module::isInstalled('privatesales')) {
|
||||
include(dirname(__FILE__).'/../privatesales/Sale.php');
|
||||
$has_trailers = file_exists(dirname(__FILE__).'/../privatesales/trailer.php');
|
||||
$sales = Sale::getSales(true, null, null, 'not_ended');
|
||||
|
||||
foreach($sales as $sale) {
|
||||
$exclude_categories = array_merge($exclude_categories, Sale::getCategoriesFromCache($sale->id));
|
||||
if ($has_trailers) {
|
||||
$trailers_i18n = array(
|
||||
'fr' => 'bande-annonce',
|
||||
'en' => 'trailer',
|
||||
);
|
||||
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS')) {
|
||||
if (count($langs) > 1) {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(TRUE, TRUE).__PS_BASE_URI__.$iso_code.'/'.(isset($trailers_i18n[$iso_code])? $trailers_i18n[$iso_code]: $trailers_i18n['en']).'/'.$sale->id.'-'.Tools::str2url($sale->title[$cookie->id_lang]), '0.8', 'weekly');
|
||||
} else {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(TRUE, TRUE).__PS_BASE_URI__.(isset($trailers_i18n[$iso_code])? $trailers_i18n[$iso_code]: $trailers_i18n['en']).'/'.$sale->id.'-'.Tools::str2url($sale->title[$cookie->id_lang]), '0.8', 'weekly');
|
||||
}
|
||||
} else {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(TRUE, TRUE).__PS_BASE_URI__.'modules/privatesales/trailer.php?id_sale='.$sale->id, '0.8', 'weekly');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ordering = (int) Configuration::get('PRIVATESALES_FEATURED_ORDER');
|
||||
if ($ordering == 0) {
|
||||
if (Module::isInstalled('privatesales_brands')) {
|
||||
$sales = Sale::getSales(TRUE, (int) Configuration::get('PRIVATESALES_FEATURED_IGNORE') == 1? NULL: !((bool) Configuration::get('PRIVATESALES_GUESTLIST')), TRUE, (bool) Configuration::get('PRIVATESALES_FEATURED_CURRENT'), TRUE);
|
||||
|
||||
$brands = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `id_brand`
|
||||
FROM `'._DB_PREFIX_.'privatesale_brands`
|
||||
WHERE `id_sale` IN ('.implode(', ', $sales).')
|
||||
GROUP BY `id_brand`
|
||||
') as $b) {
|
||||
$brands[] = $b['id_brand'];
|
||||
}
|
||||
|
||||
$manufacturers = Db::getInstance()->ExecuteS('
|
||||
SELECT m.*, ml.`short_description`
|
||||
FROM `'._DB_PREFIX_.'manufacturer` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml
|
||||
ON (
|
||||
m.`id_manufacturer` = ml.`id_manufacturer`
|
||||
AND ml.`id_lang` = '.(int) $cookie->id_lang.'
|
||||
)
|
||||
WHERE m.`active` = 1
|
||||
AND m.`id_manufacturer` IN ('.implode(', ', $brands).')
|
||||
ORDER BY m.`name` ASC
|
||||
');
|
||||
} else {
|
||||
$manufacturers = Manufacturer::getManufacturers(TRUE, (int) $cookie->id_lang, TRUE, FALSE, FALSE, TRUE);
|
||||
|
||||
// Liste des ventes actives
|
||||
$sales = Sale::getSales(true, null, null, 'not_ended');
|
||||
$products = array();
|
||||
|
||||
if (count($sales) > 0) {
|
||||
foreach ($sales as $sale) {
|
||||
|
||||
$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_category` FROM `'._DB_PREFIX_.'privatesale_category`
|
||||
WHERE `id_sale`='.(int)$sale->id);
|
||||
|
||||
$category = new Category($id_category);
|
||||
|
||||
if (($priority = 0.9 - ($category->level_depth / 10)) < 0.1) {
|
||||
$priority = 0.1;
|
||||
}
|
||||
|
||||
$brands_i18n = array(
|
||||
'fr' => 'marques',
|
||||
'en' => 'brands',
|
||||
);
|
||||
foreach($manufacturers as $manufacturer) {
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS')) {
|
||||
if (count($langs) > 1) {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(true, true).__PS_BASE_URI__.$iso_code.'/'.(isset($brands_i18n[$iso_code])? $brands_i18n[$iso_code]: $brands_i18n['en']).'/'.$manufacturer['id_manufacturer'].'-'.Tools::str2url($manufacturer['name']), '0.8', 'weekly');
|
||||
} else {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(true, true).__PS_BASE_URI__.(isset($brands_i18n[$iso_code])? $brands_i18n[$iso_code]: $brands_i18n['en']).'/'.$manufacturer['id_manufacturer'].'-'.Tools::str2url($manufacturer['name']), '0.8', 'weekly');
|
||||
}
|
||||
} else {
|
||||
$this->_addSitemapNode($xml, Tools::getShopDomain(true, true).__PS_BASE_URI__.'modules/privatesales/featured.php?id_brand='.$manufacturer['id_manufacturer'], '0.8', 'weekly');
|
||||
$tmpLink = Configuration::get('PS_REWRITING_SETTINGS') ?
|
||||
$link->getCategoryLink((int)$category->id_category, $category->link_rewrite[1]) :
|
||||
$link->getCategoryLink((int)$category->id_category);
|
||||
$this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'daily', substr($category->date_upd, 0, 10));
|
||||
|
||||
// Get products in category
|
||||
/*$productsId = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache`
|
||||
WHERE `id_sale` = '.(int) $sale->id);
|
||||
if (count($productsId) > 0) {
|
||||
foreach ($productsId as $p) {
|
||||
$products[] = $p['id_product'];
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}*/
|
||||
|
||||
/*if (Configuration::get('PS_REWRITING_SETTINGS')) {
|
||||
$categories = Db::getInstance()->ExecuteS('
|
||||
SELECT c.id_category, c.level_depth, link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, cl.id_lang
|
||||
FROM '._DB_PREFIX_.'category c
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl
|
||||
ON c.id_category = cl.id_category
|
||||
LEFT JOIN '._DB_PREFIX_.'lang l
|
||||
ON cl.id_lang = l.id_lang
|
||||
WHERE l.`active` = 1
|
||||
AND c.`active` = 1
|
||||
AND c.id_category != 1
|
||||
'.(count($exclude_categories) > 0? ' AND c.id_category NOT IN ('.implode(', ', $exclude_categories).')': '').'
|
||||
ORDER BY cl.id_category, cl.id_lang ASC
|
||||
');
|
||||
} else {
|
||||
$categories = Db::getInstance()->ExecuteS('
|
||||
SELECT c.id_category, c.level_depth, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd
|
||||
FROM '._DB_PREFIX_.'category c
|
||||
'.(count($exclude_categories) > 0? ' AND c.id_category NOT IN ('.implode(', ', $exclude_categories).')': '').'
|
||||
ORDER BY c.id_category ASC
|
||||
');
|
||||
}*/
|
||||
|
||||
foreach($categories as $category) {
|
||||
if (($priority = 0.9 - ($category['level_depth'] / 10)) < 0.1) {
|
||||
$priority = 0.1;
|
||||
}
|
||||
|
||||
$tmpLink = Configuration::get('PS_REWRITING_SETTINGS')? $link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'], (int)$category['id_lang']): $link->getCategoryLink((int)$category['id_category']);
|
||||
$this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($category['date_upd'], 0, 10));
|
||||
}
|
||||
|
||||
/*$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT p.id_product, pl.link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') date_upd, pl.id_lang, cl.`link_rewrite` category, ean13, i.id_image, il.legend legend_image, (
|
||||
SELECT MIN(level_depth)
|
||||
FROM '._DB_PREFIX_.'product p2
|
||||
LEFT JOIN '._DB_PREFIX_.'category_product cp2
|
||||
ON p2.id_product = cp2.id_product
|
||||
LEFT JOIN '._DB_PREFIX_.'category c2
|
||||
ON cp2.id_category = c2.id_category
|
||||
WHERE p2.id_product = p.id_product AND p2.`active` = 1
|
||||
AND c2.`active` = 1
|
||||
) AS level_depth
|
||||
FROM '._DB_PREFIX_.'product p
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl
|
||||
ON (p.id_product = pl.id_product)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON (p.`id_category_default` = cl.`id_category` AND pl.`id_lang` = cl.`id_lang`)
|
||||
LEFT JOIN '._DB_PREFIX_.'image i
|
||||
ON p.id_product = i.id_product
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il
|
||||
ON (i.`id_image` = il.`id_image`
|
||||
AND pl.`id_lang` = il.`id_lang`)
|
||||
LEFT JOIN '._DB_PREFIX_.'lang l
|
||||
ON (pl.id_lang = l.id_lang)
|
||||
WHERE l.`active` = 1
|
||||
AND p.`active` = 1
|
||||
'.(count($exclude_categories) > 0? ' AND p.id_category_default NOT IN ('.implode(', ', $exclude_categories).')': '').'
|
||||
'.(Configuration::get('GSITEMAP_ALL_PRODUCTS') ? '' : 'HAVING level_depth IS NOT NULL').'
|
||||
ORDER BY pl.id_product, pl.id_lang ASC
|
||||
');*/
|
||||
|
||||
$tmp = NULL;
|
||||
$res = NULL;
|
||||
|
||||
$tmp = null;
|
||||
$res = null;
|
||||
if (count($products) > 0) {
|
||||
foreach($products as $product) {
|
||||
if ($tmp == $product['id_product']) {
|
||||
foreach($products as $v) {
|
||||
$productObj = new Product($v);
|
||||
|
||||
$product = (array)$productObj;
|
||||
|
||||
if ($tmp == $product['id']) {
|
||||
$res[$tmp]['images'][] = array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']);
|
||||
} else {
|
||||
$tmp = $product['id_product'];
|
||||
$tmp = $product['id'];
|
||||
$res[$tmp] = $product;
|
||||
unset($res[$tmp]['id_image'], $res[$tmp]['legend_image']);
|
||||
$res[$tmp]['images'][] = array('id_image' => $product['id_image'], 'legend_image' => $product['legend_image']);
|
||||
@ -274,8 +180,8 @@ XML;
|
||||
if (($priority = 0.7 - ($product['level_depth'] / 10)) < 0.1) {
|
||||
$priority = 0.1;
|
||||
}
|
||||
|
||||
$tmpLink = $link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $product['category'], $product['ean13'], (int) $product['id_lang']);
|
||||
|
||||
$tmpLink = $link->getProductLink((int)$product['id'], $product['link_rewrite'][1], $product['category'], $product['ean13']);
|
||||
$sitemap = $this->_addSitemapNode($xml, htmlspecialchars($tmpLink), $priority, 'weekly', substr($product['date_upd'], 0, 10));
|
||||
$sitemap = $this->_addSitemapNodeImage($sitemap, $product);
|
||||
}
|
||||
@ -284,15 +190,15 @@ XML;
|
||||
/* Add classic pages (contact, best sales, new products...) */
|
||||
$pages = array(
|
||||
'authentication' => true,
|
||||
'best-sales' => false,
|
||||
//'best-sales' => false,
|
||||
'contact-form' => true,
|
||||
'discount' => false,
|
||||
'index' => false,
|
||||
'manufacturer' => false,
|
||||
'new-products' => false,
|
||||
'prices-drop' => false,
|
||||
'supplier' => false,
|
||||
'store' => false,
|
||||
//'discount' => false,
|
||||
'index' => true,
|
||||
//'manufacturer' => false,
|
||||
//'new-products' => false,
|
||||
//'prices-drop' => false,
|
||||
//'supplier' => false,
|
||||
//'store' => false,
|
||||
);
|
||||
|
||||
// Don't show suppliers and manufacturers if they are disallowed
|
||||
@ -305,20 +211,15 @@ XML;
|
||||
}
|
||||
|
||||
// Generate nodes for pages
|
||||
$ssl = true;
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS')) {
|
||||
foreach($pages as $page => $enable) {
|
||||
if ($enable === true) {
|
||||
foreach($langs as $lang) {
|
||||
$this->_addSitemapNode($xml, $link->getPageLink($page.'.php', $ssl, $lang['id_lang']), '0.5', 'monthly');
|
||||
}
|
||||
foreach($pages as $page => $ssl) {
|
||||
foreach($langs as $lang) {
|
||||
$this->_addSitemapNode($xml, $link->getPageLink($page.'.php', $ssl, $lang['id_lang']), '0.5', 'monthly');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($pages as $page => $enable) {
|
||||
if ($enable === true) {
|
||||
$this->_addSitemapNode($xml, $link->getPageLink($page.'.php', $ssl), '0.5', 'monthly');
|
||||
}
|
||||
foreach($pages as $page => $ssl) {
|
||||
$this->_addSitemapNode($xml, $link->getPageLink($page.'.php', $ssl), '0.5', 'monthly');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user