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 add supplier support #180

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
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
65 changes: 61 additions & 4 deletions gsitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function __construct()
'product',
'category',
'manufacturer',
'supplier',
'cms',
'module',
];
Expand Down Expand Up @@ -108,6 +109,7 @@ public function install()
'GSITEMAP_PRIORITY_PRODUCT' => 0.9,
'GSITEMAP_PRIORITY_CATEGORY' => 0.8,
'GSITEMAP_PRIORITY_MANUFACTURER' => 0.7,
'GSITEMAP_PRIORITY_SUPPLIER' => 0.7,
'GSITEMAP_PRIORITY_CMS' => 0.7,
'GSITEMAP_FREQUENCY' => 'weekly',
'GSITEMAP_LAST_EXPORT' => false,
Expand Down Expand Up @@ -207,7 +209,7 @@ public function getContent()
$this->emptySitemap();
$this->createSitemap();

/* If no posted form and the variable [continue] is found in the HTTP request variable keep creating sitemap */
/* If no posted form and the variable [continue] is found in the HTTP request variable keep creating sitemap */
} elseif (Tools::getValue('continue')) {
$this->createSitemap();
}
Expand All @@ -219,8 +221,10 @@ public function getContent()

/* Get Meta pages and remove index page it's managed elsewhere (@see $this->getHomeLink()) */
/* We also remove all pages that are blocked in core robots.txt file */
$store_metas = array_filter(Meta::getMetasByIdLang(
(int) $this->context->cookie->id_lang),
$store_metas = array_filter(
Meta::getMetasByIdLang(
(int) $this->context->cookie->id_lang
),
function ($meta) {
return $meta['page'] != 'index' && !in_array($meta['page'], $this->disallow_controllers);
}
Expand Down Expand Up @@ -584,7 +588,8 @@ protected function getManufacturerLink(&$link_sitemap, $lang, &$index, &$i, $id_
}

// Get manufacturers IDs
$manufacturers_id = Db::getInstance()->ExecuteS('SELECT m.`id_manufacturer` FROM `' . _DB_PREFIX_ . 'manufacturer` m
$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`' .
' INNER JOIN `' . _DB_PREFIX_ . 'manufacturer_shop` ms ON m.`id_manufacturer` = ms.`id_manufacturer`' .
' WHERE m.`active` = 1 AND m.`id_manufacturer` >= ' . (int) $id_manufacturer .
Expand Down Expand Up @@ -627,6 +632,58 @@ protected function getManufacturerLink(&$link_sitemap, $lang, &$index, &$i, $id_
return true;
}

protected function getSupplierLink(&$link_sitemap, $lang, &$index, &$i, $id_supplier = 0)
{
$link = new Link();
if (method_exists('ShopUrl', 'resetMainDomainCache')) {
ShopUrl::resetMainDomainCache();
}

// Get suppliers IDs
$suppliers_id = Db::getInstance()->ExecuteS(
'SELECT m.`id_supplier` FROM `' . _DB_PREFIX_ . 'supplier` m
INNER JOIN `' . _DB_PREFIX_ . 'supplier_lang` ml on m.`id_supplier` = ml.`id_supplier`' .
' INNER JOIN `' . _DB_PREFIX_ . 'supplier_shop` ms ON m.`id_supplier` = ms.`id_supplier`' .
' WHERE m.`active` = 1 AND m.`id_supplier` >= ' . (int) $id_supplier .
' AND ms.`id_shop` = ' . (int) $this->context->shop->id .
' AND ml.`id_lang` = ' . (int) $lang['id_lang'] .
' ORDER BY m.`id_supplier` ASC'
);

// Process each supplier and add it to list of links that will be further "converted" to XML and added to the sitemap
foreach ($suppliers_id as $supplier_id) {
$supplier = new Supplier((int) $supplier_id['id_supplier'], $lang['id_lang']);
$url = $link->getSupplierLink($supplier, urlencode($supplier->link_rewrite), $lang['id_lang']);

$image_link = $this->context->link->getSupplierImageLink((int) $supplier->id, ImageType::getFormattedName('medium'));
$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;

$supplier_image = [
'link' => $image_link,
];

if (!$this->addLinkToSitemap($link_sitemap, [
'type' => 'supplier',
'page' => 'supplier',
'lastmod' => $supplier->date_upd,
'link' => $url,
'image' => $supplier_image,
], $lang['iso_code'], $index, $i, $supplier_id['id_supplier'])) {
return false;
}

unset($image_link);
}

return true;
}

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