Smile\ElasticsuiteCatalog\Helper\Attribute::getMappingFieldOptions PHP Метод

getMappingFieldOptions() публичный Метод

Parse attribute to get mapping field creation parameters.
public getMappingFieldOptions ( Magento\Eav\Model\Entity\Attribute\AttributeInterface $attribute ) : array
$attribute Magento\Eav\Model\Entity\Attribute\AttributeInterface Product attribute.
Результат array
    public function getMappingFieldOptions(AttributeInterface $attribute)
    {
        $options = ['is_searchable' => $attribute->getIsSearchable(), 'is_filterable' => $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch(), 'search_weight' => $attribute->getSearchWeight(), 'is_used_for_sort_by' => $attribute->getUsedForSortBy()];
        if ($attribute->getIsUsedInSpellcheck()) {
            $options['is_used_in_spellcheck'] = true;
        }
        if ($attribute->getIsUsedInAutocomplete()) {
            $options['is_used_in_autocomplete'] = true;
        }
        return $options;
    }

Usage Example

 /**
  * 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;
 }