0
votes

similar to this question in sw-entity-many-to-many-select in a own admin module product variants without names are visible i want to display the assigned products on my storefront page, like it is discribed here (in a tab with {% sw_include '@Storefront/storefront/component/product/card/box-standard.html.twig' with {'product': product} %} ): https://docs.shopware.com/en/shopware-platform-dev-en/how-to/indepth-guide-bundle/storefront . This works, but the image and the price is not loaded, but the other informations are shown. Has anybody an idea why or what is missing?

See: Screenshot

1
Can you share the code how you load the products that you want to display? In the docs it is described in this chapter: docs.shopware.com/en/shopware-platform-dev-en/how-to/… It looks like you need to additionally include the product.cover and product.prices associations.j_elfering
Thanks for your answer and help. I add the products over: $criteria->addAssociation('products') When i change it to: $criteria->addAssociation('products.cover'); the images were loaded. But when i add $criteria->addAssociation('products.cover'); $criteria->addAssociation('products.prices'); the prices don't loaded.sschreier

1 Answers

1
votes

Instead of loading the product with the "normal" product repository you can use the sales_channel.product.repository repository instead. The sales-channel repositories load the entities with all necessary associations, so you don't have to load those associations yourself.

For details you can check the \Shopware\Core\Content\Product\SalesChannel\SalesChannelProductDefinition definition, in that class the additional associations and fields are configured that are loaded by the sales channel repository.

Keep in mind that the product sales channel repository implements the \Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface instead of the \Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface and thus the search method requires a SalesChannelContext instead of the Context.