/**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AttributeInterface $attribute, $direction, $locale = null, $scope = null)
 {
     $sortField = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $this->qb->sort(ProductQueryUtility::NORMALIZED_FIELD . '.' . $sortField, $direction);
     $this->qb->sort('_id');
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     list($data, $currency) = explode(' ', $value);
     $data = (double) $data;
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $field = sprintf('%s.%s', $field, $currency);
     $fieldData = sprintf('%s.data', $field);
     switch ($operator) {
         case '<':
             $this->qb->field($fieldData)->lt($data);
             break;
         case '<=':
             $this->qb->field($fieldData)->lte($data);
             break;
         case '>':
             $this->qb->field($fieldData)->gt($data);
             break;
         case '>=':
             $this->qb->field($fieldData)->gte($data);
             break;
         case 'EMPTY':
             $this->qb->field($fieldData)->equals(null);
             break;
         default:
             $this->qb->field($fieldData)->equals($data);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->addFieldFilter($field, $operator, $value);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'boolean');
     if (!is_bool($value)) {
         throw InvalidArgumentException::booleanExpected($attribute->getCode(), 'filter', 'boolean', gettype($value));
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $this->addFieldFilter($field, $operator, $value, $locale, $scope, $options);
     return $this;
 }
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'date');
     if (Operators::IS_EMPTY === $operator) {
         $value = null;
     } else {
         $value = $this->formatValues($attribute->getCode(), $value);
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $this->addFieldFilter($field, $operator, $value);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (Operators::IS_EMPTY !== $operator) {
         $field = $options['field'];
         $this->checkValue($field, $value);
         if (FieldFilterHelper::CODE_PROPERTY === FieldFilterHelper::getProperty($field)) {
             $value = $this->valueCodesToIds($attribute, $value);
         }
     }
     $field = sprintf('%s.%s.id', ProductQueryUtility::NORMALIZED_FIELD, ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope));
     $this->applyFilter($operator, $value, $field);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'price');
     $this->checkValue($attribute, $value);
     if (Operators::IS_EMPTY !== $operator) {
         $value['data'] = (double) $value['data'];
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $field = sprintf('%s.%s', $field, $value['currency']);
     $fieldData = sprintf('%s.data', $field);
     $this->applyFilter($operator, $fieldData, $value['data']);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'media');
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s.originalFilename', ProductQueryUtility::NORMALIZED_FIELD, $field);
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($attribute, $value);
         $value = $this->prepareValue($operator, $value);
         $this->qb->field($field)->equals($value);
     } else {
         $this->qb->field($field)->exists(false);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'metric');
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($attribute, $value);
         $value = $this->convertValue($attribute, $value);
     } else {
         $value = null;
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $fieldData = sprintf('%s.baseData', $field);
     $this->applyFilter($operator, $fieldData, $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', '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;
 }
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $field = sprintf('%s.id', $field);
     if (in_array('empty', $value)) {
         unset($value[array_search('empty', $value)]);
         $expr = new Expr();
         $expr = $expr->field($field)->exists(false);
         $this->qb->addOr($expr);
     }
     if (count($value) > 0) {
         $value = array_map('intval', $value);
         $expr = new Expr();
         $expr->field($field)->in($value);
         $this->qb->addOr($expr);
     }
     return $this;
 }
 /**
  * @param array  $result
  * @param array  $attribute
  * @param string $locale
  * @param string $scope
  *
  * @return array
  */
 public function transform(array $result, array $attribute, $locale, $scope)
 {
     $attributeCode = $attribute['code'];
     $properties = $attribute['properties'];
     if (isset($properties['reference_data_name']) && '' !== $properties['reference_data_name']) {
         $normalizedData = $result['normalizedData'];
         $fieldCode = ProductQueryUtility::getNormalizedValueField($attributeCode, $attribute['localizable'], $attribute['scopable'], $locale, $scope);
         $backendType = $attribute['backendType'];
         $references = isset($normalizedData[$fieldCode]) ? $normalizedData[$fieldCode] : [];
         if (AbstractAttributeType::BACKEND_TYPE_REF_DATA_OPTION === $backendType) {
             $references = $this->filterOptionValues($references, $locale);
         } else {
             foreach ($references as $indexReference => $reference) {
                 $references[$indexReference] = $this->filterOptionValues($reference, $locale);
             }
         }
         $result[$attributeCode][$attribute['properties']['reference_data_name']] = $references;
     }
     return $result[$attributeCode];
 }
 /**
  * @param array  $result
  * @param array  $attribute
  * @param string $locale
  * @param string $scope
  *
  * @return array
  */
 public function transform(array $result, array $attribute, $locale, $scope)
 {
     $attributeCode = $attribute['code'];
     $normalizedData = $result['normalizedData'];
     $fromNormData = array('pim_catalog_simpleselect', 'pim_catalog_multiselect');
     if (in_array($attribute['attributeType'], $fromNormData)) {
         $fieldCode = ProductQueryUtility::getNormalizedValueField($attributeCode, $attribute['localizable'], $attribute['scopable'], $locale, $scope);
         $backendType = $attribute['backendType'];
         $options = isset($normalizedData[$fieldCode]) ? $normalizedData[$fieldCode] : [];
         if ($backendType === 'option') {
             $options = $this->filterOptionValues($options, $locale);
         } else {
             foreach ($options as $indexOption => $option) {
                 $options[$indexOption] = $this->filterOptionValues($option, $locale);
             }
         }
         $result[$attributeCode][$backendType] = $options;
     }
     return $result[$attributeCode];
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AbstractAttribute $attribute, $operator, $value)
 {
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $this->addFieldFilter($field, $operator, $value);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeSorter(AbstractAttribute $attribute, $direction)
 {
     $sortField = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $this->context);
     $this->qb->sort(ProductQueryUtility::NORMALIZED_FIELD . '.' . $sortField, $direction);
     return $this;
 }