shopwareshopware6shopware6-api

Shopware 6 Plugin - SEO Friendly Pagination: , null is returned from app.request.get('properties')


I'm currently developing a Shopware 6 plugin called "SEO Friendly Pagination" that aims to make paginated URLs in product categories accessible to search engine crawlers. To achieve this, I have extended the pagination template to include invisible href elements for each page in the pagination. These href elements are generated with SEO-friendly URLs that reflect the current context of the page, including sorting order and filters.

The pagination template in my custom plugin pagination.html.twig looks like this:

{# Extend the 'pagination.html.twig' template from the storefront #}
{% sw_extends '@Storefront/storefront/component/pagination.html.twig' %}

{# Define the 'component_pagination' block #}
{% block component_pagination %}
    
    {# Access the 'TanmarSeoPagination' data from the context #}
    {% set TanmarSeoPaginationData = context.context.extensions.tanmarNgSeoPagination %}

    {# Check if TanmarSeoPagination is active #}
    {% if TanmarSeoPaginationData.active %}
        
        {# Check if active navigation ID is defined in page header #}
        {% if page.header.navigation.active.id is defined %}
            {% set currentNavigationId = page.header.navigation.active.id %} 
        {% endif %}
        
        {# Check if navigation ID is defined in search filters #}
        {% if searchResult.currentFilters.navigationId is defined %}
            {% set currentNavigationId = searchResult.currentFilters.navigationId %}
        {% endif %}
        
        {% for i in 1..totalPages %}
            {# Set up an empty SEO parameters object #}
        {% set seoParams = {} %}
        
        {# Check and set 'order' parameter from request #}
        {% set order = app.request.get('order') %}
        {% if order %}
            {% set seoParams = seoParams|merge({ order: order }) %}
        {% endif %}
        
        {# Calculate the next page number #}
        {% set pageNumber = currentPage + 1 %}
        {% if i != currentPage %}
            {% if pageNumber %}
            {% set seoParams = seoParams|merge({ p: i }) %}
        {% endif %}
   
        {# Check and set 'properties' parameter from request #}
        {% set properties = app.request.get('properties') %}
        {{ dump(properties) }}
        {% if properties  %}
            {% set seoParams = seoParams|merge({ properties: app.request.get('properties') ~ seoParams }) %}
        {% endif %}
        
        {# Properly encode the SEO parameters into a string before using it #}
        {% set seoParams = '?' ~ seoParams|url_encode %}
   
        {# Check if currentNavigationId is defined and generate SEO-friendly URL #}
        {% if currentNavigationId is defined %}
            <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) ~ seoParams }}"></a>
        {% endif %}
        
        {% endif %}
        {% endfor %}
        
    {% endif %} 
    
    {# Call the parent pagination block #}
    {{ parent() }}
{% endblock %}

Here I selected size L from the filter

Could someone please help me identify what might be causing this to return null and how I can fix it? Is there anyway I can access the properties the way I am accessing the order?

Thank you in advance for your assistance!

Best regards, Lodhi


Solution

  • This works for me locally without issue:

    {% set properties = app.request.get('properties') %}
    {{ dump(properties) }}
    {# 01896e38492873aca93edde1c6a6b3a4|01896e38492873aca93edde1c76853fe #}
    

    What didn't work was this line:

    {% set seoParams = seoParams|merge({ properties: app.request.get('properties') ~ seoParams }) %}
    

    That caused an error rendering the template. You're already merging into seoParams so you really don't need to concatenate them at that point, since you're URL encoding them later on. Removing the concatenation ~ seoParams made everything work as expected for me.