CategoryCondition example

(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);

            $products = array_values($result->getProducts());
            $products = array_map(function DListProduct $product) {
                $cheapestPrice = $product->getCheapestPrice();
                if (!$cheapestPrice instanceof Price) {
                    return $product;
                }
                
$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')) {
            
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 = [];
        


    /** * @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,
            
/** * @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;
    }
}
Home | Imprint | This part of the site doesn't use cookies.