Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider includes current variant product #14

Open
paul-per opened this issue Jun 9, 2023 · 2 comments
Open

Slider includes current variant product #14

paul-per opened this issue Jun 9, 2023 · 2 comments
Assignees

Comments

@paul-per
Copy link

paul-per commented Jun 9, 2023

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;
}
@vienthuong vienthuong self-assigned this Jun 12, 2023
@LouisEiermann
Copy link
Contributor

@vienthuong Isnt this fixed already? I noticed that you can give the slider an option to exclude the current variant

@vienthuong
Copy link
Owner

@LouisEiermann sorry I don't have time to check it in anytime soon, could you give it a go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants