I am working on Magento-2.4.5-p2 Version, as per my requirement I need to restrict some product based on customer type. For that I’ve used the following code and it’s working as expected.
Totally I’ve 3 product Product ids 1,2,3.
Here I just restricted Product 1
di.xml
<type name="MagentoElasticsearch7SearchAdapterMapper">
<plugin name="elastcisearch_mapper_plugin"
type="WilliamsCommerceProductRestrictionPluginElasticsearch7SearchAdapterMapper" />
</type>
Plugin Class :
public function afterBuildQuery(MagentoElasticsearch7SearchAdapterMapper $subject, array $searchQuery) : array
{
$filteredIds = ["1"];
$searchQuery['body']['query']['bool']['must_not'] = ['ids' => ['values' => $filteredIds]];
return $searchQuery;
}
The above functionaity are working and the product 1 is restricted.
The client wants to to see the “out of stock” Product, so I’ve enabled “Dispaly Out of Stock”, but after enabling the option the product is not restricted.
Now all the products are displaying in front-end.
Kindly share your thoughts & Ideas to fix the issue. Thanks in advance.