/**
  * Retrieve attribute source value for search
  *
  * @param int $attributeId
  * @param mixed $valueId
  * @param int $storeId
  * @return string
  */
 private function getAttributeValue($attributeId, $valueId, $storeId)
 {
     $attribute = $this->getSearchableAttribute($attributeId);
     $value = $this->engine->processAttributeValue($attribute, $valueId);
     if (false !== $value && $attribute->getIsSearchable() && $attribute->usesSource() && $this->engine->allowAdvancedIndex()) {
         $attribute->setStoreId($storeId);
         $valueText = (array) $attribute->getSource()->getIndexOptionText($valueId);
         $pieces = array_filter(array_merge([$value], $valueText));
         $value = implode($this->separator, $pieces);
     }
     $value = preg_replace('/\\s+/siu', ' ', trim(strip_tags($value)));
     return $value;
 }
 /**
  * @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']));
 }
Example #3
0
 /**
  * Regenerate search index for specific store
  *
  * @param int $storeId Store View Id
  * @param int|array $productIds Product Entity Id
  * @return \Generator
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function rebuildStoreIndex($storeId, $productIds = null)
 {
     if ($productIds !== null) {
         $productIds = array_unique(array_merge($productIds, $this->getProductIdsFromParents($productIds)));
     }
     // prepare searchable attributes
     $staticFields = [];
     foreach ($this->getSearchableAttributes('static') as $attribute) {
         $staticFields[] = $attribute->getAttributeCode();
     }
     $dynamicFields = ['int' => array_keys($this->getSearchableAttributes('int')), 'varchar' => array_keys($this->getSearchableAttributes('varchar')), 'text' => array_keys($this->getSearchableAttributes('text')), 'decimal' => array_keys($this->getSearchableAttributes('decimal')), 'datetime' => array_keys($this->getSearchableAttributes('datetime'))];
     // status and visibility filter
     $visibility = $this->getSearchableAttribute('visibility');
     $status = $this->getSearchableAttribute('status');
     $statusIds = $this->catalogProductStatus->getVisibleStatusIds();
     $allowedVisibility = $this->engine->getAllowedVisibility();
     return $this->iteratorFactory->create(['storeId' => $storeId, 'productIds' => $productIds, 'staticFields' => $staticFields, 'dynamicFields' => $dynamicFields, 'visibility' => $visibility, 'allowedVisibility' => $allowedVisibility, 'status' => $status, 'statusIds' => $statusIds]);
 }