Jump to content
combinesom

homefeatured pagination

Recommended Posts

I have modified Homefeatured.php file so that show all the products of its category on the first page. The problem is that I can not do the pagination to the list of displayed products. Can anyone tell me what's next? Oh, and there is still a problem with the display of thumbnails.

I was changed in homefeatured.php

   function hookHome($params)
   {
       global $smarty;

       $category = new Category(1);
       $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
       $products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
       $smarty->assign(array('products' => $products, 'homeSize' => Image::getSize('home')));

       return $this->display(__FILE__, 'homefeatured.tpl');
   }


to:

function hookHome($params)
   {
       global $smarty;

       $category = new Category(1);
       $nb = intval(Configuration::get('HOME_FEATURED_NBR'));
       $products = Product::getProducts($params['cookie']->id_lang, 0, NULL, 'name', 'ASC', false, true);
       include(dirname(__FILE__).'/pagination.php');

       $smarty->assign(array('products' => $products, 'homeSize' => Image::getSize('home')));

       return $this->display(__FILE__, 'homefeatured.tpl');
   }



what's next?
Please help me!

Share this post


Link to post
Share on other sites

Problem already solved. I modified the following files:

modules/homefeatured/homefeatured.tpl - delete all content.

modify index.php in root:

<?php

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

if(intval(Configuration::get('PS_REWRITING_SETTINGS')) === 1)
   $rewrited_url = __PS_BASE_URI__;

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


$smarty->assign('HOOK_HOME', Module::hookExec('home'));
$smarty->display(_PS_THEME_DIR_.'index.tpl');
include(dirname(__FILE__).'/homefeaturedto.php');

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


?>



Create homefeaturedto.php in the root

<?php
include(dirname(__FILE__).'/product-sort.php');
            $category = new Category(1);
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);

       $smarty->assign(array(
           'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL,
           'id_category' => intval($category->id),
           'id_category_parent' => intval($category->id_parent),
           'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
           'path' => Tools::getPath(intval($category->id), $category->name)
       ));


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

?> 



create homefeaturedto.tpl in your themes:

<!-- 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}
<!-- Pagination -->
   {if $products}
       {include file=$tpl_dir./pagination.tpl}
   {/if}

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




I know that a better solution would be to create a modified module homefeatured, but that's beyond me ... I finished the economies and not IT. For sure will be a programmer who embrace it.

Share this post


Link to post
Share on other sites

anyone know how i could use this in prestashop 1.4?

i have made modifications in this code and i have get to work in prestashop 1.3, but not in prestashop 1.4

Share this post


Link to post
Share on other sites

prestashop 1.4
modify modules/homefeatured/homefeatured.php

function hookHome($params)
   {
       global $smarty;

       $category = new Category(1, Configuration::get('PS_LANG_DEFAULT'));
       $nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
       $products = $category->getProducts((int)($params['cookie']->id_lang), 1, ($nb ? $nb : 10));
       $smarty->assign(array(
       'products' => $products,
       'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
       'homeSize' => Image::getSize('home')));

       return $this->display(__FILE__, 'homefeatured.tpl');
   }


to

function hookHome($params)
   {
       global $smarty;


       $controller = new FrontController();
       $controller->productSort();
       $category = new Category(1, Configuration::get('PS_LANG_DEFAULT'));
       $nbProducts = $category->getProducts(NULL, NULL, NULL, $controller->orderBy, $controller->orderWay, true);
       $controller->pagination($nbProducts);

       $smarty->assign('nb_products', $nbProducts);
       $products = $category->getProducts((int)($params['cookie']->id_lang), intval($controller->p), intval($controller->n), $controller->orderBy, $controller->orderWay);
       $smarty->assign(array(
       'products' => $products,
       'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
       'homeSize' => Image::getSize('home'),
       'id_category' => intval($category->id),
   'id_category_parent' => intval($category->id_parent),
   'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)),
       'path' => Tools::getPath(intval($category->id), $category->name)
       ));

       return $this->display(__FILE__, 'homefeatured.tpl');
   }


modify modules/homefeatured/homefeatured.tpl
Add

