From 6664fc8dac424153bb0edb4143038a939272b014 Mon Sep 17 00:00:00 2001 From: sanctusmob Date: Wed, 6 Mar 2024 10:47:41 +0200 Subject: [PATCH 1/2] re-add-supplier-support Manufacturers and Suppliers was removed at some point. The manufacturers was re add. The Suppliers was not. --- gsitemap.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/gsitemap.php b/gsitemap.php index 84fa70b..780ac7c 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -78,6 +78,7 @@ public function __construct() 'product', 'category', 'manufacturer', + 'supplier', 'cms', 'module', ]; @@ -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, @@ -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(); } @@ -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); } @@ -588,7 +592,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 . @@ -633,6 +638,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 * From 99d632bd2307ccbcbadfaa3539c987a890f84500 Mon Sep 17 00:00:00 2001 From: sanctusmob Date: Wed, 6 Mar 2024 11:00:47 +0200 Subject: [PATCH 2/2] Fix format add comments --- gsitemap.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gsitemap.php b/gsitemap.php index 780ac7c..9cdf71e 100755 --- a/gsitemap.php +++ b/gsitemap.php @@ -209,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(); } @@ -221,10 +221,8 @@ 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); } @@ -592,8 +590,7 @@ 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 . @@ -637,7 +634,18 @@ protected function getManufacturerLink(&$link_sitemap, $lang, &$index, &$i, $id_ return true; } - + + /** + * return the link elements for the supplier 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_supplier supplier object identifier + * + * @return bool + */ protected function getSupplierLink(&$link_sitemap, $lang, &$index, &$i, $id_supplier = 0) { $link = new Link();