Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re added manufacturers list #173

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions gsitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function __construct()
'meta',
'product',
'category',
'manufacturer',
'cms',
'module',
];
Expand Down Expand Up @@ -106,6 +107,7 @@ public function install()
'GSITEMAP_PRIORITY_HOME' => 1.0,
'GSITEMAP_PRIORITY_PRODUCT' => 0.9,
'GSITEMAP_PRIORITY_CATEGORY' => 0.8,
'GSITEMAP_PRIORITY_MANUFACTURER' => 0.7,
Uhor marked this conversation as resolved.
Show resolved Hide resolved
'GSITEMAP_PRIORITY_CMS' => 0.7,
'GSITEMAP_FREQUENCY' => 'weekly',
'GSITEMAP_LAST_EXPORT' => false,
Expand Down Expand Up @@ -155,6 +157,7 @@ public function uninstall()
'GSITEMAP_PRIORITY_HOME' => '',
'GSITEMAP_PRIORITY_PRODUCT' => '',
'GSITEMAP_PRIORITY_CATEGORY' => '',
'GSITEMAP_PRIORITY_MANUFACTURER' => '',
Uhor marked this conversation as resolved.
Show resolved Hide resolved
'GSITEMAP_PRIORITY_CMS' => '',
'GSITEMAP_FREQUENCY' => '',
'GSITEMAP_LAST_EXPORT' => '',
Expand Down Expand Up @@ -546,6 +549,73 @@ protected function getCategoryLink(&$link_sitemap, $lang, &$index, &$i, $id_cate
return true;
}

/**
* return the link elements for the manufacturer object
*
* @param array $link_sitemap contain all the links for the Google Sitemap file to be generated
* @param array $lang language of link to add
* @param int $index index of the current Google Sitemap file
* @param int $i count of elements added to sitemap main array
* @param int $id_manufacturer manufacturer object identifier
*
* @return bool
*/
protected function getManufacturerLink(&$link_sitemap, $lang, &$index, &$i, $id_manufacturer = 0)
{
$link = new Link();
if (method_exists('ShopUrl', 'resetMainDomainCache')) {
ShopUrl::resetMainDomainCache();
}
Uhor marked this conversation as resolved.
Show resolved Hide resolved

// Get manufacturers IDs
$manufacturers_id = Db::getInstance()->ExecuteS('SELECT m.`id_manufacturer` FROM `' . _DB_PREFIX_ . 'manufacturer` m
INNER JOIN `' . _DB_PREFIX_ . 'manufacturer_lang` ml on m.`id_manufacturer` = ml.`id_manufacturer`' .
($this->tableColumnExists(_DB_PREFIX_ . 'manufacturer_shop') ? ' INNER JOIN `' . _DB_PREFIX_ . 'manufacturer_shop` ms ON m.`id_manufacturer` = ms.`id_manufacturer` ' : '').
Uhor marked this conversation as resolved.
Show resolved Hide resolved
' WHERE m.`active` = 1 AND m.`id_manufacturer` >= ' . (int)$id_manufacturer.
($this->tableColumnExists(_DB_PREFIX_ . 'manufacturer_shop') ? ' AND ms.`id_shop` = ' . (int)$this->context->shop->id : '').
' AND ml.`id_lang` = ' . (int)$lang['id_lang'].
' ORDER BY m.`id_manufacturer` ASC'
);

// Process each manufacturer and add it to list of links that will be further "converted" to XML and added to the sitemap
foreach ($manufacturers_id as $manufacturer_id) {
$manufacturer = new Manufacturer((int) $manufacturer_id['id_manufacturer'], $lang['id_lang']);
$url = $link->getManufacturerLink($manufacturer, urlencode($manufacturer->link_rewrite), $lang['id_lang']);

$image_link = 'http'.(Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE') ? 's' : '').'://'.Tools::getMediaServer(_THEME_MANU_DIR_)._THEME_MANU_DIR_.((file_exists(_PS_MANU_IMG_DIR_.'/'.(int)$manufacturer->id.'-manu_default.jpg')) ? (int)$manufacturer->id.'-manu_default' : $lang['iso_code'].'-default-medium_default').'.jpg';
Uhor marked this conversation as resolved.
Show resolved Hide resolved
$image_link = (!in_array(rtrim(Context::getContext()->shop->virtual_uri, '/'), explode('/', $image_link))) ? str_replace([
'https',
Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri,
], [
'http',
Context::getContext()->shop->domain . Context::getContext()->shop->physical_uri . Context::getContext()->shop->virtual_uri,
], $image_link) : $image_link;

$manifacturer_image = [];
if (isset($image_link)) {
$manifacturer_image = [
'title_img' => htmlspecialchars(strip_tags($manufacturer->name)),
'caption' => htmlspecialchars(strip_tags($manufacturer->short_description)),
'link' => $image_link,
];
}

if (!$this->addLinkToSitemap($link_sitemap, [
'type' => 'manufacturer',
'page' => 'manufacturer',
'lastmod' => $manufacturer->date_upd,
'link' => $url,
'image' => $manifacturer_image
], $lang['iso_code'], $index, $i, $manufacturer_id['id_manufacturer'])) {
return false;
}

unset($image_link);
}

return true;
}

/**
* return the link elements for the CMS object
*
Expand Down