Prestashop 1.6 вывод по 4-5 товаров в ряд в категории

24 сентября 2017

В Prestashop 1.6 в категории, по умолчанию, выводится 3 товара в ряд (сетка), для увеличения количества товара (в нашем примере - 4 в ряд) надо:

> ваша тема > product_list.tpl

<ol><li>{if isset($products) && $products}</li><li>    {*<a href="http://www.php.net/define">define</a> number of products per line in other page for desktop*}</li><li>    {if $page_name !='index' && $page_name !='product'}</li><li>        {assign var='nbItemsPerLine' value=3}</li><li>        {assign var='nbItemsPerLineTablet' value=2}</li><li>        {assign var='nbItemsPerLineMobile' value=3}</li><li>    {else}</li><li>        {assign var='nbItemsPerLine' value=4}</li><li>        {assign var='nbItemsPerLineTablet' value=3}</li><li>        {assign var='nbItemsPerLineMobile' value=2}</li><li>    {/if}</li><li>    {*<a href="http://www.php.net/define">define</a> numbers of product per line in other page for tablet*}</li><li>    {assign var='nbLi' value=$products|@count}</li><li>    {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}</li><li>    {math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}</li><li>    <!-- Products <a href="http://www.php.net/list">list</a> --></li><li>    <ul{if isset($id) && $id} id="<strong>{$id}</strong>"{/if} <strong>class</strong>="product_list grid row{if isset($class) && $class} <strong>{$class}</strong>{/if}"></li><li>    {foreach from=$products item=product name=products}</li><li>        {math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}</li><li>        {math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}</li><li>        {math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}</li><li>        {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}</li><li>        {if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}</li><li>        {if $totModuloMobile == 0}{assign var='totModuloMobile' value=$nbItemsPerLineMobile}{/if}</li><li>        <li <strong>class</strong>="ajax_block_product{if $page_name == 'index' || $page_name == 'product'} col-xs-12 col-sm-4 col-md-3{else} col-xs-12 col-sm-6 col-md-4{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLine == 0} last-in-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLine == 1} first-in-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModulo)} last-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 0} last-item-of-tablet-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 1} first-item-of-tablet-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 0} last-item-of-mobile-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 1} first-item-of-mobile-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModuloMobile)} last-mobile-line{/if}"></li></ol>

заменить на

<ol><li>{if isset($products) && $products}</li><li>    {*<a href="http://www.php.net/define">define</a> number of products per line in other page for desktop*}</li><li>    {if $page_name !='index' && $page_name !='product'}</li><li>        {assign var='nbItemsPerLine' value=4}</li><li>        {assign var='nbItemsPerLineTablet' value=2}</li><li>        {assign var='nbItemsPerLineMobile' value=3}</li><li>    {else}</li><li>        {assign var='nbItemsPerLine' value=4}</li><li>        {assign var='nbItemsPerLineTablet' value=3}</li><li>        {assign var='nbItemsPerLineMobile' value=2}</li><li>    {/if}</li><li>    {*<a href="http://www.php.net/define">define</a> numbers of product per line in other page for tablet*}</li><li>    {assign var='nbLi' value=$products|@count}</li><li>    {math equation="nbLi/nbItemsPerLine" nbLi=$nbLi nbItemsPerLine=$nbItemsPerLine assign=nbLines}</li><li>    {math equation="nbLi/nbItemsPerLineTablet" nbLi=$nbLi nbItemsPerLineTablet=$nbItemsPerLineTablet assign=nbLinesTablet}</li><li>    <!-- Products <a href="http://www.php.net/list">list</a> --></li><li>    <ul{if isset($id) && $id} id="<strong>{$id}</strong>"{/if} <strong>class</strong>="product_list grid row{if isset($class) && $class} <strong>{$class}</strong>{/if}"></li><li>    {foreach from=$products item=product name=products}</li><li>        {math equation="(total%perLine)" total=$smarty.foreach.products.total perLine=$nbItemsPerLine assign=totModulo}</li><li>        {math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineTablet assign=totModuloTablet}</li><li>        {math equation="(total%perLineT)" total=$smarty.foreach.products.total perLineT=$nbItemsPerLineMobile assign=totModuloMobile}</li><li>        {if $totModulo == 0}{assign var='totModulo' value=$nbItemsPerLine}{/if}</li><li>        {if $totModuloTablet == 0}{assign var='totModuloTablet' value=$nbItemsPerLineTablet}{/if}</li><li>        {if $totModuloMobile == 0}{assign var='totModuloMobile' value=$nbItemsPerLineMobile}{/if}</li><li>        <li <strong>class</strong>="ajax_block_product{if $page_name == 'index' || $page_name == 'product'} col-xs-12 col-sm-4 col-md-3{else} col-xs-12 col-sm-6 col-md-3{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLine == 0} last-in-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLine == 1} first-in-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModulo)} last-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 0} last-item-of-tablet-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineTablet == 1} first-item-of-tablet-line{/if}{if $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 0} last-item-of-mobile-line{elseif $smarty.foreach.products.iteration%$nbItemsPerLineMobile == 1} first-item-of-mobile-line{/if}{if $smarty.foreach.products.iteration > ($smarty.foreach.products.total - $totModuloMobile)} last-mobile-line{/if}"></li></ol>

И дальше в global.js меняем бутстраповскую разметку:
строки

<ol><li>$('.product_list > li').removeClass('col-xs-12 col-sm-6 col-md-4').addClass('col-xs-12');</li></ol>

меняем на

<ol><li>$('.product_list > li').removeClass('col-xs-12 col-sm-6 col-md-3').addClass('col-xs-12');</li></ol>

и

<ol><li>$('.product_list > li').removeClass('col-xs-12').addClass('col-xs-12 col-sm-6 col-md-4');</li></ol>

меняем на

<ol><li>$('.product_list > li').removeClass('col-xs-12').addClass('col-xs-12 col-sm-6 col-md-3');</li></ol>

Если необходимо сделать, допустим 5 товаров в линию, для col-md даем значение 2, а в tpl файле {assign var='nbItemsPerLine' value= ставим 5} (верхняя часть для отображения в категориях и подкатегориях, нижняя - для главной страницы).