示例#1
0
 /**
  * Retrieve filter array
  *
  * @param Enterprise_Search_Model_Resource_Collection $collection
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param string|array $value
  * @return array
  */
 protected function _getSearchParam($collection, $attribute, $value)
 {
     if (empty($value) || isset($value['from']) && empty($value['from']) && isset($value['to']) && empty($value['to'])) {
         return false;
     }
     $localeCode = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
     $languageCode = Mage::helper('enterprise_search')->getLanguageCodeByLocaleCode($localeCode);
     $languageSuffix = $languageCode ? '_' . $languageCode : '';
     $field = $attribute->getAttributeCode();
     $backendType = $attribute->getBackendType();
     $frontendInput = $attribute->getFrontendInput();
     if ($frontendInput == 'multiselect') {
         $field = 'attr_multi_' . $field;
     } elseif ($frontendInput == 'select' || $frontendInput == 'boolean') {
         $field = 'attr_select_' . $field;
     } elseif ($backendType == 'decimal') {
         $field = 'attr_decimal_' . $field;
     } elseif ($backendType == 'datetime') {
         $field = 'attr_datetime_' . $field;
         if (is_array($value)) {
             foreach ($value as &$val) {
                 if (!is_empty_date($val)) {
                     $date = new Zend_Date($val, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
                     $val = $date->toString(Zend_Date::ISO_8601) . 'Z';
                 }
             }
         } else {
             if (!is_empty_date($value)) {
                 $date = new Zend_Date($value, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
                 $value = $date->toString(Zend_Date::ISO_8601) . 'Z';
             }
         }
     } elseif (in_array($backendType, $this->_textFieldTypes)) {
         $field .= $languageSuffix;
     }
     if ($attribute->usesSource()) {
         $attribute->setStoreId(Mage::app()->getStore()->getId());
         foreach ($value as &$val) {
             $val = $attribute->getSource()->getOptionText($val);
         }
     }
     if (empty($value)) {
         return array();
     } else {
         return array($field => $value);
     }
 }
 private function _getAttributeOptionIdByValue(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $value)
 {
     $options = $attribute->getSource()->getAllOptions(false);
     foreach ($options as $option) {
         if ($option['label'] == $value) {
             return $option['value'];
         }
     }
     return false;
 }
 /**
  * Retrieve data to be insterted after processing attribute
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param int $storeId
  * @return array
  */
 protected function getInsertValues($attribute, $storeId)
 {
     $options = array();
     if ($attribute->getSourceModel()) {
         $options = $attribute->getSource()->getAllOptions();
     } else {
         $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setStoreFilter($storeId)->setPositionOrder('asc')->setAttributeFilter($attribute->getId())->load();
         $options = $collection->toOptionArray();
     }
     $data = array();
     foreach ($options as $option) {
         // Generate url value
         $urlValue = $this->getHelper()->transliterate($option['label']);
         // Check if this url key is taken and add -{count}
         $count = 0;
         $origUrlValue = $urlValue;
         do {
             $found = false;
             foreach ($data as $line) {
                 if ($line['url_value'] == $urlValue) {
                     $found = true;
                 }
             }
             if ($found) {
                 $urlValue = $origUrlValue . '-' . ++$count;
             }
         } while ($found);
         $data[] = array('attribute_code' => $attribute->getAttributeCode(), 'attribute_id' => $attribute->getId(), 'store_id' => $storeId, 'option_id' => $option['value'], 'url_key' => $this->getHelper()->transliterate($attribute->getStoreLabel($storeId)), 'url_value' => $urlValue);
     }
     return $data;
 }