Ejemplo n.º 1
0
 /**
  * Changed to support price attribute type multi-scope
  * (non-PHPdoc)
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @see Mage_Test_Model_Mysql4_Fixture_Eav_Catalog_Abstract::_getAttributeRecords()
  */
 protected function _getAttributeRecords($row, $attribute, $tableColumns)
 {
     if ($attribute->getFrontendInput() == 'price') {
         $attribute->setIsGlobal(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE);
     }
     return parent::_getAttributeRecords($row, $attribute, $tableColumns);
 }
Ejemplo n.º 2
0
 /**
  * Add data about search criteria to object state
  *
  * @param   Mage_Eav_Model_Entity_Attribute $attribute
  * @param   mixed $value
  * @return  Mage_CatalogSearch_Model_Advanced
  */
 protected function _addSearchCriteria($attribute, $value)
 {
     $name = $attribute->getStoreLabel();
     if (is_array($value)) {
         if (isset($value['from']) && isset($value['to'])) {
             if (!empty($value['from']) || !empty($value['to'])) {
                 if (isset($value['currency'])) {
                     $currencyModel = Mage::getModel('directory/currency')->load($value['currency']);
                     $from = $currencyModel->format($value['from'], array(), false);
                     $to = $currencyModel->format($value['to'], array(), false);
                 } else {
                     $currencyModel = null;
                 }
                 if (strlen($value['from']) > 0 && strlen($value['to']) > 0) {
                     // -
                     $value = sprintf('%s - %s', $currencyModel ? $from : $value['from'], $currencyModel ? $to : $value['to']);
                 } elseif (strlen($value['from']) > 0) {
                     // and more
                     $value = Mage::helper('catalogsearch')->__('%s and greater', $currencyModel ? $from : $value['from']);
                 } elseif (strlen($value['to']) > 0) {
                     // to
                     $value = Mage::helper('catalogsearch')->__('up to %s', $currencyModel ? $to : $value['to']);
                 }
             } else {
                 return $this;
             }
         }
     }
     if (($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') && is_array($value)) {
         foreach ($value as $key => $val) {
             $value[$key] = $attribute->getSource()->getOptionText($val);
             if (is_array($value[$key])) {
                 $value[$key] = $value[$key]['label'];
             }
         }
         $value = implode(', ', $value);
     } else {
         if ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') {
             $value = $attribute->getSource()->getOptionText($value);
             if (is_array($value)) {
                 $value = $value['label'];
             }
         } else {
             if ($attribute->getFrontendInput() == 'boolean') {
                 $value = $value == 1 ? Mage::helper('catalogsearch')->__('Yes') : Mage::helper('catalogsearch')->__('No');
             }
         }
     }
     $this->_searchCriterias[] = array('name' => $name, 'value' => $value);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Get attribute type for upcoming validation.
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return string
  */
 public static function getAttributeType(Mage_Eav_Model_Entity_Attribute $attribute)
 {
     if ($attribute->usesSource()) {
         return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select';
     } elseif ($attribute->isStatic()) {
         return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar';
     } else {
         return $attribute->getBackendType();
     }
 }
Ejemplo n.º 4
0
 /**
  * Update attribute default value
  *
  * @param Mage_Eav_Model_Entity_Attribute|Mage_Core_Model_Abstract $object
  * @param int|string $optionId
  * @param int $intOptionId
  * @param array $defaultValue
  */
 protected function _updateDefaultValue($object, $optionId, $intOptionId, &$defaultValue)
 {
     if (in_array($optionId, $object->getDefault())) {
         $frontendInput = $object->getFrontendInput();
         if ($frontendInput === 'multiselect') {
             $defaultValue[] = $intOptionId;
         } elseif ($frontendInput === 'select') {
             $defaultValue = array($intOptionId);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Get Human Readable label for attribute value option
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param int|string                      $attributeValueId
  *
  * @return string|boolean
  */
 public function getAttributeAdminLabel($attribute, $attributeValueId)
 {
     if ($attribute->getFrontendInput() == 'select') {
         return $attribute->getSource()->getOptionText($attributeValueId);
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Get all options of a dropdown attribute
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return array
  */
 protected function _getAttributeOptions($attribute)
 {
     if (!isset($this->_attributeOptions[$attribute->getAttributeCode()])) {
         if ($attribute->getFrontendInput() == 'select') {
             /** @var $attributeOptions Mage_Eav_Model_Entity_Attribute_Source_Table */
             $attributeOptions = Mage::getModel('eav/entity_attribute_source_table');
             $attributeOptions->setAttribute($attribute);
         } else {
             $attributeOptions = $attribute->getSource();
         }
         $this->_attributeOptions[$attribute->getAttributeCode()] = array();
         foreach ($attributeOptions->getAllOptions(false) as $option) {
             $this->_attributeOptions[$attribute->getAttributeCode()][$option['value']] = $option['label'];
         }
     }
     return $this->_attributeOptions[$attribute->getAttributeCode()];
 }