getMinWidth example

 {
        $this->addCondition($condition$query);
    }

    private function addCondition(WidthCondition $condition, QueryBuilder $query): void
    {
        $this->variantHelper->joinVariants($query);

        $min = ':minWidth' . md5(json_encode($condition, JSON_THROW_ON_ERROR));
        $max = ':maxWidth' . md5(json_encode($condition, JSON_THROW_ON_ERROR));

        if ($condition->getMinWidth() > 0) {
            $query->andWhere('allVariants.width >= ' . $min);
            $query->setParameter($min$condition->getMinWidth());
        }

        if ($condition->getMaxWidth() > 0) {
            $query->andWhere('allVariants.width <= ' . $max);
            $query->setParameter($max$condition->getMaxWidth());
        }
    }
}
CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(WidthCondition $criteriaPart): RangeQuery
    {
        $range = [];
        if ($criteriaPart->getMinWidth()) {
            $range['gte'] = $criteriaPart->getMinWidth();
        }
        if ($criteriaPart->getMaxWidth()) {
            $range['lte'] = $criteriaPart->getMaxWidth();
        }

        return new RangeQuery('width', $range);
    }
}
Home | Imprint | This part of the site doesn't use cookies.