{if isset($products) AND $products}
   {if isset($smarty.get.id_category) && $smarty.get.id_category && isset($category)}
       {assign var='requestPage' value=$link->getPaginationLink('category', $category, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink('category', $category, true, false, false, true)}
   {else}
       {assign var='requestPage' value=$link->getPaginationLink(false, false, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink(false, false, true, false, false, true)}
   {/if}
   <!-- Pagination -->

   {if $start!=$stop}

       {if $p != 1}
           {assign var='p_previous' value=$p-1}
goPage($requestPage, $p_previous)}">« {l s='Previous'}
       {else}
« {l s='Previous'}
       {/if}
       {if $start>3}
goPage($requestPage, 1)}">1
...
       {/if}
       {section name=pagination start=$start loop=$stop+1 step=1}
           {if $p == $smarty.section.pagination.index}
{$p|escape:'htmlall':'UTF-8'}
           {else}
goPage($requestPage, $smarty.section.pagination.index)}">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}
           {/if}
       {/section}
       {if $pages_nb>$stop+2}
...
goPage($requestPage, $pages_nb)}">{$pages_nb|intval}
       {/if}
       {if $pages_nb > 1 AND $p != $pages_nb}
           {assign var='p_next' value=$p+1}
goPage($requestPage, $p_next)}">{l s='Next'} »
       {else}
{l s='Next'} »
       {/if}

   {/if}
   {if $nb_products > 10}
       <form action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get" class="pagination">


               {if isset($query) AND $query}<input type="hidden" name="search_query" value="{$query|escape:'htmlall':'UTF-8'}" />{/if}
               {if isset($tag) AND $tag AND !is_array($tag)}<input type="hidden" name="tag" value="{$tag|escape:'htmlall':'UTF-8'}" />{/if}
               <input type="submit" class="button_mini" value="{l s='OK'}" />
{l s='items:'}

               {assign var="lastnValue" value="0"}
               {foreach from=$nArray item=nValue}
                   {if $lastnValue <= $nb_products}
{$nValue|escape:'htmlall':'UTF-8'}
                   {/if}
                   {assign var="lastnValue" value=$nValue}
               {/foreach}

               {if is_array($requestNb)}
                   {foreach from=$requestNb item=requestValue key=requestKey}
                       {if $requestKey != 'requestUrl'}
                           <input type="hidden" name="{$requestKey|escape:'htmlall':'UTF-8'}" value="{$requestValue|escape:'htmlall':'UTF-8'}" />
                       {/if}
                   {/foreach}
               {/if}

       </form>
   {/if}

   <!-- /Pagination -->
{/if}

  • Like 1

Share this post


Link to post
Share on other sites

Works fine, but i have error:

Warning: Function hideCategoryPosition() is deprecated in \htdocs\shop\modules\homefeatured\homefeatured.php on line 111
in \htdocs\shop\classes\Tools.php on line 1803

Share this post


Link to post
Share on other sites

Thanks combinesom for sharing your coding. I have applied them on my site (prestashop version 1.3) and it works, except for one part. My homefeatured module was previously modified in its css to display products in 3 columns. Now my pagination is adopting its css and the elements are displayed in blocks of 3 column. I have attached a photo. I believe this is because of the coding in homefeaturedto.tpl:

<!-- Pagination -->
{if $products}
{include file=$tpl_dir./pagination.tpl}
{/if}

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

Can anyone advice me how to exclude the pagination from adopting the css coding of the homefeatured module? THANK YOU!!!

47394_O1ZJm2jwCv3oL7cgFukM_t

Share this post


Link to post
Share on other sites

Create your new pagination.tpl file and name it paginationto.tpl. Then change name of classes inside them and adjust to your page styles.

Share this post


Link to post
Share on other sites

Prestashop 1.5.3.1

 

homefeatured.tpl

<div id="featured-products_block_center" class="block products_block clearfix">
{if isset($products) AND $products}
·
·
·
{/if}
</div>
<div class="content_sortPagiBar homefeaturedPaged">
   {include file="../../paginationHomeFeatured.tpl"}
</div>

 

paginationHomeFeatured.tpl

