Beispiel #1
0
 public function setPricingLabelFromAttribute(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
 {
     if ($attribute->getSource()) {
         $this->setLabel($attribute->getSource()->getOptionText($this->getValueIndex()));
     } else {
         $this->setLabel($this->getValueIndex());
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Build attribute select element html string
  *
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @return string
  */
 public function getAttributeSelectElement($attribute)
 {
     $extra = '';
     $options = $attribute->getSource()->getAllOptions(false);
     $name = $attribute->getAttributeCode();
     // 2 - avoid yes/no selects to be multiselects
     if (is_array($options) && count($options) > 2) {
         $extra = 'multiple="multiple" size="4"';
         $name .= '[]';
     } else {
         array_unshift($options, array('value' => '', 'label' => Mage::helper('catalogsearch')->__('All')));
     }
     return $this->_getSelectBlock()->setName($name)->setId($attribute->getAttributeCode())->setTitle($this->getAttributeLabel($attribute))->setExtraParams($extra)->setValue($this->getAttributeValue($attribute))->setOptions($options)->setClass('multiselect')->getHtml();
 }
Beispiel #3
0
 /**
  * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
  *
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @return array
  */
 public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
 {
     $options = array();
     if ($attribute->usesSource()) {
         // should attribute has index (option value) instead of a label?
         $index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
         // only default (admin) store values used
         $attribute->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
         try {
             foreach ($attribute->getSource()->getAllOptions(false) as $option) {
                 foreach (is_array($option['value']) ? $option['value'] : array($option) as $innerOption) {
                     if (strlen($innerOption['value'])) {
                         // skip ' -- Please Select -- ' option
                         $options[$innerOption['value']] = $innerOption[$index];
                     }
                 }
             }
         } catch (Exception $e) {
             // ignore exceptions connected with source models
         }
     }
     return $options;
 }
 /**
  * Validate attribute value for attributes with source models
  *
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @param mixed $attrValue
  * @return array|bool
  */
 protected function _validateAttributeWithSource(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $attrValue)
 {
     $errors = array();
     // validate attributes with source models
     if (null !== $attrValue && $attribute->getSourceModel()) {
         if ('multiselect' !== $attribute->getFrontendInput() && is_array($attrValue)) {
             return array('Invalid value type for ' . $attribute->getAttributeCode());
         }
         $possibleValues = $attribute->getSource()->getAllOptions(false);
         foreach ((array) $attrValue as $value) {
             if (is_scalar($value)) {
                 $value = (string) $value;
                 $isValid = false;
                 foreach ($possibleValues as $optionData) {
                     // comparison without types check is performed only when both values are numeric
                     $useStrictMode = !(is_numeric($value) && is_numeric($optionData['value']));
                     $isValid = $useStrictMode ? $value === $optionData['value'] : $value == $optionData['value'];
                     if ($isValid) {
                         break;
                     }
                 }
                 if (!$isValid) {
                     $errors[] = 'Invalid value "' . $value . '" for ' . $attribute->getAttributeCode();
                 }
             } else {
                 $errors[] = 'Invalid value type for ' . $attribute->getAttributeCode();
             }
         }
     }
     return $errors ? $errors : true;
 }
Beispiel #5
0
 /**
  * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
  *
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @return array
  */
 public function getAttributeOptions(Mage_Eav_Model_Entity_Attribute_Abstract $attribute)
 {
     $options = array();
     if ($attribute->usesSource()) {
         // should attribute has index (option value) instead of a label?
         $index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
         /* MEP changed admin store to current profile store id */
         $attribute->setStoreId($this->getProfile()->getStoreId());
         try {
             foreach ($attribute->getSource()->getAllOptions(false) as $option) {
                 foreach (is_array($option['value']) ? $option['value'] : array($option) as $innerOption) {
                     if (strlen($innerOption['value'])) {
                         // skip ' -- Please Select -- ' option
                         $options[$innerOption['value']] = $innerOption[$index];
                     }
                 }
             }
         } catch (Exception $e) {
             // ignore exceptions connected with source models
         }
     }
     return $options;
 }