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

Add manufacturers and suppliers list to sitemap #6160

Merged
merged 1 commit into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions classes/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,43 @@ public static function getManufacturers($get_nb_products = false, $id_lang = 0,
return $manufacturers;
}

/**
* List of manufacturers
*
* @param int $id_lang Specify the id of the language used
*
* @return array Manufacturers lite tree
*/
public static function getLiteManufacturersList($id_lang = null, $format = 'default')
{
$id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang;

$manufacturers_list = array();
$manufacturers = Manufacturer::getManufacturers($id_lang, true);
if ($manufacturers && count($manufacturers)) {
foreach ($manufacturers as $manufacturer) {
if ($format === 'sitemap') {
$manufacturers_list[] = array(
'id' => 'manufacturer-page-'.(int)$manufacturer['id_manufacturer'],
'label' => $manufacturer['name'],
'url' => Context::getContext()->link->getManufacturerLink($manufacturer['id_manufacturer'], $manufacturer['link_rewrite']),
'children' => Array()
);
} else {
$manufacturers_list[] = array(
'id' => (int)$manufacturer['id_manufacturer'],
'link' => Context::getContext()->link->getManufacturerLink($manufacturer['id_manufacturer'], $manufacturer['link_rewrite']),
'name' => $manufacturer['name'],
'desc'=> $manufacturer['description'],
'children' => Array()
);
}
}
}

return $manufacturers_list;
}

/**
* Return name from id
*
Expand Down
37 changes: 37 additions & 0 deletions classes/Supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,43 @@ public static function getSuppliers($get_nb_products = false, $id_lang = 0, $act
return $suppliers;
}

/**
* List of suppliers
*
* @param int $id_lang Specify the id of the language used
*
* @return array Suppliers lite tree
*/
public static function getLiteSuppliersList($id_lang = null, $format = 'default')
{
$id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang;

$suppliers_list = array();
$suppliers = Supplier::getSuppliers(false, $id_lang, true);
if ($suppliers && count($suppliers)) {
foreach ($suppliers as $supplier) {
if ($format === 'sitemap') {
$suppliers_list[] = array(
'id' => 'supplier-page-'.(int)$supplier['id_supplier'],
'label' => $supplier['name'],
'url' => Context::getContext()->link->getSupplierLink($supplier['id_supplier'], $supplier['link_rewrite']),
'children' => Array()
);
} else {
$suppliers_list[] = array(
'id' => (int)$supplier['id_supplier'],
'link' => Context::getContext()->link->getSupplierLink($supplier['id_supplier'], $supplier['link_rewrite']),
'name' => $supplier['name'],
'desc'=> $supplier['description'],
'children' => Array()
);
}
}
}

return $suppliers_list;
}

/**
* Return name from id
*
Expand Down
26 changes: 16 additions & 10 deletions controllers/front/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,23 @@ public function getTemplateVarSitemap()
];
}

$catalog['manufacturer'] = [
'id' => 'manufacturer-page',
'label' => $this->trans('Manufacturers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('manufacturer'),
];
if (Configuration::get('PS_DISPLAY_SUPPLIERS')) {
$manufacturers = Manufacturer::getLiteManufacturersList($this->context->language->id, 'sitemap');
$catalog['manufacturer'] = [
'id' => 'manufacturer-page',
'label' => $this->trans('Manufacturers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('manufacturer'),
'children' => $manufacturers,
];

$catalog['supplier'] = [
'id' => 'supplier-page',
'label' => $this->trans('Suppliers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('supplier'),
];
$suppliers = Supplier::getLiteSuppliersList($this->context->language->id, 'sitemap');
$catalog['supplier'] = [
'id' => 'supplier-page',
'label' => $this->trans('Suppliers', array(), 'Shop.Theme.Catalog'),
'url' => $this->context->link->getPageLink('supplier'),
'children' => $suppliers,
];
}

$categories = Category::getRootCategory()->recurseLiteCategTree(0, 0, null, null, 'sitemap');
$catalog['category'] = [
Expand Down