Jump to content

how to set home page as list of my product


Recommended Posts

So basically, you want lots of new products instead of featured products? You could copy the code from new-products.php into index.php and the code from modules/homefeatured/homefeatured.tpl into index.tpl in your theme's directory to make the homepage display new products in the style of the featured products block. You can define how many new products you want by adding the following before line 11 of the new index.php:

$n = 24;

Link to comment
Share on other sites

Replace index.php in the root directory of PrestaShop with:

<?php 

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

include(dirname(__FILE__).'/product-sort.php');

$n = 24;

$nbProducts = intval(Product::getNewProducts(intval($cookie->id_lang), isset($p) ? intval($p) - 1 : NULL, isset($n) ? intval($n) : NULL, true));
include(dirname(__FILE__).'/pagination.php');

$smarty->assign(array(
   'homeSize' => Image::getSize('home'),
   'products' => Product::getNewProducts(intval($cookie->id_lang), intval($p) - 1, intval($n), false, $orderBy, $orderWay),
   'nbProducts' => intval($nbProducts)));

$smarty->display(_PS_THEME_DIR_.'index.tpl');

include(dirname(__FILE__).'/footer.php');

?>



and index.tpl in your theme's directory with:

<!-- MODULE Home Featured Products -->

{l s='New arrivals'}
   {if isset($products) AND $products}

           {assign var='liHeight' value=342}
           {assign var='nbItemsPerLine' value=4}
           {assign var='nbLi' value=$products|@count}
           {assign var='nbLines' value=$nbLi/$nbItemsPerLine|ceil}
           {assign var='ulHeight' value=$nbLines*$liHeight}

           {foreach from=$products item=product name=homeFeaturedProducts}

{$product.name|truncate:27:'...'|escape:'htmlall':'UTF-8'}

{$product.description_short|strip_tags|truncate:130:'...'}
getImageLink($product.link_rewrite, $product.id_image, 'home')}" height="{$homeSize.height}" width="{$homeSize.width}" alt="{$product.name|escape:html:'UTF-8'}" />


{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
{l s='View'}
                       {if ($product.quantity > 0 OR $product.allow_oosp) AND $product.customizable != 2}
{l s='Add to cart'}
                       {else}
{l s='Add to cart'}
                       {/if}


           {/foreach}


   {else}

{l s='No new arrivals'}
   {/if}

<!-- /MODULE Home Featured Products -->

Link to comment
Share on other sites

  • 1 month later...
  • 2 years later...

in this case you can modify homefeatured module, instead of featured products you can display new products.

in module php file instead of $category->getProducts - just use Product::getNewProducts function

after little modification of the .tpl file - everything will work as you expected

Link to comment
Share on other sites

Thank you. I have tried your solution and it works for the main part, but the product-sort.tpl and nbr-product-page.tpl

as they are used in the new-products.tpl (/index.php?controller=new-products) are not working when used in homefeatured.tpl. (One does not get the the sorting functionality e.g. "product-per-page" and "ascending-descending"  like in new-products.php)

Edited by TwoPenceCritter (see edit history)
Link to comment
Share on other sites

now i see what you exactly expect, you want the same page with the same features as you've got in new products page, but instead of separate page - you want to display everything on homepage. well, it will be a bit problematic in method that i suggested, mainly because it use different query to get products from database

Link to comment
Share on other sites

That is precisely what I ment.

I already tried to use new-products.tpl as index.tpl and a part NewProductsController.php as index.php. But of course it is not working. Also I tried to use new-products.tpl as homefeatured.tpl and make an include of NewProductsController.php in homefeatured.php with no luck. Further I tried to make a redirect in .htacces to redirect index to new products.php/NewProductsController.php but this was giving me a redirect loop error in the browser.

Link to comment
Share on other sites

So far I found a temporary solution in 1.5.4  with a simple redirect. To redirect the homepage to the new-products controller, use the file controllers/front/IndexController.php and find public function initContent() (around line 29) and paste somewhere inside the curly brackets the code 

tools::redirect('index.php?controller=new-products');

Well, if someone knows how to modify the homefeatured module not only to show new products but also to have pagination and a sort option for the products, go ahead and let us know.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...