예제 #1
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;
 }
 /**
  * {@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;
 }
 /**
  * Check that unit families of 2 attributes are consistent.
  *
  * @param AttributeInterface $fromAttribute
  * @param AttributeInterface $toAttribute
  * @param string             $type
  *
  * @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
  */
 protected function checkUnitFamily(AttributeInterface $fromAttribute, AttributeInterface $toAttribute, $type)
 {
     try {
         $this->attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute);
     } catch (\LogicException $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $fromAttribute->getCode() . ' && ' . $toAttribute->getCode(), 'copier', $type);
     }
 }
 function it_throws_an_exception_when_unit_families_are_not_consistent($attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute)
 {
     $e = new \LogicException('Metric families are not the same for attributes: "fromCode" and "toCode".');
     $fromAttribute->getCode()->willReturn('fromCode');
     $toAttribute->getCode()->willReturn('toCode');
     $attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute)->willThrow($e);
     $this->shouldThrow(InvalidArgumentException::expectedFromPreviousException($e, 'fromCode && toCode', 'copier', 'concrete'))->during('testUnitFamily', [$fromAttribute, $toAttribute]);
 }
 /**
  * Check locale and scope are valid
  *
  * @param AttributeInterface $attribute
  * @param string             $locale
  * @param string             $scope
  * @param string             $type
  *
  * @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
  */
 protected function checkLocaleAndScope(AttributeInterface $attribute, $locale, $scope, $type)
 {
     try {
         $this->attrValidatorHelper->validateLocale($attribute, $locale);
         $this->attrValidatorHelper->validateScope($attribute, $scope);
     } catch (\LogicException $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'copier', $type);
     }
 }
 function it_throws_an_exception_when_scope_is_expected_but_not_existing($attrValidatorHelper, AttributeInterface $attribute)
 {
     $e = new \LogicException('Attribute "attributeCode" expects an existing scope, "ecommerce" given.');
     $attribute->getCode()->willReturn('attributeCode');
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(true);
     $attrValidatorHelper->validateLocale($attribute, null)->shouldBeCalled();
     $attrValidatorHelper->validateScope($attribute, 'ecommerce')->willThrow($e);
     $this->shouldThrow(InvalidArgumentException::expectedFromPreviousException($e, 'attributeCode', 'setter', 'concrete'))->during('testLocaleAndScope', [$attribute, null, 'ecommerce']);
 }
예제 #7
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', 'string');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'string');
     if ($operator !== Operators::IS_EMPTY) {
         $this->checkValue($options['field'], $value);
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($field, $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);
         }
     }
     $mongoField = sprintf('%s.%s.id', ProductQueryUtility::NORMALIZED_FIELD, ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope));
     $this->applyFilter($operator, $value, $mongoField, $options);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->optionsResolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'reference data simple select');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'reference_data');
     if (Operators::IS_EMPTY !== $operator) {
         $field = $options['field'];
         $this->checkValue($field, $value);
         if (FieldFilterHelper::CODE_PROPERTY === FieldFilterHelper::getProperty($field)) {
             $value = $this->valueCodesToIds($attribute, $value);
         }
         $this->addNonEmptyFilter($attribute, $operator, $value, $locale, $scope);
     } else {
         $this->addEmptyFilter($attribute, $locale, $scope);
     }
     return $this;
 }
예제 #10
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', 'string');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'string');
     if ($operator !== Operators::IS_EMPTY) {
         $this->checkValue($options['field'], $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
     $backendField = sprintf('%s.%s', $joinAlias, $attribute->getBackendType());
     if ($operator === Operators::IS_EMPTY) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->andWhere($this->prepareCriteriaCondition($backendField, $operator, $value));
     } else {
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
         $condition .= ' AND ' . $this->prepareCondition($backendField, $operator, $value);
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }