Example #1
0
 /**
  * Return attribute data model by attribute
  * Set entity to data model (need for work)
  *
  * @param Mage_Eav_Model_Attribute $attribute
  * @param Mage_Core_Model_Abstract $entity
  * @return Mage_Eav_Model_Attribute_Data_Abstract
  */
 public static function factory(Mage_Eav_Model_Attribute $attribute, Mage_Core_Model_Abstract $entity)
 {
     /* @var $dataModel Mage_Eav_Model_Attribute_Data_Abstract */
     $dataModelClass = $attribute->getDataModel();
     if (!empty($dataModelClass)) {
         if (empty(self::$_dataModels[$dataModelClass])) {
             $dataModel = Mage::getModel($dataModelClass);
             self::$_dataModels[$dataModelClass] = $dataModel;
         } else {
             $dataModel = self::$_dataModels[$dataModelClass];
         }
     } else {
         if (empty(self::$_dataModels[$attribute->getFrontendInput()])) {
             $dataModelClass = sprintf('eav/attribute_data_%s', $attribute->getFrontendInput());
             $dataModel = Mage::getModel($dataModelClass);
             self::$_dataModels[$attribute->getFrontendInput()] = $dataModel;
         } else {
             $dataModel = self::$_dataModels[$attribute->getFrontendInput()];
         }
     }
     $dataModel->setAttribute($attribute);
     $dataModel->setEntity($entity);
     return $dataModel;
 }
 /**
  * Return scope values for attribute and website
  *
  * @param Mage_Eav_Model_Attribute $object
  * @return array
  */
 public function getScopeValues(Mage_Eav_Model_Attribute $object)
 {
     $adapter = $this->_getReadAdapter();
     $bind = array('attribute_id' => (int) $object->getId(), 'website_id' => (int) $object->getWebsite()->getId());
     $select = $adapter->select()->from($this->_getEavWebsiteTable())->where('attribute_id = :attribute_id')->where('website_id = :website_id')->limit(1);
     $result = $adapter->fetchRow($select, $bind);
     if (!$result) {
         $result = array();
     }
     return $result;
 }
 /**
  * Render attribute row and return HTML
  *
  * @param Mage_Eav_Model_Attribute $attribute
  * @return string
  */
 public function getAttributeHtml(Mage_Eav_Model_Attribute $attribute)
 {
     $type = $attribute->getFrontendInput();
     $block = $this->getRenderer($type);
     if ($block) {
         $block->setAttributeObject($attribute)->setEntity($this->getEntity())->setFieldIdFormat($this->_fieldIdFormat)->setFieldNameFormat($this->_fieldNameFormat);
         return $block->toHtml();
     }
     return false;
 }
Example #4
0
 /**
  * Whether the specified attribute needs to skip rendering/validation
  *
  * @param Mage_Eav_Model_Attribute $attribute
  * @return bool
  */
 protected function _isAttributeOmitted($attribute)
 {
     if ($this->_ignoreInvisible && !$attribute->getIsVisible()) {
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Load counfigurable attribute by product and product's attribute
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Eav_Model_Attribute  $attribute
  */
 public function loadByProductAndAttribute($product, $attribute)
 {
     $id = $this->_getResource()->getIdByProductIdAndAttributeId($this, $product->getId(), $attribute->getId());
     if ($id) {
         $this->load($id);
     }
 }
 /**
 
 
     /**
 * Return the text value for an atribute using source model.
 *
 * @param Mage_Eav_Model_Attribute $attribute Attribute we want the value for.
 * @param mixed                    $value     Raw value
 * @param int                      $storeId   Store id
 *
 * @return mixed.
 */
 protected function _getOptionsText($attribute, $value, $storeId)
 {
     $attribute->setStoreId($storeId);
     if ($attribute->getSource()) {
         $value = $attribute->getSource()->getIndexOptionText($value);
     }
     return $value;
 }
 /**
  * Indicates if an attribute is used into a search type.
  *
  * @param Mage_Eav_Model_Attribute $attribute  Attribute we want the value for.
  * @param string                   $searchType Search type
  *
  * @return boolean
  */
 protected function _isAttributeUsedForSearchType($attribute, $searchType)
 {
     $isSearchable = $attribute->getIsSearchable() || $attribute->getAttributeCode() == 'name';
     if (in_array($searchType, array(self::SEARCH_TYPE_FUZZY, self::SEARCH_TYPE_PHONETIC))) {
         $isSearchable = $isSearchable && (bool) $attribute->getIsFuzzinessEnabled();
     } else {
         if ($searchType == self::SEARCH_TYPE_AUTOCOMPLETE) {
             $isSearchable = $isSearchable && (bool) $attribute->getIsUsedInAutocomplete();
         }
     }
     return $isSearchable;
 }
Example #8
0
 /**
  * Render attribute row and return HTML
  *
  * @param Mage_Eav_Model_Attribute $attribute
  * @return string
  */
 public function getAttributeHtml(Mage_Eav_Model_Attribute $attribute)
 {
     $showOnGuest = TRUE;
     $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
     $entityTypeId = $setup->getEntityTypeId('customer');
     if ($attribute->getEntityTypeId() == $entityTypeId) {
         $collection = Mage::getModel('customerattribute/customerattribute')->getCollection()->addFieldToFilter('attribute_id', $attribute->getAttributeId())->getFirstItem();
         if ($collection->getShowOnCheckoutRegisterGuest() == 0) {
             $showOnGuest = FALSE;
         }
     }
     $type = $attribute->getFrontendInput();
     $block = $this->getRenderer($type);
     if ($block) {
         $block->setAttributeObject($attribute)->setEntity($this->getEntity())->setFieldIdFormat($this->_fieldIdFormat)->setFieldNameFormat($this->_fieldNameFormat)->setShowOnGuest($showOnGuest);
         return $block->toHtml();
     }
     return false;
 }
Example #9
0
 /**
  * Whether the specified attribute needs to skip rendering/validation
  *
  * @param Mage_Eav_Model_Attribute $attribute
  * @return bool
  */
 protected function _isAttributeOmitted($attribute)
 {
     if (!$attribute->getIsVisible()) {
         return true;
     }
     return false;
 }