Skip to content

Commit

Permalink
Add fix for filters and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Radomir98 committed Sep 4, 2024
1 parent 346c07f commit 764033e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
40 changes: 20 additions & 20 deletions src/Resources/views/storefront/component/pagination.html.twig
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{% sw_extends '@Storefront/storefront/component/pagination.html.twig' %}

{% block component_pagination_nav %}
{% if not (searchResult.criteria.extensions.nostoPagination) %}
{% set currentPage = ((criteria.offset + 1) / criteria.limit )|round(0, 'ceil') %}
{% set totalPages = (entities.total / criteria.limit)|round(0, 'ceil') %}
{% if not context.context.extensions.nostoService.enabled %}
{{ parent() }}
{% else %}
{% set currentPage = ((searchResult.criteria.extensions.nostoPagination.offset + 1) / searchResult.criteria.extensions.nostoPagination.limit )|round(0, 'ceil') %}
{% set totalPages = (searchResult.criteria.extensions.nostoPagination.total / searchResult.criteria.extensions.nostoPagination.limit)|round(0, 'ceil') %}
{% endif %}
{% if not (searchResult.criteria.extensions.nostoPagination) %}
{% set currentPage = ((criteria.offset + 1) / criteria.limit )|round(0, 'ceil') %}
{% set totalPages = (entities.total / criteria.limit)|round(0, 'ceil') %}
{% else %}
{% set currentPage = ((searchResult.criteria.extensions.nostoPagination.offset + 1) / searchResult.criteria.extensions.nostoPagination.limit )|round(0, 'ceil') %}
{% set totalPages = (searchResult.criteria.extensions.nostoPagination.total / searchResult.criteria.extensions.nostoPagination.limit)|round(0, 'ceil') %}
{% endif %}

{% set paginationSuffix = '' %}
{% if paginationLocation %}
{% set paginationSuffix = '-' ~ paginationLocation %}
{% endif %}
{% set paginationSuffix = '' %}
{% if paginationLocation %}
{% set paginationSuffix = '-' ~ paginationLocation %}
{% endif %}

{% if totalPages > 1 %}
<nav aria-label="pagination" class="pagination-nav nosto-ns-nav">
{% block component_pagination %}
{{ parent() }}
{% endblock %}
</nav>
<style>
.nosto-ns-nav { display: none }
.nosto-ns-nav:first-of-type { display: block }
</style>
{% if totalPages > 1 %}
<nav aria-label="pagination" class="pagination-nav">
{% block component_pagination %}
{{ parent() }}
{% endblock %}
</nav>
{% endif %}
{% endif %}
{% endblock %}
48 changes: 22 additions & 26 deletions src/Resources/views/storefront/component/product/listing.html.twig
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
{% sw_extends '@Storefront/storefront/component/product/listing.html.twig' %}

{% block element_product_listing_wrapper_content %}
{% if not (context.context.extensions.nostoService.enabled) %}
{{ parent() }}
{% else %}
<div class="cms-element-product-listing">
{% if searchResult.total > 0 %}
{% block element_product_listing_pagination_nav_actions %}
{{ parent() }}
{% endblock %}
{% endif %}

{% block element_product_listing_row %}
<div class="cms-element-product-listing">
{% if searchResult.total > 0 %}
{% block element_product_listing_pagination_nav_actions %}
{{ parent() }}
{% endblock %}
{% endif %}

{% if not (searchResult.criteria.extensions.nostoPagination) %}
{% set paginationTotal = searchResult.total %}
{% set paginationLimit = searchResult.limit %}
{% else %}
{% set paginationTotal = searchResult.criteria.extensions.nostoPagination.total %}
{% set paginationLimit = searchResult.criteria.extensions.nostoPagination.limit %}
{% endif %}
{% block element_product_listing_row %}
{{ parent() }}
{% endblock %}

{% set totalPages = (paginationTotal / paginationLimit)|round(0, 'ceil') %}
{% if totalPages > 1 %}
{% block element_product_listing_pagination_nav_bottom %}
{{ parent() }}
{% endblock %}
{% endif %}
{% if not (searchResult.criteria.extensions.nostoPagination) %}
{% set paginationTotal = searchResult.total %}
{% set paginationLimit = searchResult.limit %}
{% else %}
{% set paginationTotal = searchResult.criteria.extensions.nostoPagination.total %}
{% set paginationLimit = searchResult.criteria.extensions.nostoPagination.limit %}
{% endif %}

{% set totalPages = (paginationTotal / paginationLimit)|round(0, 'ceil') %}
{% if totalPages > 1 %}
{% block element_product_listing_pagination_nav_bottom %}
{{ parent() }}
{% endblock %}
</div>
{% endif %}
{% endif %}
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions src/Subscriber/FrontendSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Nosto\NostoIntegration\Decorator\Storefront\Framework\Cookie\NostoCookieProvider;
use Nosto\NostoIntegration\Model\ConfigProvider;
use Nosto\NostoIntegration\Struct\Config;
use Nosto\NostoIntegration\Utils\SearchHelper;
use Shopware\Core\Content\Category\Event\CategoryRouteCacheKeyEvent;
use Shopware\Storefront\Framework\Routing\StorefrontResponse;
use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -31,6 +33,7 @@ public static function getSubscribedEvents(): array
return [
HeaderPageletLoadedEvent::class => 'onHeaderLoaded',
KernelEvents::RESPONSE => 'onKernelResponse',
CategoryRouteCacheKeyEvent::class => 'addNostoData',
];
}

Expand Down Expand Up @@ -84,4 +87,9 @@ private function triggerCookieBanner(Response $response, Request $request): void
$response->headers->setCookie($cookie);
}
}

public function addNostoData(CategoryRouteCacheKeyEvent $event): void
{
SearchHelper::shouldHandleRequest($event->getContext(), $this->configProvider, true);
}
}

0 comments on commit 764033e

Please sign in to comment.