Do you know how product visibility work? Let me explain in this blogpost.
By default, Shopware 6 has three different product visibilities. Go to product Visibility & structure > Set visibility for selected Sales Channels
:
Then you will see the visibility options:
Type | Explanation |
---|---|
Visible | Product will be displayed in category navigation Product will be displayed in search |
Hide in Listings | Product will *NOT* be displayed in category navigation Product will be displayed in search |
Hide in Listings and search | Product will *NOT* be displayed anywhere. Neither on category or search |
Please, take a look in the database table product_visibility
. You will see on the visibility
column the following values: 10
, 20
or 30
. Probably mostly 30
. Why? They represent the above visibilities.
use Shopware\Core\Content\Product\Aggregate\ProductVisibility;
ProductVisibilityDefinition::VISIBILITY_LINK; // 10 - Hide in Listings and search
ProductVisibilityDefinition::VISIBILITY_SEARCH; // 20 - Hide in Listings
ProductVisibilityDefinition::VISIBILITY_ALL; // 30 - Visible
In order to keep consistency all over the code, please use the existing visibility constants. Please don't use hard coded numbers like 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 so much! Hope you enjoyed!