addCondition example

return $condition instanceof CreateDateCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(CreateDateCondition $condition, QueryBuilder $query): void
    {
        $date = new DateTime();
        $intervalSpec = 'P' . $condition->getDays() . 'D';
        $interval = new DateInterval($intervalSpec);
        $date->sub($interval);

        $suffix = md5(json_encode($condition, JSON_THROW_ON_ERROR));
        $key = ':createDateFrom' . $suffix;

        
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;

class IsCustomerSinceConditionHandler implements ConditionHandlerInterface
{
    public function supports(ConditionInterface $condition)
    {
        return $condition instanceof IsCustomerSinceCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(IsCustomerSinceCondition $condition, QueryBuilder $query): void
    {
        switch ($condition->getOperator()) {
            case ConditionInterface::OPERATOR_EQ:
                $query->andWhere('customer.firstlogin = :IsCustomerSinceCondition');
                break;
            case ConditionInterface::OPERATOR_NEQ:
                $query->andWhere('customer.firstlogin != :IsCustomerSinceCondition');
                break;
            
$edit = [];
    $edit['label'] = $this->randomMachineName(16);
    $view_id = $edit['id'] = strtolower($this->randomMachineName(16));
    $edit['description'] = $this->randomMachineName(16);
    $edit['page[create]'] = TRUE;
    $edit['page[path]'] = 'admin/foo';

    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($edit, 'Save and edit');

    $parameters = new MenuTreeParameters();
    $parameters->addCondition('id', $menu_link_content->getPluginId());
    $result = \Drupal::menuTree()->load('admin', $parameters);
    $plugin_definition = end($result)->link->getPluginDefinition();
    $this->assertEquals('view.' . $view_id . '.page_1', $plugin_definition['route_name']);

    $this->clickLink('No menu');

    $this->submitForm([
      'menu[type]' => 'default tab',
      'menu[title]' => 'Menu title',
    ], 'Apply');

    
return $condition instanceof CustomerGroupCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(CustomerGroupCondition $condition, QueryBuilder $query): void
    {
        $key = ':customerGroupIds' . md5(json_encode($condition, JSON_THROW_ON_ERROR));

        $query->leftJoin(
            'product',
            's_articles_avoid_customergroups',
            'avoidCustomerGroup',
            'avoidCustomerGroup.articleID = product.id AND avoidCustomerGroup.customerGroupId IN ('
class AgeConditionHandler implements ConditionHandlerInterface
{
    use DynamicConditionParserTrait;

    public function supports(ConditionInterface $condition)
    {
        return $condition instanceof AgeCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(AgeCondition $condition, QueryBuilder $query): void
    {
        $this->parse(
            $query,
            's_customer_search_index',
            'customer',
            'age',
            $condition->getValue(),
            $condition->getOperator()
        );
Request $request,
        Criteria $criteria,
        ProductAttributeFacet $facet
    ) {
        if (!$this->isAttributeInRequest($facet$request)) {
            return;
        }
        $data = $request->getParam($facet->getFormFieldName());

        switch ($facet->getMode()) {
            case ProductAttributeFacet::MODE_BOOLEAN_RESULT:
                $criteria->addCondition(
                    new ProductAttributeCondition(
                        $facet->getField(),
                        ProductAttributeCondition::OPERATOR_NOT_IN,
                        [false]
                    )
                );

                return;

            case ProductAttributeFacet::MODE_RADIO_LIST_RESULT:
                $criteria->addCondition(
                    
return $condition instanceof PropertyCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(PropertyCondition $condition, QueryBuilder $query): void
    {
        $tableKey = $condition->getName();

        $suffix = md5(json_encode($condition, JSON_THROW_ON_ERROR));

        if ($query->hasState('property_' . $tableKey)) {
            return;
        }
        
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;

class OrderedOnDeviceConditionHandler implements ConditionHandlerInterface
{
    public function supports(ConditionInterface $condition)
    {
        return $condition instanceof OrderedOnDeviceCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(OrderedOnDeviceCondition $condition, QueryBuilder $query): void
    {
        $wheres = [];
        foreach ($condition->getDevices() as $i => $id) {
            $wheres[] = 'customer.ordered_on_devices LIKE :device' . $i;
            $query->setParameter(':device' . $i, '%|' . $id . '|%');
        }
        $query->andWhere(implode(' OR ', $wheres));
    }
}
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;

class NotOrderedWithDeliveryConditionHandler implements ConditionHandlerInterface
{
    public function supports(ConditionInterface $condition): bool
    {
        return $condition instanceof NotOrderedWithDeliveryCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query): void
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(NotOrderedWithDeliveryCondition $condition, QueryBuilder $query): void
    {
        $likes = [];
        foreach ($condition->getDispatchIds() as $i => $number) {
            $likes[] = 'ordered_with_deliveries LIKE :delivery' . $i;
        }

        $query->where('customernumber NOT IN ( SELECT customernumber FROM s_customer_search_index WHERE '

    public function getOne($id$offset = 0, $limit = 50, $conditions = '', $sortings = '')
    {
        $this->checkPrivilege('read');

        $criteria = new Criteria();

        $parsedConditions = $this->getConditions($id$conditions);

        foreach ($parsedConditions as $condition) {
            $criteria->addCondition($condition);
        }
        $decodedSortings = json_decode($sortings, true);
        if (!empty($decodedSortings)) {
            $unserializedSortings = $this->reflectionHelper->unserialize($decodedSortings, '');

            foreach ($unserializedSortings as $sorting) {
                if (!$sorting instanceof SortingInterface) {
                    continue;
                }
                $criteria->addSorting($sorting);
            }
        }
'last-child' => $this->translateLastChild(...),
            'first-of-type' => $this->translateFirstOfType(...),
            'last-of-type' => $this->translateLastOfType(...),
            'only-child' => $this->translateOnlyChild(...),
            'only-of-type' => $this->translateOnlyOfType(...),
            'empty' => $this->translateEmpty(...),
        ];
    }

    public function translateRoot(XPathExpr $xpath): XPathExpr
    {
        return $xpath->addCondition('not(parent::*)');
    }

    public function translateScopePseudo(XPathExpr $xpath): XPathExpr
    {
        return $xpath->addCondition('1');
    }

    public function translateFirstChild(XPathExpr $xpath): XPathExpr
    {
        return $xpath
            ->addStarPrefix()
            
$a$b] = Parser::parseSeries($function->getArguments());
        } catch (SyntaxErrorException $e) {
            throw new ExpressionErrorException(sprintf('Invalid series: "%s".', implode('", "', $function->getArguments())), 0, $e);
        }

        $xpath->addStarPrefix();
        if ($addNameTest) {
            $xpath->addNameTest();
        }

        if (0 === $a) {
            return $xpath->addCondition('position() = '.($last ? 'last() - '.($b - 1) : $b));
        }

        if ($a < 0) {
            if ($b < 1) {
                return $xpath->addCondition('false()');
            }

            $sign = '<=';
        } else {
            $sign = '>=';
        }

        
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;

class NotOrderedProductOfCategoryConditionHandler implements ConditionHandlerInterface
{
    public function supports(ConditionInterface $condition): bool
    {
        return $condition instanceof NotOrderedProductOfCategoryCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query): void
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(NotOrderedProductOfCategoryCondition $condition, QueryBuilder $query): void
    {
        $likes = [];
        foreach ($condition->getCategoryIds() as $i => $id) {
            $likes[] = 'ordered_products_of_categories LIKE :category' . $i;
        }

        $query->where('customernumber NOT IN ( SELECT customernumber FROM s_customer_search_index WHERE '
return $condition instanceof CategoryCondition;
    }

    /** * {@inheritdoc} */
    public function generateCondition(
        ConditionInterface $condition,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(CategoryCondition $condition, QueryBuilder $query): void
    {
        $joinName = self::STATE_NAME;
        $counter = 1;

        while ($query->hasState($joinName)) {
            ++$counter;
            $joinName = self::STATE_NAME . $counter;
        }

        
use Shopware\Bundle\SearchBundleDBAL\QueryBuilder;

class OrderedWithDeliveryConditionHandler implements ConditionHandlerInterface
{
    public function supports(ConditionInterface $condition)
    {
        return $condition instanceof OrderedWithDeliveryCondition;
    }

    public function handle(ConditionInterface $condition, QueryBuilder $query)
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(OrderedWithDeliveryCondition $condition, QueryBuilder $query): void
    {
        $wheres = [];
        foreach ($condition->getDispatchIds() as $i => $number) {
            $wheres[] = 'customer.ordered_with_deliveries LIKE :delivery' . $i;
            $query->setParameter(':delivery' . $i, '%|' . $number . '|%');
        }
        $query->andWhere(implode(' OR ', $wheres));
    }
}
Home | Imprint | This part of the site doesn't use cookies.