/**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     switch ($operator) {
         case Operators::SINCE_LAST_JOB:
             if (!is_string($value)) {
                 throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
             }
             $this->addUpdatedSinceLastJob($field, $value);
             break;
         case Operators::SINCE_LAST_N_DAYS:
             if (!is_numeric($value)) {
                 throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
             }
             $this->addSinceLastNDays($field, $value);
             break;
         case Operators::NOT_BETWEEN:
             $values = $this->formatValues($field, $value);
             $field = current($this->qb->getRootAliases()) . '.' . $field;
             $this->applyNotBetweenFilter($field, $values);
             break;
         default:
             $value = Operators::IS_EMPTY === $operator ? null : $this->formatValues($field, $value);
             $field = current($this->qb->getRootAliases()) . '.' . $field;
             $this->qb->andWhere($this->prepareCriteriaCondition($field, $operator, $value));
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator && Operators::SINCE_LAST_JOB !== $operator && Operators::SINCE_LAST_N_DAYS !== $operator) {
         $value = $this->formatValues($field, $value);
     }
     if (Operators::SINCE_LAST_JOB === $operator) {
         if (!is_string($value)) {
             throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
         }
         $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]);
         $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED);
         if (null === $lastCompletedJobExecution) {
             return $this;
         }
         $lastJobStartTime = $lastCompletedJobExecution->getStartTime()->setTimezone(new \DateTimeZone('UTC'));
         $value = $lastJobStartTime->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     if (Operators::SINCE_LAST_N_DAYS === $operator) {
         if (!is_numeric($value)) {
             throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
         }
         $fromDate = new \DateTime(sprintf('%s days ago', $value), new \DateTimeZone('UTC'));
         $value = $fromDate->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($field, $operator, $value);
     return $this;
 }
 /**
  * Check if value is valid
  *
  * @param string      $field
  * @param mixed       $value
  * @param string|null $locale
  * @param string|null $scope
  */
 protected function checkValue($field, $value, $locale, $scope)
 {
     if (!is_numeric($value)) {
         throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
     }
     if (null === $locale || null === $scope) {
         throw InvalidArgumentException::localeAndScopeExpected($field, 'filter', 'completeness');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (!is_numeric($value) && null !== $value) {
         throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($value));
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($operator, $value, $field);
     return $this;
 }
 /**
  * Check if value is a valid identifier
  *
  * @param string $field
  * @param mixed  $value
  * @param string $filter
  */
 public static function checkIdentifier($field, $value, $filter)
 {
     $invalidIdField = static::hasProperty($field) && static::getProperty($field) === 'id' && !is_numeric($value);
     $invalidDefaultField = !static::hasProperty($field) && !is_numeric($value);
     if ($invalidIdField || $invalidDefaultField) {
         throw InvalidArgumentException::numericExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
     $invalidStringField = static::hasProperty($field) && static::getProperty($field) !== 'id' && !is_string($value);
     if ($invalidStringField) {
         throw InvalidArgumentException::stringExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (!is_numeric($value) && null !== $value) {
         throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($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->prepareCriteriaCondition($backendField, $operator, $value);
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }
 function it_throws_an_exception_if_value_is_not_a_valid_array(AttributeInterface $attribute)
 {
     $attribute->getId()->willReturn(1);
     $attribute->getCode()->willReturn('color');
     $value = 'string';
     $this->shouldThrow(InvalidArgumentException::arrayExpected('color', 'filter', 'reference_data', $value))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
     $value = ['foo'];
     $this->shouldThrow(InvalidArgumentException::numericExpected('color', 'filter', 'reference_data', 'string'))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
 }
 function it_throws_an_exception_if_value_is_not_a_numeric(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('number_code');
     $this->shouldThrow(InvalidArgumentException::numericExpected('number_code', 'filter', 'number', gettype('WRONG')))->during('addAttributeFilter', [$attribute, '=', 'WRONG']);
 }
 function it_throws_an_exception_if_content_of_array_is_not_integer_or_empty()
 {
     $this->shouldThrow(InvalidArgumentException::numericExpected('groups', 'filter', 'groups', gettype('WRONG')))->during('addFieldFilter', ['groups.id', 'IN', [1, 2, 'WRONG']]);
 }
 function it_throws_an_exception_if_the_content_of_value_are_not_numeric(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('options_code');
     $this->shouldThrow(InvalidArgumentException::numericExpected('options_code', 'filter', 'options', gettype('not numeric')))->during('addAttributeFilter', [$attribute, 'IN', [123, 'not numeric'], null, null, ['field' => 'options_code.id']]);
 }
 function it_throws_an_exception_if_value_is_not_an_integer()
 {
     $this->shouldThrow(InvalidArgumentException::numericExpected('completeness', 'filter', 'completeness', gettype('123')))->during('addFieldFilter', ['completeness', '=', '12a3', 'fr_FR', 'mobile']);
 }
 function it_throws_an_exception_if_value_is_not_a_numeric_for_since_last_n_days()
 {
     $this->shouldThrow(InvalidArgumentException::numericExpected('updated', 'filter', 'updated', 'string'))->during('addFieldFilter', ['updated', 'SINCE LAST N DAYS', 'csv_product_export', null, null]);
 }