Shopware pagination using wrong total-property to calculate totalPages in pagination.html.twig

In Shopware I want to implement pagination for reviews on the product detail-page.

To achieve this I extend pagination.html.twig

{% sw_include '@Storefront/storefront/component/pagination.html.twig' with {
    entities: reviews,
    criteria: criteria,
}  %}

Because I wanted to customize the limit of the items per page I made a custom decorator

<?php declare(strict_types=1);

namespace MyAppDecorators;

use ShopwareCoreSystemSalesChannelSalesChannelContext;
use ShopwareStorefrontPageProductReviewProductReviewLoader;
use SymfonyComponentHttpFoundationRequest;
use ShopwareStorefrontPageProductReviewReviewLoaderResult;

final class ProductDetailPageReviewPagerDecorator extends ProductReviewLoader
{
    private const LIMIT = 3;

    private ProductReviewLoader $decorated;

    public function __construct(ProductReviewLoader $decorated)
    {
        $this->decorated = $decorated;
    }

    public function load(Request $request, SalesChannelContext $context): ReviewLoaderResult
    {
        $request->attributes->set("limit", $request->get("limit", self::LIMIT));
        return $this->decorated->load($request, $context);
    }
}

The pagination is not showing, this is the issue, pagination.html.twig contains the following variable:

    {% set totalPages = (entities.total / criteria.limit)|round(0, 'ceil') %}

The totalPages is used by calculating entities.total, but contains the value of the amount of loaded reviews which by definition is equal to or lower then the limit. So totalPages is always 1.

There is also a variable totalReviews which does contain the correct amount of totalReviews. So by making the following change:

    {% set totalPages = (entities.totalReviews / criteria.limit)|round(0, 'ceil') %}

it does work. But making changes in the vendor Shopware-core of course is not allowed.

Other disallowed options

  1. I could also make a new component called pdp-pagination.html.twig containing the following code
{% sw_extends '@Storefront/storefront/component/pagination.html.twig' %}

{% block component_pagination_nav %}
    {% set currentPage = ((criteria.offset + 1) / criteria.limit )|round(0, 'ceil') %}
    {% set totalPages = (entities.totalReviews / criteria.limit)|round(0, 'ceil') %}
    {% if totalPages > 1 %}
        <nav aria-label="pagination" class="pagination-nav">
            {% block component_pagination %}
                {% set totalPages = (entities.totalReviews / criteria.limit)|round(0, 'ceil') %}
                {{ parent() }}
            {% endblock %}
        </nav>
    {% endif %}
{% endblock %}

This fixes the issue but is not allowed.

  1. Using reflection – works but is not allowed
    public function load(Request $request, SalesChannelContext $context): ReviewLoaderResult
    {
        $request->attributes->set("limit", $request->get("limit", self::LIMIT));
        $result = $this->decorated->load($request, $context);

        $reflectionReviewLoaderResult = new ReflectionClass($result);
        $reviewLoaderResultTotal = $reflectionReviewLoaderResult->getProperty('total');
        $reviewLoaderResultTotal->setAccessible(true);
        $reviewLoaderResultTotal->setValue($result, $result->getTotalReviews());

        return $result;
    }

So how would I fix this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật