Skip to content

Commit

Permalink
[TASK] Replace SimplePagination with SlidingWindowPagination
Browse files Browse the repository at this point in the history
Relates: #259
  • Loading branch information
extcode committed Mar 3, 2025
1 parent fab628d commit befb3d5
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 9 deletions.
11 changes: 6 additions & 5 deletions Classes/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Extcode\CartProducts\Domain\Repository\CategoryRepository;
use Extcode\CartProducts\Domain\Repository\Product\ProductRepository;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Pagination\SlidingWindowPagination;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
Expand Down Expand Up @@ -154,19 +154,20 @@ public function listAction(int $currentPage = 1): ResponseInterface
$demand = $this->createDemandObjectFromSettings($this->settings);
$demand->setActionAndClass(__METHOD__, self::class);

$itemsPerPage = $this->settings['itemsPerPage'] ?? 20;
$itemsPerPage = (int)($this->settings['itemsPerPage'] ?? 20);
$maximumNumberOfLinks = (int)($this->settings['maximumNumberOfLinks'] ?? 0);

$products = $this->productRepository->findDemanded($demand);
$arrayPaginator = new QueryResultPaginator(
$paginator = new QueryResultPaginator(
$products,
$currentPage,
$itemsPerPage
);
$pagination = new SimplePagination($arrayPaginator);
$pagination = new SlidingWindowPagination($paginator, $maximumNumberOfLinks);
$this->view->assignMultiple(
[
'products' => $products,
'paginator' => $arrayPaginator,
'paginator' => $paginator,
'pagination' => $pagination,
'pages' => range(1, $pagination->getLastPageNumber()),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EXT:cart.
format.currency < plugin.tx_cart.settings.format.currency
itemsPerPage = 9
maximumNumberOfLinks = 0
}
}
Expand All @@ -49,3 +50,10 @@ the individual parameter are described.
:Default: The default value is 20 if there is no TypoScript configuration.

Defines how many records should be displayed per page in the list action.

.. confval:: maximumNumberOfLinks

:Type: int
:Default: The default value is 0 if there is no TypoScript configuration.

Defines how many links the paginator should show. The default value 0 means that the page links are not limited.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. include:: ../../Includes.rst.txt

=====================================================================
Feature: #259 - Replace SimplePagination with SlidingWindowPagination
=====================================================================

See `Issue 259 <https://github.com/extcode/cart_products/issues/259>`__

Description
===========

If you have a long list of products, you would like to display them in a pagination
with a defined number of products per page. This is already possible with the
TypoScript configuration `itemsPerPage`. With a large number of products, the
display of all page links may not work well, especially when it comes to the
display on mobile devices.
The TYPO3 core offers the SlidingWindowPagination since TYPO3 v12.
This is compatible with the previously used SimplePagination if you pass the
value 0 for the number of links.

Integration
===========

Set the new TypoScript configuration variable `plugin.tx_cartproducts.maximumNumberOfLinks` to a value greater than 0.
If you use an own template file for `Resources/Private/Partials/Utility/Paginator.html` you have to adapt the changes
to your file.

.. index:: Frontend
20 changes: 20 additions & 0 deletions Documentation/Changelog/7.1/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. include:: ../../Includes.rst.txt

7.1 Changes
===========

**Table of contents**

.. contents::
:local:
:depth: 1

Features
^^^^^^^^

.. toctree::
:maxdepth: 1
:titlesonly:
:glob:

Feature-*
1 change: 1 addition & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ChangeLog
:maxdepth: 5
:titlesonly:

7.1/Index
7.0/Index
6.0/Index
5.0/Index
Expand Down
2 changes: 1 addition & 1 deletion Documentation/guides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
interlink-shortcode="extcode/cart_products"
/>
<project title="Cart Products"
release="7.0.2"
release="7.1.0"
version="7.0"
copyright="2018 - 2025"
/>
Expand Down
13 changes: 11 additions & 2 deletions Resources/Private/Partials/Utility/Paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
<li class="disabled"><a href="#" class="btn btn-link">&lsaquo;</a></li>
</f:else>
</f:if>
<f:for each="{pages}" as="page">

<f:if condition="{pagination.hasLessPages}">
<li></li>
</f:if>

<f:for each="{pagination.allPageNumbers}" as="page">
<li class="{f:if(condition: '{page} == {paginator.currentPageNumber}', then:'active', else:'waves-effect')}">
<a href="{f:uri.action(action:actionName, arguments:{currentPage: page})}" class="btn btn-link">{page}</a>
</li>
</f:for>

<f:if condition="{pagination.hasMorePages}">
<li></li>
</f:if>

<f:if condition="{pagination.nextPageNumber} && {pagination.nextPageNumber} <= {pagination.lastPageNumber}">
<f:then>
<li class="waves-effect">
Expand All @@ -39,4 +48,4 @@
</f:if>
</ul>
</f:if>
</html>
</html>
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'title' => 'Cart - Products',
'description' => 'Shopping Cart(s) for TYPO3 - Products',
'category' => 'plugin',
'version' => '7.0.2',
'version' => '7.1.0',
'state' => 'stable',
'author' => 'Daniel Gohlke',
'author_email' => 'ext@extco.de',
Expand Down

0 comments on commit befb3d5

Please sign in to comment.