Change number of products in a row on category vie

2019-06-02 08:54发布

问题:

I have a working on a shop right now, and i want to display 4 products in a row in category view, but i cant figure out, how to solve that. When i toggle inspect element in browser i see this code:

<div class="row">
<div class="product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12">..</div>
<div class="product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12">..</div>
<div class="product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12">..</div>
<div class="clearfix visible-lg"></div>..</div>
<div class="product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12">..</div>

When here i change from col-lg-4 to col-lg-3, and i delete inbe with clearfix-visible, it looks like i want, but when i search in

catalog/view/theme/default/template/product/category.tpl

  <div class="row">
        <?php foreach ($products as $product) { ?>
        <div class="product-layout product-list col-xs-12">
          <div class="product-thumb">

but it refers to list view. Where can i setup this permamently?

回答1:

So i found the solution: must change catalog/view/javascript/common.js at // Product Grid:

// Product Grid
    $('#grid-view').click(function() {
        $('#content .product-layout > .clearfix').remove();

        // What a shame bootstrap does not take into account dynamically loaded columns
        cols = $('#column-right, #column-left').length;

        if (cols == 2) {
            $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-6');
        } else if (cols == 1) {
            $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-6');
        } else {
            $('#content .product-layout').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-6');
        }

         localStorage.setItem('display', 'grid');
    });

And also clearfix in common.js:

// Adding the clear Fix cols1 = $('#column-right, #column-left').length;

if (cols1 == 2) {
    $('#content .product-layout:nth-child(2n+2)').after('<div class="clearfix visible-md visible-sm"></div>');
} else if (cols1 == 1) {
    $('#content .product-layout:nth-child(4n+4)').after('<div class="clearfix visible-lg"></div>'); /*3n+3*/
} else {
    $('#content .product-layout:nth-child(4n+4)').after('<div class="clearfix"></div>');