{*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* 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 http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2012 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
{if isset($no_follow) AND $no_follow}
{assign var='no_follow_text' value='rel="nofollow"'}
{else}
{assign var='no_follow_text' value=''}
{/if}
{if isset($p) AND $p}
 {assign var='requestPage' value=$base_dir|cat:'index.php'}
 {assign var='requestNb' value=$base_dir|cat:'index.php'}

<!-- Pagination -->
<div id="pagination" class="pagination">
{if $start!=$stop}
 <ul class="pagination">
 {if $p != 1}
  {assign var='p_previous' value=$p-1}
  <li id="pagination_previous"><a {$no_follow_text} href="{$link->goPage($requestPage, $p_previous)}">« {l s='Previous'}</a></li>
 {else}
  <li id="pagination_previous" class="disabled"><span>« {l s='Previous'}</span></li>
 {/if}
 {if $start==3}
  <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
  <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 2)}">2</a></li>
 {/if}
 {if $start==2}
  <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
 {/if}
 {if $start>3}
  <li><a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">1</a></li>
  <li class="truncate">...</li>
 {/if}
 {section name=pagination start=$start loop=$stop+1 step=1}
  {if $p == $smarty.section.pagination.index}
   <li class="current"><span>{$p|escape:'htmlall':'UTF-8'}</span></li>
  {else}
   <li><a {$no_follow_text} href="{$link->goPage($requestPage, $smarty.section.pagination.index)}">{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}</a></li>
  {/if}
 {/section}
 {if $pages_nb>$stop+2}
  <li class="truncate">...</li>
  <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
 {/if}
 {if $pages_nb==$stop+1}
  <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
 {/if}
 {if $pages_nb==$stop+2}
  <li><a href="{$link->goPage($requestPage, $pages_nb-1)}">{$pages_nb-1|intval}</a></li>
  <li><a href="{$link->goPage($requestPage, $pages_nb)}">{$pages_nb|intval}</a></li>
 {/if}
 {if $pages_nb > 1 AND $p != $pages_nb}
  {assign var='p_next' value=$p+1}
  <li id="pagination_next"><a {$no_follow_text} href="{$link->goPage($requestPage, $p_next)}">{l s='Next'} »</a></li>
 {else}
  <li id="pagination_next" class="disabled"><span>{l s='Next'} »</span></li>
 {/if}
 </ul>
{/if}
{if $nb_products > $products_per_page}
 <form action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get" class="pagination">
  <p>
   {if isset($search_query) AND $search_query}<input type="hidden" name="search_query" value="{$search_query|escape:'htmlall':'UTF-8'}" />{/if}
   {if isset($tag) AND $tag AND !is_array($tag)}<input type="hidden" name="tag" value="{$tag|escape:'htmlall':'UTF-8'}" />{/if}
   <input type="submit" class="button_mini" value="{l s='OK'}" />
   <label for="nb_item">{l s='items:'}</label>
   <select name="n" id="nb_item">
   {assign var="lastnValue" value="0"}
   {foreach from=$nArray item=nValue}
 {if $lastnValue <= $nb_products}
  <option value="{$nValue|escape:'htmlall':'UTF-8'}" {if $n == $nValue}selected="selected"{/if}>{$nValue|escape:'htmlall':'UTF-8'}</option>
 {/if}
 {assign var="lastnValue" value=$nValue}
   {/foreach}
   </select>
   {if is_array($requestNb)}
 {foreach from=$requestNb item=requestValue key=requestKey}
  {if $requestKey != 'requestUrl'}
   <input type="hidden" name="{$requestKey|escape:'htmlall':'UTF-8'}" value="{$requestValue|escape:'htmlall':'UTF-8'}" />
  {/if}
 {/foreach}
   {/if}
  </p>
 </form>
{/if}
</div>
<!-- /Pagination -->
{/if}

Share this post


Link to post
Share on other sites

Homefeatured pagination Prestashop 1.6

http://tinyurl.com/pe5m8ma

 

 

ps: link is ok now, sorry

[]'s

 

Muchas gracias, pero he copiado el código que indica y soy incapaz de que me haga algo, sigue sin que me funcione la paginación en homefeatured. Estoy usando la versión 1.6 de prestashop

Share this post


Link to post
Share on other sites
On 9/2/2014 at 11:56 PM, p4t0X said:

 

Homefeatured pagination Prestashop 1.6

http://tinyurl.com/pe5m8ma

 

 

ps: link is ok now, sorry

[]'s

thank you worked, but it is not random like before, it acts as normal category.. how to make homefeatured with pagination or better with infinite scroll and random?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More