Ejemplo n.º 1
0
 /**
  * Prepare Fulltext index value for product
  *
  * @param array $indexData
  * @param array $productData
  * @param int $storeId
  * @return string
  */
 protected function _prepareProductIndex($indexData, $productData, $storeId)
 {
     $index = array();
     foreach ($this->_getSearchableAttributes('static') as $attribute) {
         $attributeCode = $attribute->getAttributeCode();
         if (isset($productData[$attributeCode])) {
             $value = $this->_getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId);
             if ($value) {
                 //For grouped products
                 if (isset($index[$attributeCode])) {
                     if (!is_array($index[$attributeCode])) {
                         $index[$attributeCode] = array($index[$attributeCode]);
                     }
                     $index[$attributeCode][] = $value;
                 } else {
                     $index[$attributeCode] = $value;
                 }
             }
         }
     }
     foreach ($indexData as $attributeData) {
         foreach ($attributeData as $attributeId => $attributeValue) {
             $value = $this->_getAttributeValue($attributeId, $attributeValue, $storeId);
             if (!is_null($value) && $value !== false) {
                 $code = $this->_getSearchableAttribute($attributeId)->getAttributeCode();
                 //For grouped products
                 if (isset($index[$code])) {
                     if (!is_array($index[$code])) {
                         $index[$code] = array($index[$code]);
                     }
                     $index[$code][] = $value;
                 } else {
                     $index[$code] = $value;
                 }
             }
         }
     }
     $product = $this->_getProductEmulator()->setId($productData['entity_id'])->setTypeId($productData['type_id'])->setStoreId($storeId);
     $typeInstance = $this->_getProductTypeInstance($productData['type_id']);
     if ($data = $typeInstance->getSearchableData($product)) {
         $index['options'] = $data;
     }
     if (isset($productData['in_stock'])) {
         $index['in_stock'] = $productData['in_stock'];
     }
     if ($this->_engine) {
         if ($this->_engine->allowAdvancedIndex()) {
             $index += $this->_engine->addAllowedAdvancedIndexField($productData);
         }
         return $this->_engine->prepareEntityIndex($index, $this->_separator);
     }
     return Mage::helper('catalogsearch')->prepareIndexdata($index, $this->_separator);
 }
Ejemplo n.º 2
0
 /**
  * Retrieve attribute source value for search
  *
  * @param int $attributeId
  * @param mixed $value
  * @param int $storeId
  * @return mixed
  */
 protected function _getAttributeValue($attributeId, $value, $storeId)
 {
     $attribute = $this->_getSearchableAttribute($attributeId);
     if (!$attribute->getIsSearchable()) {
         if ($this->_engine->allowAdvancedIndex()) {
             if ($attribute->getAttributeCode() == 'visibility') {
                 return $value;
             } elseif (!($attribute->getIsVisibleInAdvancedSearch() || $attribute->getIsFilterable() || $attribute->getIsFilterableInSearch() || $attribute->getUsedForSortBy())) {
                 return null;
             }
         } else {
             return null;
         }
     }
     if ($attribute->usesSource()) {
         if ($this->_engine->allowAdvancedIndex()) {
             return $value;
         }
         $attribute->setStoreId($storeId);
         $value = $attribute->getSource()->getIndexOptionText($value);
         if (is_array($value)) {
             $value = implode($this->_separator, $value);
         } elseif (empty($value)) {
             $inputType = $attribute->getFrontend()->getInputType();
             if ($inputType == 'select' || $inputType == 'multiselect') {
                 return null;
             }
         }
     } elseif ($attribute->getBackendType() == 'datetime') {
         $value = $this->_getStoreDate($storeId, $value);
     } else {
         $inputType = $attribute->getFrontend()->getInputType();
         if ($inputType == 'price') {
             $value = Mage::app()->getStore($storeId)->roundPrice($value);
         }
     }
     $value = preg_replace("#\\s+#siu", ' ', trim(strip_tags($value)));
     return $value;
 }