mrweb Posted August 9, 2023 Share Posted August 9, 2023 Hi Prestashop 1.7.8.0 I'd like to all the products list in the sitemap.tpl Example on demo : https://hollow-office.demo.prestashop.com/en/sitemap In this page, we have already the list of the categories is it possible to display the list of all the products with links in 1 new column and/or display the products by category Thanks for your help Link to comment Share on other sites More sharing options...
AddWeb Solution Posted August 10, 2023 Share Posted August 10, 2023 Hi, Take a backup of sitemap.tpl file before making any changes. In sitemap.tpl file, you might need to add the code like below to add have div inside container-fluid div to show the product list in new column. <div class="row sitemap-products col-xs-12"> <div class="col-md-12"> <h2>{$products_title}</h2> <ul> {foreach from=$products item=product} <li> <a href="{$product.link}" title="{$product.name}">{$product.name}</a> </li> {/foreach} </ul> </div> </div> In this snippet, replace {$products_title} with a string that you want to use as the title for the product list section in your sitemap. This title will be displayed above the list of products. The actual product names are fetched from the {$product.name} variable within the {foreach} loop. After making changes, clear the cache and check. Let me know If this works! Thanks! 1 Link to comment Share on other sites More sharing options...
mrweb Posted August 10, 2023 Author Share Posted August 10, 2023 Hi Thanks for your fast answer I placed your code in sitemap.tpl In the code I see this : <div class="row sitemap-products col-xs-12"> <div class="col-md-12"> <h2></h2> <ul> </ul> </div> </div> The loop is empty, no products display I attach the file I have tried with this also, the result is empty again <div id="products"> <div class="products row"> {foreach from=$products item="product"} {include file="catalog/_partials/miniatures/product.tpl" product=$product} {/foreach} </div> </div> Thanks for your help sitemap.tpl Link to comment Share on other sites More sharing options...
AddWeb Solution Posted August 10, 2023 Share Posted August 10, 2023 Hi, May be in custom controller, you need to fetch the product data and assign it to the template. Sample code to be added in custom controller class MyCustomSitemapModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); // Fetch product data. $products = $this->getProducts(); $this->context->smarty->assign(array( 'products' => $products, 'products_title' => 'Products', // Set the title )); $this->setTemplate('sitemap.tpl'); } // Method to fetch product data private function getProducts() { $products = array(); $productList = Product::getProducts($this->context->language->id, 0, 0, 'id_product', 'ASC'); // This fetches a list of products foreach ($productList as $product) { $products[] = array( 'name' => $product['name'], 'link' => $this->context->link->getProductLink($product['id_product']) ); } return $products; } } After we get the product data from the controller, we can use it in tpl to display. Let me know If this helps! Thanks! Link to comment Share on other sites More sharing options...
mrweb Posted August 10, 2023 Author Share Posted August 10, 2023 I just add your code in /www/controllers/front/ProductController.php but it's still empty in the sitemap What is "custom controller" please ? Thanks for your help Link to comment Share on other sites More sharing options...
AddWeb Solution Posted August 10, 2023 Share Posted August 10, 2023 26 minutes ago, mrweb said: I just add your code in /www/controllers/front/ProductController.php but it's still empty in the sitemap What is "custom controller" please ? Thanks for your help Custom controller is the controller that you need to create newly in order to make any changes. Link to comment Share on other sites More sharing options...
mrweb Posted August 10, 2023 Author Share Posted August 10, 2023 Ok but where I add your code ? In /www/controllers/front/ProductController.php it's not working Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now