Display variants in the listing

Hello,

I’ve seen there’s a block called frontend_listing_box_variant_description in file themes/Frontend/Bare/frontend/listing/product-box/box-basic.tpl that seems to be prepared to display the product variant in the listing, but I can’t make it work and there’s no information about this on any guide (at least one I can find)

{* Variant description *}
{block name='frontend_listing_box_variant_description'}
	{if $sArticle.attributes.swagVariantConfiguration}
		
			
				{foreach $sArticle.attributes.swagVariantConfiguration->get('value') as $group}
					
						{$group.groupName}: {$group.optionName} {if !$group@last}|{/if}
					
				{/foreach}
			
		
	{/if}
{/block}

Anyone have this working?

Still trying to achieve this but from a different approach. Now I’m able to display the variants in the listing but I modified the sArticles file, now I’m trying to extend that file to not change core files. I’m using the getListing function to retrieve the variants and return them into the sArticles array.

I’ve created a plugin and subscribed to Enlight_Controller_Action_PostDispatchSecure_Frontend_Listing but now I don’t know how to get the current sArticles array to modify it as I did on the getListing function.

Someone to point me in the right direction?

Thanks!

Hello Roberto

**'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Listing'** =\> **'onPostDispatchListing'** , **'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Search'** =\> **'onPostDispatchSearch'** ,

_/\*\*_ _\*_ _@param_ _\Enlight\_Event\_EventArgs $args_ _\*/_ **public function** onPostDispatchListing(\Enlight\_Controller\_ActionEventArgs $args) { $request = $args-\>getSubject()-\>Request(); $action = $args-\>getSubject(); $response = $action-\>Response(); $view = $action-\>View(); **if** (!$request-\>isDispatched() || $response-\>isException() || !$view-\>hasTemplate() ) { **return false** ; } $assignData = $view-\>getAssign( **'sArticles'** ); _print\_r_($assignData); **exit** ; } _/\*\*_ _\*_ _@param_ _\Enlight\_Event\_EventArgs $args_ _\*/_ **public function** onPostDispatchSearch(\Enlight\_Controller\_ActionEventArgs $args) { $request = $args-\>getSubject()-\>Request(); $action = $args-\>getSubject(); $response = $action-\>Response(); $view = $action-\>View(); **if** (!$request-\>isDispatched() || $response-\>isException() || !$view-\>hasTemplate() ) { **return false** ; } $assignData = $view-\>getAssign( **'sSearchResults'** ); _print\_r_($assignData); **exit** ; }

For widgets or emotions you need to extend **Enlight\_Controller\_Action\_PostDispatch\_Widgets**, in case you want to extend similar/related articles on detail page, you need extend **Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Detail** and get **sArticle**[’ sRelatedArticles’]/[’ sSimilarArticles’]

I hope my answer will help you.

This is absolutely brilliant! Thank you very much @odessite‍ this helped me a lot to achieve what I was trying to do, I owe you a beer at least!

Hello, could someone explain what to do from the beginning?
I’m sorry, but it’s hard to understand, if you are new with shopware.
Thanks a lot.

I would advise to extend the productlisting service to resolve the issue on a higher level.

The additional variant data can be stored as a parameter for the sArticle which is available in the tpl-file.

Hi Sition,
can you give a quick hint on how to accomplish extending the service.
I am stuck in developing a proper extension… I implemented the ListProductServiceInterface and the ContextServiceInterface and managed to retrieve the article data, but now I don’t know how to query all according variants…

Can you help out?
Thanks a lot!

@Sition schrieb:

I would advise to extend the productlisting service to resolve the issue on a higher level.

The additional variant data can be stored as a parameter for the sArticle which is available in the tpl-file.