andHaving example

->leftJoin('variant', 's_articles_attributes', 'productAttribute', 'productAttribute.articledetailsID = variant.id')
            ->leftJoin('product', 's_articles_supplier_attributes', 'manufacturerAttribute', 'manufacturerAttribute.supplierID = product.supplierID')
            ->leftJoin('product', 's_articles_top_seller_ro', 'topSeller', 'topSeller.article_id = product.id')
            ->leftJoin('variant', 's_articles_esd', 'esd', 'esd.articledetailsID = variant.id')
            ->leftJoin('esd', 's_articles_esd_attributes', 'esdAttribute', 'esdAttribute.esdID = esd.id')
            ->leftJoin('manufacturer', 's_media', 'manufacturerMedia', 'manufacturerMedia.path = manufacturer.img')
            ->where('variant.ordernumber IN (:numbers)')
            ->andWhere('variant.active = 1')
            ->andWhere('product.active = 1')
            ->setParameter(':numbers', $numbers, Connection::PARAM_STR_ARRAY);
        if ($this->config->get('hideNoInstock')) {
            $query->andHaving('__product_has_available_variants >= 1');
        }
        $this->fieldHelper->addProductTranslation($query$context);
        $this->fieldHelper->addVariantTranslation($query$context);
        $this->fieldHelper->addManufacturerTranslation($query$context);
        $this->fieldHelper->addUnitTranslation($query$context);
        $this->fieldHelper->addEsdTranslation($query$context);

        return $query;
    }

    private function getPriceCountQuery(string $key): QueryBuilder
    {
// Sort by _score primarily if the criteria has a score query or search term         if (!$this->hasScoreSorting($criteria)) {
            $criteria->addSorting(new FieldSorting('_score', FieldSorting::DESCENDING));
        }

        $minScore = array_map(fn (ScoreQuery $query) => $query->getScore()$criteria->getQueries());
        \assert(!empty($minScore));

        $minScore = min($minScore);

        $query->andHaving('_score >= :_minScore');
        $query->setParameter('_minScore', $minScore);
        $query->addState('_score');

        foreach ($queries->getParameters() as $key => $value) {
            $query->setParameter($key$value$queries->getType($key));
        }
    }

    private function hasGroupBy(Criteria $criteria, QueryBuilder $query): bool
    {
        if ($query->hasState(EntityReader::MANY_TO_MANY_LIMIT_QUERY)) {
            
$builder
                ->andWhere('c.shops IS NULL OR c.shops LIKE :shopLike')
                ->setParameter(':shopLike', '%|' . $shopId . '|%');
        }

        $builder = $this->addArticleCountSelect($builder, true);
        $builder = $this->addChildrenCountSelect($builder);

        if (isset($customerGroupId)) {
            $builder->leftJoin('c.customerGroups', 'cg', Join::WITH, 'cg.id = :cgId')
                    ->setParameter('cgId', $customerGroupId)
                    ->andHaving('COUNT(cg.id) = 0');
        }

        // to prevent a temporary table and file sort we have to set the same sort and group by condition         $builder->groupBy('c.parentId')
            ->addGroupBy('c.position')
            ->addGroupBy('c.id')
            ->orderBy('c.parentId', 'ASC')
            ->addOrderBy('c.position', 'ASC')
            ->addOrderBy('c.id', 'ASC');

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