addBaseCondition example



        foreach ($products as $product) {
            $result[] = $product->getId();
        }

        sort($result, SORT_NUMERIC);

        $lastProductId = $result[\count($result) - 1];

        $criteria->removeBaseCondition('last_product_id');
        $criteria->addBaseCondition(new LastProductIdCondition($lastProductId));

        return array_merge($result$this->readProductUrlsRecursive($criteria));
    }

    /** * Reads the blog item urls * * @param int $parentId * * @return array */
    
null,
            2,
            'frontend/listing/filter/facet-currency-range.tpl'
        );
    }

    private function buildQuery(Criteria $reverted, Criteria $criteria, ShopContextInterface $context): QueryBuilder
    {
        $tmp = clone $reverted;
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        foreach ($conditions as $condition) {
            $tmp->addBaseCondition($condition);
        }

        $query = $this->queryBuilderFactory->createQuery($tmp$context);

        $this->listingPriceSwitcher->joinPrice($query$criteria$context);
        $query->select('listing_price.cheapest_price');
        $query->setFirstResult(0);
        $query->setMaxResults(1);
        $query->addGroupBy('product.id');

        return $query;
    }
$this->addHeightCondition($request$criteria);
        $this->addWidthCondition($request$criteria);
        $this->addLengthCondition($request$criteria);
    }

    private function addCategoryCondition(Request $request, Criteria $criteria): void
    {
        if ($request->has('sCategory')) {
            /** @var array<numeric-string> $ids */
            $ids = explode('|', $request->getParam('sCategory')) ?: [];

            $criteria->addBaseCondition(new CategoryCondition($ids));
        } elseif ($request->has('categoryFilter')) {
            /** @var array<numeric-string> $ids */
            $ids = explode('|', $request->getParam('categoryFilter')) ?: [];

            $criteria->addCondition(new CategoryCondition($ids));
        }
    }

    private function addManufacturerCondition(Request $request, Criteria $criteria): void
    {
        if (!$request->has('sSupplier')) {
            
/** * {@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 [];
        }

        // Load all available product ids         $productIds = array_map(function DBaseProduct $baseProduct) {
            return $baseProduct->getId();
        },
$isSelectionSpecified = $data['isSelectionSpecified'];
        }

        if ($isSelectionSpecified === true || !$product->hasConfigurator()) {
            $data = $this->legacyEventManager->fireArticleByIdEvents($data$this);

            return $data;
        }

        $criteria = new Criteria();
        foreach ($selection as $groupId => $optionId) {
            $criteria->addBaseCondition(
                new VariantCondition([(int) $optionId], true, (int) $groupId)
            );
        }

        $service = Shopware()->Container()->get(VariantListingPriceServiceInterface::class);

        $result = new ProductSearchResult(
            [$product->getNumber() => $product],
            1,
            [],
            $criteria,
            
$this->assignConditions($productStream$criteria);

        $sortings = $criteria->getSortings();
        if (empty($sortings)) {
            $this->assignSortings($productStream$criteria);
        }
    }

    private function prepareSelectionStream(array $productStream, Criteria $criteria): void
    {
        $productIds = $this->getProductIds((int) $productStream['id']);
        $criteria->addBaseCondition(new ProductIdCondition($productIds));

        $sortings = $criteria->getSortings();
        if (empty($sortings)) {
            $this->assignSortings($productStream$criteria);
        }
    }

    /** * @return int[] */
    private function getProductIds(int $productStreamId): array
    {


    /** * @param int[] $categoryIds * * @return Criteria */
    public function createBaseCriteria($categoryIds, ShopContextInterface $context)
    {
        $criteria = new Criteria();

        $criteria->addBaseCondition(new CategoryCondition($categoryIds));

        if ($this->config->get('hideNoInStock')) {
            $criteria->addBaseCondition(new IsAvailableCondition());
        }

        $criteria->addBaseCondition(
            new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()])
        );

        $this->eventManager->notify('Shopware_SearchBundle_Create_Base_Criteria', [
            'criteria' => $criteria,
            


            $criteria->offset($this->Request()->getParam('start', 0));
            $criteria->limit($this->Request()->getParam('limit', 20));

            $context = $this->createContext(
                (int) $this->Request()->getParam('shopId'),
                (int) $this->Request()->getParam('currencyId'),
                $this->Request()->getParam('customerGroupKey')
            );

            $criteria->addBaseCondition(
                new CustomerGroupCondition([$context->getCurrentCustomerGroup()->getId()])
            );

            $category = $context->getShop()->getCategory()->getId();
            $criteria->addBaseCondition(
                new CategoryCondition([$category])
            );

            $result = Shopware()->Container()->get(ProductSearchInterface::class)
                ->search($criteria$context);

            
/** * @return Criteria */
    public function createCriteria(Request $request, ShopContextInterface $context)
    {
        $criteria = $this->criteriaFactory->createListingCriteria($request$context);

        $criteria->removeBaseCondition('category');
        $criteria->resetFacets();

        $category = $context->getShop()->getCategory()->getId();
        $criteria->addBaseCondition(new CategoryCondition([$category]));

        return $criteria;
    }
}
ContextServiceInterface $contextService,
        MediaServiceInterface $mediaService
    ) {
        $this->queryBuilderFactory = $queryBuilderFactory;
        $this->contextService = $contextService;
        $this->mediaService = $mediaService;
    }

    public function load(int $categoryId, ?int $start, ?int $limit, CustomSorting $customSorting): array
    {
        $criteria = new Criteria();
        $criteria->addBaseCondition(new CategoryCondition([$categoryId]));
        $criteria->addSorting(new ManualSorting());
        $criteria->offset($start);
        $criteria->limit($limit);

        foreach ($customSorting->getSortings() as $sorting) {
            $criteria->addSorting($sorting);
        }

        $query = $this->queryBuilderFactory->createQueryWithSorting($criteria$this->contextService->getShopContext());

        $data = [];
        
$this->setDefaultSorting($sortings);

            $this->view->assign('sortings', $sortings);
        }

        $criteria = $this->storeFrontCriteriaFactory
            ->createListingCriteria($this->Request()$context);

        if ($condition = $criteria->getCondition('manufacturer')) {
            $criteria->removeCondition('manufacturer');
            $criteria->addBaseCondition($condition);
        }

        $categoryProducts = Shopware()->Modules()->Articles()->sGetArticlesByCategory(
            $context->getShop()->getCategory()->getId(),
            $criteria
        );
        if (!\is_array($categoryProducts)) {
            $categoryProducts = ['facets' => []];
        }

        $manufacturer = $this->manufacturerService->get(
            
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.