createBaseCriteria example

$product->setListingPrice(
                $prices[\count($prices) - 1]
            );
        }
    }

    private function generateCriteria(Element $element, ShopContextInterface $context): Criteria
    {
        $categoryId = (int) $element->getConfig()->get('article_category');
        $type = $element->getConfig()->get('article_type');

        $criteria = $this->criteriaFactory->createBaseCriteria([$categoryId]$context);
        $criteria->limit(1);

        switch ($type) {
            case self::TYPE_TOPSELLER:
                $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_NEWCOMER:
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_RANDOM:
                $criteria->addSorting(new RandomSorting());
        }
$this->storeFrontCriteriaFactory = $storeFrontCriteriaFactory;
        $this->connection = $connection;
        $this->batchSize = $batchSize;
    }

    /** * {@inheritdoc} */
    public function getUrls(Context $routingContext, ShopContextInterface $shopContext)
    {
        $criteria = $this->storeFrontCriteriaFactory
            ->createBaseCriteria([$shopContext->getShop()->getCategory()->getId()]$shopContext);
        $criteria->setFetchCount(false);
        $criteria->limit($this->batchSize);

        if ($this->lastId) {
            $criteria->addBaseCondition(new LastProductIdCondition($this->lastId));
        }

        $productNumberSearchResult = $this->productNumberSearch->search($criteria$shopContext);

        if (\count($productNumberSearchResult->getProducts()) === 0) {
            return [];
        }
if (!empty($category)) {
            $category = (int) $category;
        } elseif ($this->frontController->Request()->getQuery('sCategory')) {
            $category = (int) $this->frontController->Request()->getQuery('sCategory');
        } else {
            $category = $this->categoryId;
        }

        $context = $this->contextService->getShopContext();

        $criteria = $this->storeFrontCriteriaFactory->createBaseCriteria([$category]$context);
        $criteria->limit($sLimitChart);

        $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));

        $criteria->setFetchCount(false);

        $result = $this->searchService->search($criteria$context);
        $products = $this->legacyStructConverter->convertListProductStructList($result->getProducts());

        Shopware()->Events()->notify(
            'Shopware_Modules_Articles_GetArticleCharts',
            [
break;

            case self::TYPE_ARTICLE_OR_BLOG:
                $isBlog = (bool) $element->getConfig()->get('blog_category');
                $categoryId = (int) $element->getConfig()->get('category_selection');

                if ($isBlog) {
                    break;
                }

                $criteria = $this->criteriaFactory->createBaseCriteria([$categoryId]$context);
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                $criteria->limit(50);

                $collection->getBatchRequest()->setCriteria($key$criteria);
                break;
        }
    }

    public function handle(ResolvedDataCollection $collection, Element $element, ShopContextInterface $context)
    {
        $imageType = $element->getConfig()->get('image_type');
        

    private function getProductSliderData($category$offset$limit$sort = null)
    {
        /** @var ShopContext $context */
        $context = Shopware()->Container()->get(ContextServiceInterface::class)->getShopContext();
        /** @var StoreFrontCriteriaFactory $factory */
        $factory = Shopware()->Container()->get(StoreFrontCriteriaFactoryInterface::class);
        $criteria = $factory->createBaseCriteria([$category]$context);

        $criteria->offset($offset)
            ->limit($limit);

        switch ($sort) {
            case 'price_asc':
                $criteria->addSorting(new PriceSorting(SortingInterface::SORT_ASC));
                break;
            case 'price_desc':
                $criteria->addSorting(new PriceSorting(SortingInterface::SORT_DESC));
                break;
            
if (empty($fallback)) {
            return $result;
        }

        $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();
        }
private function generateCriteria(Element $element, ShopContextInterface $context): Criteria
    {
        $type = $element->getConfig()->get(self::SLIDER_TYPE_KEY);
        $limit = (int) $element->getConfig()->get('article_slider_max_number');
        $categoryId = (int) $element->getConfig()->get('article_slider_category');

        if ($type === self::TYPE_PRODUCT_STREAM) {
            $categoryId = $context->getShop()->getCategory()->getId();
        }

        $criteria = $this->criteriaFactory->createBaseCriteria([$categoryId]$context);
        $criteria->limit($limit);

        switch ($type) {
            case self::TYPE_LOWEST_PRICE:
                $criteria->addSorting(new PriceSorting(SortingInterface::SORT_ASC));
                break;
            case self::TYPE_HIGHEST_PRICE:
                $criteria->addSorting(new PriceSorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_TOPSELLER:
                $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                

    private function readProductUrls(array $categoryIds)
    {
        if (empty($categoryIds)) {
            return [];
        }

        $criteria = $this->storeFrontCriteriaFactory->createBaseCriteria($categoryIds$this->contextService->getShopContext());

        $productIds = $this->readProductUrlsRecursive($criteria);

        $statement = $this->connection->executeQuery(
            'SELECT id,changetime FROM s_articles WHERE id IN (:articleIds)',
            [':articleIds' => $productIds],
            [':articleIds' => Connection::PARAM_INT_ARRAY]
        );

        $products = [];
        while ($product = $statement->fetch()) {
            
Home | Imprint | This part of the site doesn't use cookies.