Beispiel #1
0
 protected function setUp()
 {
     $category = new Mage_Catalog_Model_Category();
     $category->load(4);
     $attribute = new Mage_Catalog_Model_Entity_Attribute();
     $attribute->loadByCode('catalog_product', 'weight');
     $this->_model = new Mage_Catalog_Model_Layer_Filter_Decimal();
     $this->_model->setData(array('layer' => new Mage_Catalog_Model_Layer(array('current_category' => $category)), 'attribute_model' => $attribute));
 }
Beispiel #2
0
 protected function setUp()
 {
     $attribute = new Mage_Catalog_Model_Entity_Attribute();
     $attribute->loadByCode('catalog_product', 'attribute_with_option');
     foreach ($attribute->getSource()->getAllOptions() as $optionInfo) {
         if ($optionInfo['label'] == 'Option Label') {
             $this->_attributeOptionId = $optionInfo['value'];
             break;
         }
     }
     $this->_model = new Mage_Catalog_Model_Layer_Filter_Attribute();
     $this->_model->setData(array('layer' => new Mage_Catalog_Model_Layer(), 'attribute_model' => $attribute));
 }
Beispiel #3
0
 protected function _beforeSave()
 {
     if (!Mage::getSingleton('adminhtml/session')->getIsForFME() || Mage::getSingleton('adminhtml/session')->getIsForFME() == false) {
         if ($this->_getResource()->isUsedBySuperProducts($this)) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('This attribute is used in configurable products'));
         }
         $this->setData('modulePrefix', self::MODULE_NAME);
         return parent::_beforeSave();
     }
 }
Beispiel #4
0
 /**
  *  Check whether attribute reserved or not
  *
  *  @param Mage_Catalog_Model_Entity_Attribute $attribute Attribute model object
  *  @return boolean
  */
 public function isReservedAttribute($attribute)
 {
     return $attribute->getIsUserDefined() && in_array($attribute->getAttributeCode(), $this->getReservedAttributes());
 }
Beispiel #5
0
 /**
  * Check attributes has options and searchable
  *
  * @param Mage_Catalog_Model_Entity_Attribute $attribute
  * @return boolean
  */
 protected function _hasAttributeOptionsAndSearchable($attribute)
 {
     if ($attribute->getIsSearchable() && in_array($attribute->getFrontendInput(), array('select', 'multiselect'))) {
         return true;
     }
     return false;
 }
Beispiel #6
0
 /**
  * Compare attribues sorting
  *
  * @param Mage_Catalog_Model_Entity_Attribute $attribute1
  * @param Mage_Catalog_Model_Entity_Attribute $attribute2
  * @return int
  */
 public function attributesCompare($attribute1, $attribute2)
 {
     $sort1 = $attribute1->getGroupSortPath() * 1000 + $attribute1->getSortPath() * 0.0001;
     $sort2 = $attribute2->getGroupSortPath() * 1000 + $attribute2->getSortPath() * 0.0001;
     if ($sort1 > $sort2) {
         return 1;
     } elseif ($sort1 < $sort2) {
         return -1;
     }
     return 0;
 }
 /**
  * Update the frontend labels of the attribute
  *
  * @param Mage_Catalog_Model_Entity_Attribute              $attribute       Attribute to update
  * @param Aoe_AttributeConfigurator_Model_Config_Attribute $attributeConfig Attribute config
  *
  * @return void
  */
 protected function _updateAttributeLabels($attribute, $attributeConfig)
 {
     $stores = Mage::app()->getStores(true);
     $storeLabels = [];
     $frontendLabel = $attribute->getAttributeCode();
     foreach ($stores as $store) {
         /** @var Mage_Core_Model_Store $store */
         $storeLocale = Mage::getStoreConfig('general/locale/code', $store);
         $storeLabel = $attributeConfig->getLabel($storeLocale);
         if (!$storeLabel) {
             continue;
         }
         $storeLabels[$store->getId()] = $storeLabel;
         if (0 == $store->getId()) {
             $frontendLabel = $storeLabel;
         }
     }
     $attribute->setFrontendLabel($frontendLabel)->setStoreLabels($storeLabels);
     $attribute->save();
 }
 /**
  * Create the block filter for an attribute into the layer.
  *
  * @param Mage_Catalog_Model_Entity_Attribute $attribute Filtered attributes.
  *
  * @return Mage_Catalog_Block_Layer_Filter_Abstract
  */
 protected function _addFilter($attribute)
 {
     $decimalValidationClasses = array('validate-number', 'validate-digits');
     if ($attribute->getAttributeCode() == 'price') {
         $filterBlockName = $this->_priceFilterBlockName;
     } elseif ($attribute->getAttributeCode() == 'rating_filter') {
         $filterBlockName = $this->_ratingFilterBlockName;
     } elseif ($attribute->getSourceModel() == 'eav/entity_attribute_source_boolean') {
         $filterBlockName = $this->_booleanFilterBlockName;
     } elseif ($attribute->getBackendType() == 'decimal' || in_array($attribute->getFrontendClass(), $decimalValidationClasses)) {
         $filterBlockName = $this->_decimalFilterBlockName;
     } else {
         $filterBlockName = $this->_attributeFilterBlockName;
     }
     $filter = $this->getLayout()->createBlock($filterBlockName, $attribute->getAttributeCode() . '_filter')->setLayer($this->getLayer())->setAttributeModel($attribute)->init();
     return $filter;
 }
 /**
  * Indicate if attribute is filterable in search.
  *
  * @param Mage_Catalog_Model_Entity_Attribute $attribute Attribute to be tested
  *
  * @return bool
  */
 protected function _getIsFilterableAttribute($attribute)
 {
     return $attribute->getIsFilterableInSearch();
 }