コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($field, $value);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('group', $value);
         }
     }
     $rootAlias = $this->qb->getRootAlias();
     $entityAlias = $this->getUniqueAlias('filter' . FieldFilterHelper::getCode($field));
     $this->qb->leftJoin($rootAlias . '.' . FieldFilterHelper::getCode($field), $entityAlias);
     switch ($operator) {
         case Operators::IN_LIST:
             $this->qb->andWhere($this->qb->expr()->in($entityAlias . '.id', $value));
             break;
         case Operators::NOT_IN_LIST:
             $this->qb->andWhere($this->qb->expr()->notIn($rootAlias . '.id', $this->getNotInSubquery(FieldFilterHelper::getCode($field), $value)));
             break;
         case Operators::IS_EMPTY:
         case Operators::IS_NOT_EMPTY:
             $this->qb->andWhere($this->prepareCriteriaCondition($entityAlias . '.id', $operator, null));
             break;
     }
     return $this;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'option');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'option');
     $field = $options['field'];
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($field, $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode(), true);
     // prepare join value condition
     $optionAlias = $joinAlias . '.option';
     if (Operators::IS_EMPTY === $operator) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->andWhere($this->qb->expr()->isNull($optionAlias));
     } else {
         // inner join to value
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value);
         }
         $condition .= ' AND ( ' . $this->qb->expr()->in($optionAlias, $value) . ' ) ';
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $categoryIds = $value;
     if ($operator !== Operators::UNCLASSIFIED) {
         $this->checkValue($field, $value);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $categoryIds = $this->objectIdResolver->getIdsFromCodes('category', $value);
         }
     }
     switch ($operator) {
         case Operators::IN_LIST:
             $this->itemCategoryRepo->applyFilterByCategoryIds($this->qb, $categoryIds, true);
             break;
         case Operators::NOT_IN_LIST:
             $this->itemCategoryRepo->applyFilterByCategoryIds($this->qb, $categoryIds, false);
             break;
         case Operators::IN_CHILDREN_LIST:
             $categoryIds = $this->getAllChildrenIds($categoryIds);
             $this->itemCategoryRepo->applyFilterByCategoryIds($this->qb, $categoryIds, true);
             break;
         case Operators::NOT_IN_CHILDREN_LIST:
             $categoryIds = $this->getAllChildrenIds($categoryIds);
             $this->itemCategoryRepo->applyFilterByCategoryIds($this->qb, $categoryIds, false);
             break;
         case Operators::UNCLASSIFIED:
             $this->itemCategoryRepo->applyFilterByUnclassified($this->qb);
             break;
         case Operators::IN_LIST_OR_UNCLASSIFIED:
             $this->itemCategoryRepo->applyFilterByCategoryIdsOrUnclassified($this->qb, $categoryIds);
             break;
     }
     return $this;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'options');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'options');
     if ($operator != Operators::IS_EMPTY) {
         $this->checkValue($options['field'], $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
     $joinAliasOpt = $this->getUniqueAlias('filterO' . $attribute->getCode());
     $backendField = sprintf('%s.%s', $joinAliasOpt, 'id');
     if (Operators::IS_EMPTY === $operator) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->leftJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt)->andWhere($this->qb->expr()->isNull($backendField));
     } else {
         if (FieldFilterHelper::getProperty($options['field']) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value);
         }
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope))->innerJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt, 'WITH', $this->qb->expr()->in($backendField, $value));
     }
     return $this;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($field, $value);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('family', $value);
         }
     }
     $fieldCode = FieldFilterHelper::getCode($field);
     switch ($operator) {
         case Operators::IN_LIST:
             $expr = new Expr();
             $this->qb->addAnd($expr->field($fieldCode)->in($value));
             break;
         case Operators::NOT_IN_LIST:
             $this->qb->field($fieldCode)->notIn($value);
             break;
         case Operators::IS_EMPTY:
             $exists = new Expr();
             $equals = new Expr();
             $expr = new Expr();
             $exists->field($fieldCode)->exists(false);
             $equals->field($fieldCode)->equals(null);
             $expr->addOr($exists)->addOr($equals);
             $this->qb->addAnd($expr);
             break;
     }
     return $this;
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkValue($field, $value);
     $value = is_array($value) ? $value : [$value];
     if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
         $value = $this->objectIdResolver->getIdsFromCodes('group', $value);
     }
     $value = array_map('intval', $value);
     $this->applyFilter($value, 'groupIds', $operator);
     return $this;
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($field, $value);
         if (FieldFilterHelper::CODE_PROPERTY === FieldFilterHelper::getProperty($field)) {
             $value = $this->objectIdResolver->getIdsFromCodes('group', $value);
         } else {
             $value = array_map('intval', $value);
         }
     }
     $this->applyFilter('groupIds', $operator, $value);
     return $this;
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'option');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'option');
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($options['field'], $value);
         if (FieldFilterHelper::getProperty($options['field']) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value, $attribute);
         }
     }
     $mongoField = sprintf('%s.%s.id', ProductQueryUtility::NORMALIZED_FIELD, ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope));
     $this->applyFilter($operator, $value, $mongoField, $options);
     return $this;
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($field, $value);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('group', $value);
         }
     }
     $rootAlias = $this->qb->getRootAlias();
     $entityAlias = $this->getUniqueAlias('filter' . FieldFilterHelper::getCode($field));
     $this->qb->leftJoin($rootAlias . '.' . FieldFilterHelper::getCode($field), $entityAlias);
     if ($operator === Operators::IN_LIST) {
         $this->qb->andWhere($this->qb->expr()->in($entityAlias . '.id', $value));
     } elseif ($operator === Operators::NOT_IN_LIST) {
         $this->qb->andWhere($this->qb->expr()->orX($this->qb->expr()->notIn($entityAlias . '.id', $value), $this->qb->expr()->isNull($entityAlias . '.id')));
     } elseif ($operator === Operators::IS_EMPTY) {
         $this->qb->andWhere($this->qb->expr()->isNull($entityAlias . '.id'));
     }
     return $this;
 }