Jump to content

homefeatured pagination


combinesom

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!

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

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
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...
  • 2 weeks later...
  • 6 months later...

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 [email protected] 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 <[email protected]>
*  @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}

Link to comment
Share on other sites

  • 8 months later...
  • 1 month later...
  • 5 months later...
  • 2 months later...
  • 9 months later...
  • 3 months later...
  • 3 years later...
  • 9 months later...

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...