Yosri Mekni
Yosri Mekni

Reputation: 19

PagerFanta issue: setMaxPerPage not working

i trying to create a paginator when i display products but the $paginator->setMaxPerPage() and $paginator->setCurrentPage() are not working :

my repository method :

 public function findLatestBySubcategAndTaxon($ids, $taxon_id)
{
    $sids = implode(",", $ids);



    $manager = $this->getEntityManager();

    $res = $manager->createQuery('
            select p from AppBundle:Product p
            join p.subcategories sp WITH sp.id in (:ids)
            group by p.id
            having GROUP_CONCAT(sp.id order by sp.id separator \',\') = :sids
        ')
        ->setParameter('ids', $ids)
        ->setParameter('sids',$sids);


        //$products = $res->getResult();

    $paginator = new Pagerfanta(new DoctrineORMAdapter($res, false));
    $mp= 1;
    $cp=1;
    $paginator->setMaxPerPage($mp); // not working , always return  10 instead of 1
    $paginator->setCurrentPage($cp);// not working , always return  1
    var_dump($paginator->setMaxPerPage($mp));
    //var_dump($paginator);
    //var_dump($paginator);
    //exit();
    return $paginator;

        //return $products;

}

my routing :

app_latest_prod_subcateg_taxon:
path: /products/prodfilter # configure a new path that has all the needed variables
methods: [POST]
defaults:
    _controller: sylius.controller.product:indexAction # you make a call on the Product Controller's index action
    _sylius:
        template: $template
        repository:
            method: findLatestBySubcategAndTaxon # here use the new repository method
            arguments:
                - $ids
                - $taxon_id

twig file :

<div class="ui four column stackable grid">
<div class="row">
   

    {{ dump(products) }}
    {{ dump(products.maxPerPage) }}

    {{ dump(products.maxPerPage) }}
    {% if products|length >0 %}
    {% for product in products.getCurrentPageResults() %}
    <div class="column">
        {% include '@App/ProductList/_simpleBox.html.twig' %}
    </div>
    {% if 0 == loop.index % 3 %}
</div>
<div class="row">
    {% endif %}
    {% endfor %}
 {% if products.haveToPaginate %}
        {{ pagerfanta(products) }}
    {% endif %}
    {% else %}
        <div class="ui negative message">
            <i class="close icon"></i>
            <div class="header">
                Oups !
            </div>
            <p>Aucun article trouvés
            </p></div>
    {% endif %}
</div>

and the dump(products) in the yml file return :

enter image description here

the maxPerPage attribut should be 1 !!! where is the problem

Upvotes: 0

Views: 518

Answers (1)

Sylvan D Ash
Sylvan D Ash

Reputation: 1117

Seems to have been an issue with Sylius itself and seemingly it has also been fixed here. I suggest you update your version of Sylius

Upvotes: 0

Related Questions