How does product visibility work in Shopware 6?
Are you familiar with how product visibility works? In this blog article, we are gonna explain, so keep reading till the end!
Shopware 6 comes with three distinct product visibility settings by default. Go to Catalogues > Product > Open a Product for Edit > Visibility & Structure > select the sales channels which you want to make visible:
You’ll get visibility option, you can see on below image
|Type of Option||Details|
|Visible||The product will Appear in the category navigation and in the search results.|
|Hide in Listing||The product will Not Appear in the category Product Listing but, it will appear in the search result.|
|Hide in Listings and search||The product will Not Appear anywhere. Not even in category or search.|
Get a free consultation from Shopware experts
on do's and don't
Look At Code:
Please have a look at the product visibility database table. The visibility column will have the following values: 10, 20, or 30. Most of them are probably in 30. Why? They symbolize the desired visibility.
public const VISIBILITY_LINK = 10; /*Hide in Listing & Search*/
public const VISIBILITY_SEARCH = 20; /*Hide in Listing*/
public const VISIBILITY_ALL = 30; /*Visible everywhere*/
Tip to be consistent:
Please utilize the existing visibility variables to maintain consistency throughout the code. Please don't utilize numbers that are hard-coded, such as 10, 20, or 30. Example:
/*BAD*/ 'visibilities' => [[ 'salesChannelId' => $this->salesChannel->getSalesChannel()->getId(), 'visibility' => 30, ]], /*GOOD*/ 'visibilities' => [[ 'salesChannelId' => $this->salesChannel->getSalesChannel()->getId(), 'visibility' => ProductVisibilityDefinition::VISIBILITY_ALL, ]],
Thank you for keeping up till the end! Hope you enjoyed it!