コード例 #1
0
 /**
  * Prepare search condition for attribute
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param string|array $value
  * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection
  * @return mixed
  */
 public function prepareCondition($attribute, $value, $collection)
 {
     $condition = false;
     if (is_array($value)) {
         if (!empty($value['from']) || !empty($value['to'])) {
             // range
             $condition = $value;
         } else {
             if ($attribute->getBackendType() == 'varchar') {
                 // multiselect
                 $condition = array('in_set' => $value);
             } else {
                 if (!isset($value['from']) && !isset($value['to'])) {
                     // select
                     $condition = array('in' => $value);
                 }
             }
         }
     } else {
         if (strlen($value) > 0) {
             if (in_array($attribute->getBackendType(), array('varchar', 'text', 'static'))) {
                 $condition = array('like' => '%' . $value . '%');
                 // text search
             } else {
                 $condition = $value;
             }
         }
     }
     return $condition;
 }
コード例 #2
0
ファイル: Advanced.php プロジェクト: jpbender/mage_virtual
 /**
  * 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);
     }
 }
コード例 #3
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return float|int|string
  */
 protected function _mapAttributeType(Mage_Catalog_Model_Resource_Eav_Attribute $attribute)
 {
     if ($attribute->getBackendType() == 'int') {
         return self::MAPPING_TYPE_INT;
     }
     if ($attribute->getBackendType() == 'decimal') {
         return self::MAPPING_TYPE_DOUBLE;
     }
     if ($attribute->getBackendType() == 'varchar' || $attribute->getBackendType() == 'text' || $attribute->getBackendType() == 'static') {
         return self::MAPPING_TYPE_STRING;
     }
     if ($attribute->getBackendType() == 'datetime') {
         return self::MAPPING_TYPE_DATE;
     }
     return self::MAPPING_TYPE_UNKNOWN;
 }
コード例 #4
0
 /**
  * Return Google Base Attribute Type By Product Attribute
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string Google Base Attribute Type
  */
 public function getGbaseAttributeType($attribute)
 {
     $typesMapping = array('price' => 'floatUnit', 'decimal' => 'numberUnit');
     if (isset($typesMapping[$attribute->getFrontendInput()])) {
         return $typesMapping[$attribute->getFrontendInput()];
     } elseif (isset($typesMapping[$attribute->getBackendType()])) {
         return $typesMapping[$attribute->getBackendType()];
     } else {
         return Mage_GoogleBase_Model_Service_Item::DEFAULT_ATTRIBUTE_TYPE;
     }
 }
コード例 #5
0
 /**
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param                                           $productAttributeValue
  * @return float|int|string
  */
 protected function _castAttributeValueType(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $productAttributeValue)
 {
     $productAttributeValue = is_array($productAttributeValue) && array_key_exists(0, $productAttributeValue) ? $productAttributeValue[0] : $productAttributeValue;
     if ($attribute->getBackendType() == 'decimal') {
         return (double) $productAttributeValue;
     } elseif ($attribute->getBackendType() == 'int') {
         return (int) $productAttributeValue;
     }
     return $productAttributeValue;
 }
コード例 #6
0
 /**
  * Return Google Content Attribute Type By Product Attribute
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  *
  * @return string Google Content Attribute Type
  */
 public function getGcontentAttributeType($attribute)
 {
     $typesMapping = ['price' => self::ATTRIBUTE_TYPE_FLOAT, 'decimal' => self::ATTRIBUTE_TYPE_INT];
     if (isset($typesMapping[$attribute->getFrontendInput()])) {
         return $typesMapping[$attribute->getFrontendInput()];
     } elseif (isset($typesMapping[$attribute->getBackendType()])) {
         return $typesMapping[$attribute->getBackendType()];
     } else {
         return self::ATTRIBUTE_TYPE_TEXT;
     }
 }
コード例 #7
0
ファイル: Data.php プロジェクト: javik223/Evron-Magento
 /**
  * Checks if attribute is using options.
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return bool
  */
 public function isUsingOptions($attribute)
 {
     $sourceModel = Mage::getModel($attribute->getSourceModel());
     $backendType = $attribute->getBackendType();
     return $attribute->usesSource() && ($backendType == 'int' && $sourceModel instanceof Mage_Eav_Model_Entity_Attribute_Source_Table) || $backendType == 'varchar' && $attribute->getFrontendInput() == 'multiselect';
 }
コード例 #8
0
 /**
  * Returns attribute type for indexation.
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute Attribute
  *
  * @return string
  */
 protected function _getAttributeType($attribute)
 {
     $type = 'string';
     if ($attribute->getBackendType() == 'int' || $attribute->getFrontendClass() == 'validate-digits') {
         $type = 'integer';
     } elseif ($attribute->getBackendType() == 'decimal') {
         $type = 'double';
     } elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
         $type = 'boolean';
     } elseif ($attribute->getBackendType() == 'datetime') {
         $type = 'date';
     } elseif ($attribute->usesSource() && $attribute->getSourceModel() === null) {
         $type = 'integer';
     } else {
         if ($attribute->usesSource()) {
             $type = 'string';
         }
     }
     return $type;
 }
コード例 #9
0
ファイル: Data.php プロジェクト: technomagegithub/norma
 /**
  * Checks if specified attribute is using options.
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return bool
  */
 public function isAttributeUsingOptions($attribute)
 {
     $model = Mage::getModel($attribute->getSourceModel());
     return $attribute->usesSource() && $attribute->getBackendType() == 'int' && $model instanceof Mage_Eav_Model_Entity_Attribute_Source_Table;
 }
コード例 #10
0
ファイル: Client.php プロジェクト: javik223/Evron-Magento
 /**
  * Returns attribute type for indexation.
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string
  */
 protected function _getAttributeType($attribute)
 {
     $type = 'string';
     if ($attribute->getBackendType() == 'decimal') {
         $type = 'double';
     } elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
         $type = 'boolean';
     } elseif ($attribute->getBackendType() == 'datetime') {
         $type = 'date';
     } elseif ($this->_helper->isUsingOptions($attribute)) {
         $type = 'option';
         // custom type to build an object for option id (facets) and label (search)
     } elseif ($attribute->usesSource() || $attribute->getFrontendClass() == 'validate-digits') {
         $type = 'integer';
     }
     return $type;
 }
コード例 #11
0
ファイル: Data.php プロジェクト: jpbender/mage_virtual
 /**
  * Retrieve attribute field's name for sorting
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  *
  * @return string
  */
 public function getAttributeSolrFieldName($attribute)
 {
     $attributeCode = $attribute->getAttributeCode();
     if ($attributeCode == 'score') {
         return $attributeCode;
     }
     $field = $attributeCode;
     $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 (in_array($backendType, $this->_textFieldTypes)) {
         $locale = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
         $languageCode = $this->getLanguageCodeByLocaleCode($locale);
         $languageSuffix = $languageCode ? '_' . $languageCode : '';
         $field .= $languageSuffix;
     }
     return $field;
 }