XML/CSV Shopping Feed: Order of the product images URLs

We are in the process of importing our products into the german eBay-classifieds website, but the output of the product photos URLs are in the wrong order.
With the standard defaults (from the documentation as well as the billiger.de template) this is unfortunately not possible, the order seems very arbitrary.
Even with another approach I found here in the forum, the order is still messed up. Only the cover image is output correctly:

<title>{{ product.translated.name|escape }}</title>
<description>{{ product.translated.description|escape }}</description>


<g:image_link>{{ product.cover.media.url }}</g:image_link>

<g:image_link>
    {%- if product.media|length > 1 -%}
        "{%- for mediaAssociation in product.media|slice(0, 5) -%}
            {{ mediaAssociation.media.url }}
            {%- if not loop.last -%},{%- endif -%}
        {%- endfor -%}"
    {%- endif -%}
</g:image_link>

<additional_image_link>
    {% for img in product.media.elements %}
        {{ img.media.url }},
    {% endfor %}
</additional_image_link>


<g:condition>new</g:condition>
<g:availability>in_stock</g:availability>

For your information: We import the products via Connector Plugin from Plentymarkets into SW6 and have no problems with the order of the images whatsoever. In the shop itself, everything is displayed in the correct way and the cover images are assigned accordingly. Only the export feed from Shopware does not correspond to the order of the images.

What could be the reason for this?

Doubled by https://forum.shopware.com/t/xml-csv-shopping-feed-reihenfolge-der-produktbilder/98381/2 (German Forum)

Hello devdrop,
I don’t have a direct solution for this. However, you can create your own solution for many things with TWIG.

The For loop only runs through the additional images from beginning to end in the standard order. To be honest, the question of a special sorting has not come up for me so far, but maybe you can solve it in a similar way as in this stackoverflow link: https://stackoverflow.com/questions/25194470/twig-sort-array-of-objects-by-field. The Position field in the product_media table could be used for this.

Best regards
Markus