/** * Prepare Fulltext index value for product * * @param array $indexData * @param array $productData * @param int $storeId * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function prepareProductIndex($indexData, $productData, $storeId) { $index = []; foreach ($this->getSearchableAttributes('static') as $attribute) { $attributeCode = $attribute->getAttributeCode(); if (isset($productData[$attributeCode])) { if ('store_id' === $attributeCode) { continue; } $value = $this->getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId); if ($value) { if (isset($index[$attribute->getId()])) { if (!is_array($index[$attribute->getId()])) { $index[$attribute->getId()] = [$index[$attribute->getId()]]; } $index[$attribute->getId()][] = $value; } else { $index[$attribute->getId()] = $value; } } } } foreach ($indexData as $entityId => $attributeData) { foreach ($attributeData as $attributeId => $attributeValue) { $value = $this->getAttributeValue($attributeId, $attributeValue, $storeId); if (!empty($value)) { if (isset($index[$attributeId])) { $index[$attributeId][$entityId] = $value; } else { $index[$attributeId] = [$entityId => $value]; } } } } $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; } return $this->engine->prepareEntityIndex($index, $this->separator); }
/** * @param null|string $expected * @param array $data * @dataProvider prepareEntityIndexDataProvider */ public function testPrepareEntityIndex($expected, array $data) { $this->assertEquals($expected, $this->target->prepareEntityIndex($data['index'], $data['separator'])); }