getBaseCondition example



    /** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $categoryCondition = $criteria->getBaseCondition('category');
        if (!$categoryCondition instanceof CategoryCondition) {
            return;
        }

        $search->addSort($this->getSorting($criteriaPart$categoryCondition));
    }

    private function getSorting(ManualSorting $criteriaPart, CategoryCondition $categoryCondition): FieldSort
    {
        $categoryId = $categoryCondition->getCategoryIds()[0];

        
$criteria = $this->createCriteriaFromRequest($request$context);

        $systemId = $context->getShop()->getCategory()->getId();

        if (!$criteria->hasBaseCondition('category')) {
            $criteria->addBaseCondition(new CategoryCondition([$systemId]));

            return $criteria;
        }

        /** @var CategoryCondition $condition */
        $condition = $criteria->getBaseCondition('category');

        if (!\in_array($systemId$condition->getCategoryIds())) {
            $criteria->removeBaseCondition('category');
            $criteria->addCondition($condition);
            $criteria->addBaseCondition(new CategoryCondition([$systemId]));
        }

        return $criteria;
    }

    /** * @return Criteria */
/** * @param FacetResultInterface[] $facets */
    private function switchPriceFilterValues(array $facets, Criteria $criteria)
    {
        /** @var RangeFacetResult|null $facet */
        $facet = $this->getFacetByName($facets, 'price');

        if ($facet && $criteria->hasBaseCondition('price')) {
            /** @var PriceCondition $condition */
            $condition = $criteria->getBaseCondition('price');

            $facet->setMin($condition->getMinPrice());
            if ($condition->getMaxPrice() != 0) {
                $facet->setMax($condition->getMaxPrice());
            }
        }
    }

    /** * @param FacetResultInterface[] $facets */
    
Home | Imprint | This part of the site doesn't use cookies.