/** * Prepare Fulltext index value for product * * @param array $indexData * @param array $productData * @param int $storeId * @return string */ protected function prepareProductIndex($indexData, $productData, $storeId) { $index = []; foreach ($this->getSearchableAttributes('static') as $attribute) { $attributeCode = $attribute->getAttributeCode(); if (isset($productData[$attributeCode])) { $value = $this->getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId); if ($value) { if (isset($index[$attributeCode])) { if (!is_array($index[$attributeCode])) { $index[$attributeCode] = [$index[$attributeCode]]; } $index[$attributeCode][] = $value; } else { $index[$attributeCode] = $value; } } } } foreach ($indexData as $entityId => $attributeData) { foreach ($attributeData as $attributeId => $attributeValue) { $value = $this->getAttributeValue($attributeId, $attributeValue, $storeId); if (!is_null($value) && $value !== false) { $attributeCode = $this->getSearchableAttribute($attributeId)->getAttributeCode(); if (isset($index[$attributeCode])) { $index[$attributeCode][$entityId] = $value; } else { $index[$attributeCode] = [$entityId => $value]; } } } } if (!$this->engineProvider->get()->allowAdvancedIndex()) { $product = $this->getProductEmulator($productData['type_id'])->setId($productData['entity_id'])->setStoreId($storeId); $typeInstance = $this->getProductTypeInstance($productData['type_id']); $data = $typeInstance->getSearchableData($product); if ($data) { $index['options'] = $data; } } if ($this->engineProvider->get()) { return $this->engineProvider->get()->prepareEntityIndex($index, $this->separator); } return $this->catalogSearchData->prepareIndexdata($index, $this->separator); }
/** * @param null|string $expected * @param array $data * @dataProvider prepareIndexdataDataProvider */ public function testPrepareIndexdata($expected, array $data) { $this->assertEquals($expected, $this->_model->prepareIndexdata($data['index'], $data['separator'])); }
/** * Prepare index array as a string glued by separator * * @param array $index * @param string $separator * @return string */ public function prepareEntityIndex($index, $separator = ' ') { return $this->_catalogSearchData->prepareIndexdata($index, $separator); }