/** * Create attribute on category to enable/disable name indexation for search. * * @return void */ private function addCategoryNameSearchAttribute() { // Installing the new attribute. $this->eavSetup->addAttribute(Category::ENTITY, 'use_name_in_product_search', ['type' => 'int', 'label' => 'Use category name in product search', 'input' => 'select', 'source' => 'Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Boolean', 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, 'required' => true, 'default' => 1, 'visible' => true, 'note' => "If the category name is used for fulltext search on products.", 'sort_order' => 150, 'group' => 'General Information']); // Set the attribute value to 1 for all existing categories. $this->updateAttributeDefaultValue(Category::ENTITY, 'use_name_in_product_search', 1); }
/** * Add entity attribute. Overwritten for flat entities support * * @param int|string $entityTypeId * @param string $code * @param array $attr * @return $this */ public function addAttribute($entityTypeId, $code, array $attr) { if (isset($this->_flatEntityTables[$entityTypeId]) && $this->_flatTableExist($this->_flatEntityTables[$entityTypeId])) { $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr); } else { parent::addAttribute($entityTypeId, $code, $attr); } return $this; }