doubi6669
2017-09-30 08:08
浏览 29
已采纳

Prestashop 1.7产品每页下拉列表类别

I am looking through Prestashop 1.7 and i want to overide the controller responsible for Products Listing ( aka Category Archive ). I am using the official Prestashop starter theme and i want to override the controller in order to get some more data to the sort-order.tpl

<div class="products-sort-order">
  <span>{if isset($listing.sort_selected)}{$listing.sort_selected}{else}{l s='Sort by:' d='Shop.Theme.Global'}{/if}</span>
  {foreach from=$sort_orders item=sort_order}
    <a
      class="{['current' => $sort_order.current, 'js-search-link' => true]|classnames}"
      href="{$sort_order.url}"
      rel="nofollow"
    >
      {$sort_order.label}
    </a>
  {/foreach}
</div>

In the above snippet there is a sort_order variable , part of a $listing variable comming from products-top.tpl

<div id="js-product-list-top" class="products-selection">
  {if $listing.pagination.total_items|count > 1}
    <p>{l s='There are %product_count% products.' d='Shop.Theme.Catalog' sprintf=['%product_count%' => $listing.pagination.total_items|count]}</p>
  {elseif $listing.pagination.total_items > 0}
    <p>{l s='There is 1 product.' d='Shop.Theme.Catalog'}</p>
  {/if}

  {block name='sort_by'}
    {include file='catalog/_partials/sort-orders.tpl' sort_orders=$listing.sort_orders}
  {/block}

  {block name='pagination_summary'}
    {l s='Showing %from%-%to% of %total% item(s)' d='Shop.Theme.Catalog' sprintf=[
    '%from%' => $listing.pagination.items_shown_from ,
    '%to%' => $listing.pagination.items_shown_to,
    '%total%' => $listing.pagination.total_items
    ]}
  {/block}
</div>

My goal is to override the responsible controller in order to generate some links to alter the resultsPerPage just like the $sort_order changes the listing order passing some parameters to the url. The problem is that althought i've search nearly all controllers , i did not find the one passing those data to the tpl. Due to the lack of proper documentation i am asking for a bit of "where-is-that" information from a more experienced dev Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我正在浏览Prestashop 1.7,我想覆盖负责产品列表的控制器(又名Category Archive)。 我正在使用正式的Prestashop启动主题,我想覆盖控制器,以便获得更多数据到sort-order.tpl

 &lt; div class =“产品 -sort-order“&gt; 
&lt; span&gt; {if isset($ listing.sort_selected)} {$ listing.sort_selected} {else} {ls ='排序方式:'d ='Shop.Theme.Global'}  {/ if}&lt; / span&gt; 
 {foreach from = $ sort_orders item = sort_order} 
&lt; a 
 class =“{['current'=&gt; $ sort_order.current,'js-search-link  '=&gt; true] | classnames}“
 href =”{$ sort_order.url}“
 
et =”nofollow“
&gt; 
 {$ sort_order.label} 
&lt; / a&gt; 
  {/ foreach} 
&lt; / div&gt; 
   
 
 

在上面的代码片段中有一个sort_order变量,它是来自products-top.tpl的$ listing变量的一部分

 &lt; div id =“js-product-list-top”class =“pro 管道选择“&gt; 
 {if {listing.pagination.total_items | count&gt;  1} 
&lt; p&gt; {l s ='有%product_count%产品。'  d ='Shop.Theme.Catalog'sprintf = ['%product_count%'=&gt;  $ listing.pagination.total_items | count]}&lt; / p&gt; 
 {elseif $ listing.pagination.total_items&gt;  0} 
&lt; p&gt; {l s ='有1个产品。'  d ='Shop.Theme.Catalog'}&lt; / p&gt; 
 {/ if} 
 
 {block name ='sort_by'} 
 {include file ='catalog / _partials / sort-orders.tpl'  sort_orders = $ listing.sort_orders} 
 {/ block} 
 
 {block name ='pagination_summary'} 
 {ls ='%% from% - %to%of total total items(s)'d =  'Shop.Theme.Catalog'sprintf = [
'%from%'=&gt;  $ listing.pagination.items_shown_from,
'%to%'=&gt;  $ listing.pagination.items_shown_to,
'%total%'=&gt;  $ listing.pagination.total_items 
]} 
 {/ block} 
&lt; / div&gt; 
   
 
 

我的目标是覆盖负责的控制器以便 生成一些链接来改变resultsPerPage就像$ sort_order更改列表顺序一样,将一些参数传递给url。 问题是,虽然我已经搜索了几乎所有的控制器,但我没有找到将这些数据传递给tpl的人。 由于缺乏适当的文档,我要求一位经验丰富的开发人员提供一些“来自哪里”的信息

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhao6557 2017-09-30 08:58
    已采纳

    First, create an override for classes/controller/ProductListingFrontController.php

    and change line 279:

    $resultsPerPage <= 0 || $resultsPerPage > 36
    

    to (for example..)

    $resultsPerPage <= 0 || $resultsPerPage > 100
    

    100 in this example is the max number of items you want per page. You can also choose more or less, depending what you want. Now let's alter your .tpl

    In your theme, go to themes/yourtheme/templates/catalog/_partials/sort-orders.tpl

    On the top of the page (right underneath the licence) add this to assign the variables:

    {if !empty($smarty.get.order)}
            {capture assign='ordering'}order={$smarty.get.order}&amp;{/capture}
        {else}
            {assign var='ordering' value=''}
        {/if}
    
        {if !empty($smarty.get.resultsPerPage)}
            {assign var='results_per_page' value=$smarty.get.resultsPerPage}
        {else}
            {assign var='results_per_page' value=25}
        {/if}
    

    And now, right underneath, add this code:

    <div class="col-md-3">
      <label style="float:left;margin-right: 15px" class="form-control-label hidden-sm-down sort-label">{l s='Products per page:'}</label>
      <div style="float:left;" class="sort-select dropdown js-dropdown">
        <a class="custom-select select-title" rel="nofollow" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            {$results_per_page}
        </a>
        <div class="dropdown-menu">
          <a rel="nofollow" href="?{$ordering}resultsPerPage=25" class="dropdown-item js-search-link">
                25
            </a>
          <a rel="nofollow" href="?{$ordering}resultsPerPage=50" class="dropdown-item js-search-link">
                50
            </a>
          <a rel="nofollow" href="?{$ordering}resultsPerPage=75" class="dropdown-item js-search-link">
                75
            </a>
          <a rel="nofollow" href="?{$ordering}resultsPerPage=100" class="dropdown-item js-search-link">
                100
            </a>
        </div>
      </div>
    </div>
    

    You might need to change the layout (or the number of items, or the max results per page...) but you'll be good to go :)

    If you're going to change the number of items (in the dropdown) for example, just change:

    <a rel="nofollow" href="?{$ordering}resultsPerPage=25"
    

    to

    <a rel="nofollow" href="?{$ordering}resultsPerPage=40"
    

    To adjust the amount of products per page.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题