/**
  * Create a mapping field from an attribute.
  *
  * @param AttributeInterface $attribute Entity attribute.
  *
  * @return \Smile\ElasticsuiteCatalog\Model\Eav\Indexer\Fulltext\Datasource\AbstractAttributeData
  */
 private function initField(AttributeInterface $attribute)
 {
     $fieldName = $attribute->getAttributeCode();
     $fieldConfig = $this->attributeHelper->getMappingFieldOptions($attribute);
     if ($attribute->usesSource()) {
         $optionFieldName = $this->attributeHelper->getOptionTextFieldName($fieldName);
         $fieldType = 'string';
         $fieldOptions = ['name' => $optionFieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];
         $this->fields[$optionFieldName] = $this->fieldFactory->create($fieldOptions);
         // Reset parent field values : only the option text field should be used for spellcheck and autocomplete.
         $fieldConfig['is_used_in_spellcheck'] = false;
         $fieldConfig['is_used_in_autocomplete'] = false;
         $fieldConfig['is_searchable'] = false;
     }
     $fieldType = $this->attributeHelper->getFieldType($attribute);
     $fieldOptions = ['name' => $fieldName, 'type' => $fieldType, 'fieldConfig' => $fieldConfig];
     $this->fields[$fieldName] = $this->fieldFactory->create($fieldOptions);
     return $this;
 }
Example #2
0
 /**
  * Ensure types of numerical values is correct before indexing.
  *
  * @param AttributeInterface $attribute Product attribute.
  * @param mixed              $value     Raw value.
  *
  * @return mixed
  */
 private function prepareSimpleIndexAttributeValue(AttributeInterface $attribute, $value)
 {
     if ($attribute->getBackendType() == 'decimal') {
         $value = floatval($value);
     } elseif ($attribute->getBackendType() == 'int') {
         $value = intval($value);
     }
     return $value;
 }