示例#1
0
 public function setObject($object, $attributes = null)
 {
     try {
         parent::setObject($object);
         Mage::helper('solr/log')->addDebugMessage('Add Landingpage #' . $object->getId() . ' to index of store ' . $this->getStoreId());
         $staticFields = DMC_Solr_Model_SolrServer_Adapter_Landingpage_TypeConverter::getStaticFields();
         foreach ($staticFields as $key => $defaultValue) {
             $methodName = '_get_value_' . $key;
             if (method_exists($this, $methodName)) {
                 $value = $this->{$methodName}($object);
             } elseif (is_null($defaultValue)) {
                 continue;
             } else {
                 $value = $defaultValue;
             }
             if (is_array($value)) {
                 foreach ($value as $datum) {
                     $this->setMultiValue($key, $datum);
                 }
             } else {
                 $this->_fields[$key] = $value;
             }
         }
         if (is_null($attributes)) {
             $attributes = $object->getAttributes();
         }
     } catch (DMC_Solr_Model_Catalog_Product_Exception $e) {
         Mage::helper('solr/log')->addDebugMessage($e->getMessage());
         return false;
     }
     return true;
 }
示例#2
0
 /**
  * Prepare object data for Solr
  *
  */
 public function setObject($object, $attributes = null)
 {
     try {
         parent::setObject($object);
         $staticFields = DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter::getStaticFields();
         foreach ($staticFields as $key => $defaultValue) {
             $methodName = '_get_value_' . $key;
             if (method_exists($this, $methodName)) {
                 $value = $this->{$methodName}($object);
             } elseif (is_null($defaultValue)) {
                 continue;
             } else {
                 $value = $defaultValue;
             }
             if (is_array($value)) {
                 foreach ($value as $datum) {
                     $this->setMultiValue($key, $datum);
                 }
             } else {
                 $this->_fields[$key] = $value;
             }
         }
         $this->_updatePositions($this->_fields, $object);
         if (is_null($attributes)) {
             $attributes = $object->getAttributes();
         }
         foreach ($attributes as $name => $attribute) {
             $attrCode = $attribute->getAttributeCode();
             if (!DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter::isStaticField($attrCode)) {
                 $inputType = $attribute->getFrontendInput();
                 $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter($inputType);
                 if (isset($typeConverter->solr_index)) {
                     if ($storeId = $object->getStoreId()) {
                         $attribute->setStoreId($storeId);
                     }
                     $values = $attribute->getFrontend()->getValue($object);
                     $indexes = $object->getData($attrCode);
                     if ($attrCode == 'tier_price' || $attrCode == 'group_price') {
                         if (is_array($indexes)) {
                             $res = '';
                             foreach ($indexes as $one) {
                                 if (isset($one['website_price'])) {
                                     $res .= $one['website_price'] . ' ';
                                 }
                             }
                             $indexes = $res;
                         }
                     } elseif ($inputType === 'multiselect') {
                         $values = is_string($values) && strlen($values) ? explode(',', $values) : array();
                         $indexes = is_string($indexes) && strlen($indexes) ? explode(',', $indexes) : array();
                         array_walk($values, array($this, 'itemTrim'));
                         array_walk($indexes, array($this, 'itemTrim'));
                     } elseif ($inputType === 'date') {
                         $indexes = $this->dateConvert($indexes);
                     }
                     if (($attribute->getData('is_searchable') || $attribute->getData('used_in_product_listing') || $attribute->getData('is_visible_in_advanced_search')) && $typeConverter->isSearchable()) {
                         $key = $typeConverter->solr_search_prefix . 'search_' . $attrCode;
                         if (is_array($indexes) && count($indexes)) {
                             foreach ($values as $value) {
                                 $this->setMultiValue($key, trim($value));
                             }
                         } elseif (is_string($indexes) && strlen($indexes)) {
                             $this->{$key} = trim($values);
                         }
                     }
                     $key = $typeConverter->solr_index_prefix . 'index_' . $attrCode;
                     if (is_array($indexes) && count($indexes)) {
                         foreach ($indexes as $index) {
                             //sm
                             //print_r($index);Exit;
                             // group prices seem to be a problem here
                             if (is_array($index)) {
                                 #foreach ( $index as $k => $v ) {
                                 #    $this->setMultiValue( $k, trim($v) );
                                 #}
                             } else {
                                 $this->setMultiValue($key, trim($index));
                             }
                         }
                     } elseif (is_string($indexes) && strlen($indexes)) {
                         $this->{$key} = trim($indexes);
                     }
                     if ($attribute->getData('used_for_sort_by') && $typeConverter->isSortable()) {
                         $key = $typeConverter->solr_sort_prefix . 'sort_' . $attrCode;
                         if (is_array($indexes) && count($indexes)) {
                             foreach ($values as $value) {
                                 $this->setMultiValue($key, trim($value));
                             }
                         } elseif (is_string($indexes) && strlen($indexes)) {
                             $this->{$key} = trim($values);
                         }
                     }
                 }
             }
         }
         Mage::helper('solr/log')->addDebugMessage('Added Product #' . $object->getId() . ' to solr object of store ' . $this->getStoreId());
     } catch (Exception $e) {
         die($e->getMessage());
         Mage::helper('solr/log')->addDebugMessage($e->getMessage());
         throw new Exception('Solr Error ' . $e->getMessage());
         //return false;
     }
     return true;
 }