If you go on a detail page of a variant product, than to another product and than back to the first variant product: The first variant product will be in the slider.
Fix: in "RecentlyViewedProductService" exchange the function "buildRecentProductSliderStruct" with this code:
public function buildRecentProductSliderStruct(SalesChannelContext $context, ?array $excludeProductIds = []): ProductSliderStruct
{
$products = $this->getRecentProductEntities($context) ?? new ProductCollection([]);
if (!empty($excludeProductIds)) {
foreach ($excludeProductIds as $productId) {
if($products->has($productId)){
$products->remove($productId);
continue;
}
// If the $productId is from a child, exclude the parent
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $productId));
$searchResult = $this->salesChannelProductRepository->search($criteria, $context);
$product = $searchResult->getEntities()->first();
$products = $products->filter(function(SalesChannelProductEntity $element) use ($product) {
if($product->getParentId() !== $element->getId()){
return true;
}
return false;
});
}
}
$productSliderStruct = new ProductSliderStruct();
$productSliderStruct->setProducts($products);
return $productSliderStruct;
}
If you go on a detail page of a variant product, than to another product and than back to the first variant product: The first variant product will be in the slider.
Fix: in "RecentlyViewedProductService" exchange the function "buildRecentProductSliderStruct" with this code: