private function saveAttribute() { if ($this->attributeObj->getId()) { return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode()); } if (!$this->validate()) { return array('result' => false, 'error' => 'Attribute builder. Validation failed.'); } $data = $this->params; $data['attribute_code'] = $this->code; $data['frontend_label'] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $this->primaryLabel); $data['frontend_input'] = $this->inputType; $data['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType); $data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($this->inputType); !isset($data['is_global']) && ($data['is_global'] = self::SCOPE_STORE); !isset($data['is_configurable']) && ($data['is_configurable'] = 0); !isset($data['is_filterable']) && ($data['is_filterable'] = 0); !isset($data['is_filterable_in_search']) && ($data['is_filterable_in_search'] = 0); $this->attributeObj = Mage::getModel('catalog/resource_eav_attribute'); if (is_null($this->attributeObj->getIsUserDefined()) || $this->attributeObj->getIsUserDefined() != 0) { $data['backend_type'] = $this->attributeObj->getBackendTypeByInput($this->inputType); } // default value if (empty($data['default_value'])) { unset($data['default_value']); } // --------------------------------------- !isset($data['apply_to']) && ($data['apply_to'] = array()); // prepare options foreach ($this->options as $optionValue) { $code = 'option_' . substr(sha1($optionValue), 0, 6); $data['option']['value'][$code] = array(Mage_Core_Model_App::ADMIN_STORE_ID => $optionValue); } // --------------------------------------- $this->attributeObj->addData($data); $this->attributeObj->setEntityTypeId($this->entityTypeId); $this->attributeObj->setIsUserDefined(1); try { $this->attributeObj->save(); } catch (Exception $e) { return array('result' => false, 'error' => $e->getMessage()); } return array('result' => true, 'obj' => $this->attributeObj, 'code' => $this->attributeObj->getAttributeCode()); }
/** * Check whether attribute reserved or not * * @param Mage_Eav_Model_Entity_Attribute $attribute Attribute model object * @return boolean */ public function isReservedAttribute($attribute) { return $attribute->getIsUserDefined() && in_array($attribute->getAttributeCode(), $this->getReservedAttributes()); }
/** * Checkin attribute availability for create superproduct * * @param Mage_Eav_Model_Entity_Attribute $attribute * @return bool */ public function canUseAttribute(Mage_Eav_Model_Entity_Attribute $attribute) { $allow = $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL && $attribute->getIsVisible() && $attribute->getIsConfigurable() && $attribute->usesSource() && $attribute->getIsUserDefined(); return $allow; }