Skip to content

Commit

Permalink
Merge pull request #173 from Uhor/add-manu-list
Browse files Browse the repository at this point in the history
Re added manufacturers list
  • Loading branch information
Hlavtox committed Jan 5, 2024
2 parents 3ca761b + 698c55a commit a25fce1
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.xml
Expand Up @@ -2,7 +2,7 @@
<module>
<name>gsitemap</name>
<displayName><![CDATA[Google sitemap]]></displayName>
<version><![CDATA[4.3.1]]></version>
<version><![CDATA[4.4.0]]></version>
<description><![CDATA[Generate your Google sitemap file]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[seo]]></tab>
Expand Down
73 changes: 70 additions & 3 deletions gsitemap.php
Expand Up @@ -60,7 +60,7 @@ public function __construct()
{
$this->name = 'gsitemap';
$this->tab = 'checkout';
$this->version = '4.3.1';
$this->version = '4.4.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
Expand All @@ -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,
'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' => '',
'GSITEMAP_PRIORITY_CMS' => '',
'GSITEMAP_FREQUENCY' => '',
'GSITEMAP_LAST_EXPORT' => '',
Expand Down Expand Up @@ -546,6 +549,70 @@ 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();
}

// 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`' .
' 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 .
' 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 = $this->context->link->getManufacturerImageLink((int) $manufacturer->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;

$manufacturer_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' => $manufacturer_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 All @@ -563,8 +630,8 @@ protected function getCmsLink(&$link_sitemap, $lang, &$index, &$i, $id_cms = 0)
if (method_exists('ShopUrl', 'resetMainDomainCache')) {
ShopUrl::resetMainDomainCache();
}
$cmss_id = Db::getInstance()->ExecuteS('SELECT c.`id_cms` FROM `' . _DB_PREFIX_ . 'cms` c INNER JOIN `' . _DB_PREFIX_ . 'cms_lang` cl ON c.`id_cms` = cl.`id_cms` ' . ($this->tableColumnExists(_DB_PREFIX_ . 'supplier_shop') ? 'INNER JOIN `' . _DB_PREFIX_ . 'cms_shop` cs ON c.`id_cms` = cs.`id_cms` ' : '') . 'INNER JOIN `' . _DB_PREFIX_ . 'cms_category` cc ON c.id_cms_category = cc.id_cms_category AND cc.active = 1
WHERE c.`active` =1 AND c.`indexation` =1 AND c.`id_cms` >= ' . (int) $id_cms . ($this->tableColumnExists(_DB_PREFIX_ . 'supplier_shop') ? ' AND cs.id_shop = ' . (int) $this->context->shop->id : '') . ' AND cl.`id_lang` = ' . (int) $lang['id_lang'] . ' GROUP BY c.`id_cms` ORDER BY c.`id_cms` ASC');
$cmss_id = Db::getInstance()->ExecuteS('SELECT c.`id_cms` FROM `' . _DB_PREFIX_ . 'cms` c INNER JOIN `' . _DB_PREFIX_ . 'cms_lang` cl ON c.`id_cms` = cl.`id_cms` ' . 'INNER JOIN `' . _DB_PREFIX_ . 'cms_shop` cs ON c.`id_cms` = cs.`id_cms` ' . 'INNER JOIN `' . _DB_PREFIX_ . 'cms_category` cc ON c.id_cms_category = cc.id_cms_category AND cc.active = 1
WHERE c.`active` =1 AND c.`indexation` =1 AND c.`id_cms` >= ' . (int) $id_cms . ' AND cs.id_shop = ' . (int) $this->context->shop->id . ' AND cl.`id_lang` = ' . (int) $lang['id_lang'] . ' GROUP BY c.`id_cms` ORDER BY c.`id_cms` ASC');

if (is_array($cmss_id)) {
foreach ($cmss_id as $cms_id) {
Expand Down
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.1.2.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.3.4.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.4.4.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.5.1.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.6.neon
Expand Up @@ -7,3 +7,4 @@ parameters:
- '#Parameter \#1 \$idCategory of class Category constructor expects null, int given.#'
- '#Parameter \#2 \$idLang of class Category constructor expects null, int given.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.7.neon
Expand Up @@ -5,3 +5,4 @@ parameters:
ignoreErrors:
- '#Access to an undefined property Cookie\:\:\$id_lang.#'
- '#Parameter \#3 \$type of method LinkCore\:\:getCatImageLink\(\) expects null, string given.#'
- '#Parameter \#2 \$type of method LinkCore\:\:getManufacturerImageLink\(\) expects null, string given.#'
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.7.8.neon
Expand Up @@ -4,3 +4,4 @@ includes:
parameters:
ignoreErrors:
- '#Access to an undefined property Cookie\:\:\$id_lang.#'
- '#Parameter \#1 \$str of function strip_tags expects string, array<string> given.#'
35 changes: 35 additions & 0 deletions upgrade/upgrade-4.4.0.php
@@ -0,0 +1,35 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_4_4_0($object)
{
Configuration::updateValue('GSITEMAP_PRIORITY_MANUFACTURER', 0.7);

return true;
}

0 comments on commit a25fce1

Please sign in to comment.