[Vuejs]-How Do I Display Product Images In Shopware 6 Administration

0👍

The media elements of the products are associations that are not loaded automatically, but you can configure the criteria, so that those associations will be loaded directly when you fetch the products. Refer to the official docs for detailed infos.

In you case that means to load the cover image / or all product images, you would have to adjust the criteria you use for fetching the products the following way

        logProducts(){    
            const criteria = new Criteria();
            criteria.addAssociation('cover.media');
            criteria.addAssociation('media.media');


            this.productRepository
                .search(criteria, Shopware.Context.api)
                .then(result => {
                 console.log(result[0]);
                });
        },

Then to link to the cover image you can use:

<sw-card title="Watermark">
    <img src="product.cover.media.url" alt="Product Image" />

</sw-card>

You find all the media elements of the product as an array under product.media and can also use product.media[0].media.url to link to those images.

Leave a comment