-
-
Save johnulist/78a1de6212aaf81850164d34dd7ff971 to your computer and use it in GitHub Desktop.
[PS1.7 Pagination results in Backoffice does not working] Only for ver. 1.7.7.0 #PS17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Just replace the function paginationAction for this one in src/PrestaShopBundle/Controller/Admin/CommonController.php: | |
public function paginationAction(Request $request, $limit = 10, $offset = 0, $total = 0, $view = 'full', $prefix = '') | |
{ | |
$offsetParam = empty($prefix) ? 'offset' : sprintf('%s[offset]', $prefix); | |
$limitParam = empty($prefix) ? 'limit' : sprintf('%s[limit]', $prefix); | |
$limit = max($limit, 10); | |
$currentPage = floor($offset / $limit) + 1; | |
$pageCount = ceil($total / $limit); | |
$from = $offset; | |
$to = $offset + $limit - 1; | |
// urls from route | |
$callerParameters = $request->attributes->get('caller_parameters', array()); | |
foreach ($callerParameters as $k => $v) { | |
if (strpos($k, '_') === 0) { | |
unset($callerParameters[$k]); | |
} | |
} | |
$routeName = $request->attributes->get('caller_route', $request->attributes->get('caller_parameters', ['_route' => false])['_route']); | |
$nextPageUrl = (!$routeName || ($offset + $limit >= $total)) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => min($total - 1, $offset + $limit), | |
$limitParam => $limit, | |
) | |
)); | |
$previousPageUrl = (!$routeName || ($offset == 0)) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => max(0, $offset - $limit), | |
$limitParam => $limit, | |
) | |
)); | |
$firstPageUrl = (!$routeName || ($offset == 0)) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => 0, | |
$limitParam => $limit, | |
) | |
)); | |
$lastPageUrl = (!$routeName || ($offset + $limit >= $total)) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => ($pageCount - 1) * $limit, | |
$limitParam => $limit, | |
) | |
)); | |
$changeLimitUrl = (!$routeName) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => 0, | |
$limitParam => '_limit', | |
) | |
)); | |
$jumpPageUrl = (!$routeName) ? false : $this->generateUrl($routeName, array_merge( | |
$callerParameters, | |
array( | |
$offsetParam => 999999, | |
$limitParam => $limit, | |
) | |
)); | |
$limitChoices = $request->attributes->get('limit_choices', array(10, 20, 50, 100)); | |
// Template vars injection | |
$vars = array( | |
'limit' => $limit, | |
'changeLimitUrl' => $changeLimitUrl, | |
'first_url' => $firstPageUrl, | |
'previous_url' => $previousPageUrl, | |
'from' => $from, | |
'to' => $to, | |
'total' => $total, | |
'current_page' => $currentPage, | |
'page_count' => $pageCount, | |
'next_url' => $nextPageUrl, | |
'last_url' => $lastPageUrl, | |
'jump_page_url' => $jumpPageUrl, | |
'limit_choices' => $limitChoices, | |
); | |
if ($view != 'full') { | |
return $this->render('@PrestaShop/Admin/Common/pagination_' . $view . '.html.twig', $vars); | |
} | |
return $vars; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment