SimilarProductCondition example

$limit = $this->config->get('similarLimit');
        if ($limit <= 0) {
            return $result;
        }

        $fallbackResult = [];
        foreach ($fallback as $product) {
            $criteria = $this->factory->createBaseCriteria([$context->getShop()->getCategory()->getId()]$context);
            $criteria->limit($limit);

            $condition = new SimilarProductCondition($product->getId()$product->getName());

            $criteria->addBaseCondition($condition);
            $criteria->addSorting(new PopularitySorting());
            $criteria->setFetchCount(false);

            $searchResult = $this->search->search($criteria$context);

            $fallbackResult[$product->getNumber()] = $searchResult->getProducts();
        }

        return $result + $fallbackResult;
    }
Home | Imprint | This part of the site doesn't use cookies.