removeFacet example


    public function createListingCriteria(Request $request, ShopContextInterface $context)
    {
        $criteria = $this->createCriteriaFromRequest($request$context);

        $this->eventManager->notify('Shopware_SearchBundle_Create_Listing_Criteria', [
            'criteria' => $criteria,
            'request' => $request,
            'context' => $context,
        ]);

        $criteria->removeFacet('category');

        return $criteria;
    }

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

        
foreach ($facets as $facet) {
            $customFacet = $facet->getFacet();

            if ($customFacet instanceof FacetInterface) {
                $criteria->addFacet($customFacet);
            }
        }

        $this->facetFilter->add($criteria);

        $criteria->removeFacet('category');

        return $criteria;
    }

    /** * @param array<string, mixed> $categoryContent */
    private function loadCategoryListing(int $categoryId, array $categoryContent, ShopContextInterface $context): void
    {
        $sortings = $this->customSortingService->getSortingsOfCategories([$categoryId]$context);
        $sortings = array_shift($sortings);

        
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');
        }

        if ($criteria->hasBaseCondition('manufacturer')) {
            
Home | Imprint | This part of the site doesn't use cookies.