Paginate子类prestashop

时间:2018-05-30 11:51:51

标签: php prestashop smarty

我在prestashop下创建了一个分页子类别,但是遇到了一个困难。当我来到最后一页时,我有2个空页面被添加更多。这是我在CategoryController中的函数:

/**
 * Assigns subcategory templates variables
 */
protected function assignSubcategories()
{
    // Get pagination parameter
    $p = 1;
    if ( isset( $_GET['p'] ) && ! empty( $_GET['p'] ) ) {
        $p = (int) $_GET['p'];
    }

    if ($sub_categories = $this->category->getSubCategories($this->context->language->id)) {
        $this->context->smarty->assign(array(
            'subcategories_nb_total' => count($sub_categories),
            'subcategories_with_pagination' => $this->category->getSubCategoriesWithPagination( $this->context->language->id, true, $p ),
            'subcategories_nb_per_page' => ceil( count($sub_categories) / 15) ,
            'subcategories_nb_half' => ceil(count($sub_categories) / 2)
        ));
    }
}

我在第1页上的结果是正确的:

Pagination 1

我的模板聪明:

    {if isset($no_follow) AND $no_follow}
    {assign var='no_follow_text' value='rel="nofollow"'}
{else}
    {assign var='no_follow_text' value=''}
{/if}

{*{Fix page number, take subcategorys total number instead of products}*}
{assign var='pages_nb' value={$subcategories_nb_per_page}}
{if isset($p) AND $p}
    {if isset($smarty.get.id_category) && $smarty.get.id_category && isset($category)}
        {if !isset($current_url)}
            {assign var='requestPage' value=$link->getPaginationLink('category', $category, false, false, true, false)}
        {else}
            {assign var='requestPage' value=$current_url}
        {/if}
        {assign var='requestNb' value=$link->getPaginationLink('category', $category, true, false, false, true)}
    {/if}
    <!-- Pagination -->
    <div id="pagination{if isset($paginationId)}_{$paginationId}{/if}" class="pagination clearfix">
        {if $subcategories_nb_total > $subcategories_nb_per_page && $start!=$stop && ( ! isset( $smarty.get.show_total_req ) || $smarty.get.show_total_req == 0 ) }
            <form class="showall" action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get">
                <div>
                    {if isset($search_query) AND $search_query}
                        <input type="hidden" name="search_query" value="{$search_query|escape:'html':'UTF-8'}" />
                    {/if}
                    {if isset($tag) AND $tag AND !is_array($tag)}
                        <input type="hidden" name="tag" value="{$tag|escape:'html':'UTF-8'}" />
                    {/if}
                    <button type="submit" class="btn btn-default">
                        <span><i class="icon-double-angle-down"></i>{l s='Tout montrer'}</span>
                    </button>
                    {if is_array($requestNb)}
                        {foreach from=$requestNb item=requestValue key=requestKey}
                            {if $requestKey != 'requestUrl' && $requestKey != 'p'}
                                <input type="hidden" name="{$requestKey|escape:'html':'UTF-8'}" value="{$requestValue|escape:'html':'UTF-8'}" />
                            {/if}
                        {/foreach}
                    {/if}
                    <input name="n" id="nb_item" class="hidden" value="{$subcategories_nb_total}" />
                    <input name="show_total_req" id="show_total_req" class="hidden" value="1" />
                </div>
            </form>
        {/if}
        {if isset( $smarty.get.show_total_req ) && $smarty.get.show_total_req == 1}

            <form class="showpagination" action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get">
                <div>
                    <button type="submit" class="btn btn-default">
                        <span><i class="icon-double-angle-down"></i>{l s='Réinitialiser la pagination'}</span>
                    </button>
                    <input name="show_total_req" id="show_total_req" class="hidden" value="0" />
                </div>
            </form>
        {/if}
        {if $start!=$stop}
            <ul class="pagination">
                {if $p != 1}
                    {assign var='p_previous' value=$p-1}
                    <li class="pagination_previous">
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $p_previous)}" rel="prev">
                            <i class="icon-angle-left"></i> 
                        </a>
                    </li>
                {else}
                    <li  class="disabled pagination_previous">
                        <span>
                            <i class="icon-angle-left"></i> 
                        </span>
                    </li>
                {/if}
                {if $start==3}
                    <li>
                        <a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">
                            <span>1</span>
                        </a>
                    </li>
                    <li>
                        <a {$no_follow_text}  href="{$link->goPage($requestPage, 2)}">
                            <span>2</span>
                        </a>
                    </li>
                {/if}
                {if $start==2}
                    <li>
                        <a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">
                            <span>1</span>
                        </a>
                    </li>
                {/if}
                {if $start>3}
                    <li>
                        <a {$no_follow_text}  href="{$link->goPage($requestPage, 1)}">
                            <span>1</span>
                        </a>
                    </li>
                    <li class="truncate">
                        <span>
                            <span>...</span>
                        </span>
                    </li>
                {/if}
                {section name=pagination start=$start loop=$stop+1 step=1}
                    {if $p == $smarty.section.pagination.index}
                        <li class="active current">
                            <span>
                                <span>{$p|escape:'html':'UTF-8'}</span>
                            </span>
                        </li>
                    {else}
                        <li>
                            <a {$no_follow_text} href="{$link->goPage($requestPage, $smarty.section.pagination.index)}">
                                <span>{$smarty.section.pagination.index|escape:'html':'UTF-8'}</span>
                            </a>
                        </li>
                    {/if}
                {/section}
                {if $pages_nb>$stop+2}
                    <li class="truncate">
                        <span>
                            <span>...</span>
                        </span>
                    </li>
                    <li>
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $pages_nb)}">
                            <span>{$pages_nb|intval}</span>
                        </a>
                    </li>
                {/if}
                {if $pages_nb==$stop+1}
                    <li>
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $pages_nb)}">
                            <span>{$pages_nb|intval}</span>
                        </a>
                    </li>
                {/if}
                {if $pages_nb==$stop+2}
                    <li>
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $pages_nb-1)}">
                            <span>{$pages_nb-1|intval}</span>
                        </a>
                    </li>
                    <li>
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $pages_nb)}">
                            <span>{$pages_nb|intval}</span>
                        </a>
                    </li>
                {/if}
                {if $pages_nb > 1 AND $p != $pages_nb}
                    {assign var='p_next' value=$p+1}
                    <li  class="pagination_next">
                        <a {$no_follow_text} href="{$link->goPage($requestPage, $p_next)}" rel="next">
                         <i class="icon-angle-right"></i>
                        </a>
                    </li>
                {else}
                    <li class="disabled pagination_next">
                        <span>
                        <i class="icon-angle-right"></i>
                        </span>
                    </li>
                {/if}
            </ul>
        {/if}
    </div>
    <!-- /Pagination -->
{/if}

这就是我在最后一页时所拥有的:

Pagination 2

我检查我应该只有10页,其他2页是空的。

你知道这可能来自哪里吗?

谢谢。

0 个答案:

没有答案