hasBaseCondition example



    /** * @return Criteria */
    private function getSearchCriteria(Request $request, ShopContextInterface $context)
    {
        $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);
            
use Shopware\Bundle\SearchBundle\Criteria;
use Shopware\Bundle\SearchBundle\CriteriaPartInterface;
use Shopware\Bundle\SearchBundle\FacetResult\FacetResultGroup;
use Shopware\Bundle\SearchBundle\FacetResult\RangeFacetResult;
use Shopware\Bundle\SearchBundle\FacetResult\ValueListFacetResult;
use Shopware\Bundle\SearchBundle\FacetResultInterface;

class FacetFilter implements FacetFilterInterface
{
    public function add(Criteria $criteria)
    {
        if ($criteria->hasBaseCondition('immediate_delivery')) {
            $criteria->removeFacet('immediate_delivery');
        }

        if ($criteria->hasBaseCondition('shipping_free')) {
            $criteria->removeFacet('shipping_free');
        }

        if ($criteria->hasBaseCondition('vote_average')) {
            $criteria->removeFacet('vote_average');
        }

        
Home | Imprint | This part of the site doesn't use cookies.