Example #1
0
 /**
  * {@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(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'media');
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($attribute, $value);
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s.originalFilename', ProductQueryUtility::NORMALIZED_FIELD, $field);
     switch ($operator) {
         case Operators::NOT_EQUAL:
             $this->qb->field($field)->exists(true);
             $this->qb->field($field)->notEqual($value);
             break;
         case Operators::IS_NOT_EMPTY:
             $this->qb->field($field)->exists(true);
             break;
         case Operators::IS_EMPTY:
             $this->qb->field($field)->exists(false);
             break;
         default:
             $value = $this->prepareValue($operator, $value);
             $this->qb->field($field)->equals($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);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($field, $operator, $value);
     return $this;
 }
 /**
  * @param array $result
  * @param array $attribute
  * @param string $locale
  * @param string $scope
  *
  * @return array
  */
 protected function prepareMediaData(array $result, array $attribute, $locale, $scope)
 {
     $attributeCode = $attribute['code'];
     $backendType = $attribute['backendType'];
     $value = $result[$attributeCode];
     if (AttributeTypes::IMAGE === $attribute['attributeType'] && isset($value[$backendType])) {
         $normalizedData = $result['normalizedData'];
         $attributeCode = ProductQueryUtility::getNormalizedValueField($attributeCode, $attribute['localizable'], $attribute['scopable'], $locale, $scope);
         $value[$backendType] = $normalizedData[$attributeCode];
     }
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'price');
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($attribute, $value);
         $value['data'] = (double) $value['data'];
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s.%s.data', ProductQueryUtility::NORMALIZED_FIELD, $field, $value['currency']);
     $this->applyFilter($field, $operator, $value['data']);
     return $this;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'date');
     if (Operators::IS_EMPTY === $operator || Operators::IS_NOT_EMPTY === $operator) {
         $value = null;
     } else {
         $value = $this->formatValues($attribute->getCode(), $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 = [])
 {
     $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 = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'string');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'string');
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $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', 'options');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'options');
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($options['field'], $value);
         if (FieldFilterHelper::CODE_PROPERTY === FieldFilterHelper::getProperty($options['field'])) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value, $attribute);
         } else {
             $value = array_map('intval', $value);
         }
     }
     $field = sprintf('%s.%s.id', ProductQueryUtility::NORMALIZED_FIELD, ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope));
     $this->applyFilter($field, $operator, $value);
     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'];
     $normalizedData = $result['normalizedData'];
     $fromNormData = [AttributeTypes::OPTION_SIMPLE_SELECT, AttributeTypes::OPTION_MULTI_SELECT];
     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];
 }
 /**
  * @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 (AttributeTypes::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];
 }