Exemple #1
0
 /**
  * @dataProvider attributeValueDataProvider
  */
 public function testValidate($data)
 {
     $this->_attribute->expects($this->atLeastOnce())->method('getAttributeCode')->will($this->returnValue('code'));
     $product = new Varien_Object(array('code' => $data));
     $this->_model->validate($product);
     $this->assertEquals('1,2,3', $product->getCode());
 }
Exemple #2
0
 private function saveAttribute()
 {
     if ($this->attributeObj->getId()) {
         return array('result' => true, 'obj' => $this->attributeObj);
     }
     if (!$this->validate()) {
         return array('result' => false, 'error' => 'Attribute builder. Validation failed.');
     }
     $this->attributeObj = Mage::getModel('catalog/resource_eav_attribute');
     $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['entity_type_id'] = $this->entityTypeId;
     $data['is_user_defined'] = 1;
     $data['source_model'] = Mage::helper('catalog/product')->getAttributeSourceModelByInputType($this->inputType);
     $data['backend_model'] = Mage::helper('catalog/product')->getAttributeBackendModelByInputType($this->inputType);
     $data['backend_type'] = $this->attributeObj->getBackendTypeByInput($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);
     !isset($data['apply_to']) && ($data['apply_to'] = array());
     $this->prepareOptions($data);
     $this->prepareDefault($data);
     $this->attributeObj->addData($data);
     try {
         $this->attributeObj->save();
     } catch (Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $this->attributeObj);
 }
Exemple #3
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);
 }
Exemple #4
0
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  *
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='0'", array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
     return $this;
 }
Exemple #5
0
 /**
  * Retrieve attribute field name
  *
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return string
  */
 public function getAttributeFieldName($attribute)
 {
     $name = $attribute->getAttributeCode();
     if ($suffix = $this->getForm()->getFieldNameSuffix()) {
         $name = $this->getForm()->addSuffixToName($name, $suffix);
     }
     return $name;
 }
 /**
  * Gets attribute options from database
  *
  * @param \Mage_Eav_Model_Entity_Attribute $attribute
  *
  * @return array
  */
 protected function getOptions($attribute)
 {
     $select = $this->readConnection->select()->from(array('o' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')))->join(array('ov' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')), 'o.option_id = ov.option_id')->where('o.attribute_id = ?', $attribute->getId())->where('ov.store_id = 0')->order('ov.option_id');
     $query = $select->query();
     $values = array();
     foreach ($query->fetchAll() as $row) {
         $values[] = $row['value'];
     }
     return array('values' => $values);
 }
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  * @return Mage_Eav_Model_Resource_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $adapter = $this->_getReadAdapter();
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0";
     $tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", $collection->getStoreId());
     $valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", "{$optionTable1}.value", "{$optionTable2}.value");
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), $tableJoinCond1, array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), $tableJoinCond2, array($attributeCode => $valueExpr));
     return $this;
 }
Exemple #8
0
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  *
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$adminStore}'", $collection->getStoreId() != $adminStore ? array() : array($attributeCode . '_value' => "{$optionTable1}.value"));
     if ($collection->getStoreId() != $adminStore) {
         $collection->getSelect()->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode . '_value' => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
     }
     return $this;
 }
 /**
  * Delete product data
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return Enterprise_GiftCard_Model_Resource_Attribute_Backend_Giftcard_Amount
  */
 public function deleteProductData($product, $attribute)
 {
     $condition = array();
     if (!$attribute->isScopeGlobal()) {
         if ($storeId = $product->getStoreId()) {
             $condition['website_id IN (?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId());
         }
     }
     $condition['entity_id=?'] = $product->getId();
     $condition['attribute_id=?'] = $attribute->getId();
     $this->_getWriteAdapter()->delete($this->getMainTable(), $condition);
     return $this;
 }
 /**
  * Copy all eav attribute values for a specified attribute from one table to another eav attribute table,
  * updating the attribute id. The old records remain in the old value table.
  *
  * @param Mage_Eav_Model_Entity_Attribute $oldAttribute
  * @param Mage_Eav_Model_Entity_Attribute $newAttribute
  * @return array Affected entity ids
  */
 public function copyAttributeValues(Mage_Eav_Model_Entity_Attribute $oldAttribute, Mage_Eav_Model_Entity_Attribute $newAttribute)
 {
     $select = $this->_getReadAdapter()->select()->reset()->distinct(true)->from($oldAttribute->getBackendTable(), 'entity_id')->where('attribute_id=:attribute_id');
     $entityIds = $this->_getReadAdapter()->fetchCol($select, array('attribute_id' => $oldAttribute->getId()));
     // Remove new attribute value records for entities that are being migrated
     $this->_getWriteAdapter()->delete($newAttribute->getBackendTable(), array('attribute_id=?' => $newAttribute->getId(), 'entity_id IN(?)' => $entityIds));
     // Copy old attribute values to the new attribute
     $selectFields = array('entity_type_id', new Zend_Db_Expr($newAttribute->getId()), 'store_id', 'entity_id', 'value');
     $insertFields = array('entity_type_id', 'attribute_id', 'store_id', 'entity_id', 'value');
     $select->reset()->from($oldAttribute->getBackendTable(), $selectFields)->where('attribute_id=?', $oldAttribute->getId());
     $update = $this->_getWriteAdapter()->insertFromSelect($select, $newAttribute->getBackendTable(), $insertFields, Varien_Db_Adapter_Interface::INSERT_IGNORE);
     $this->_getWriteAdapter()->query($update);
     return $entityIds;
 }
 protected function _beforeSave()
 {
     if ($this->getFrontendInput() == "image") {
         $this->setBackendModel('catalog/category_attribute_backend_image');
         $this->setBackendType('varchar');
     }
     if ($this->getFrontendInput() == "date") {
         $this->setBackendModel('eav/entity_attribute_backend_datetime');
         $this->setBackendType('datetime');
     }
     if ($this->getFrontendInput() == "textarea") {
         $this->setBackendType('text');
     }
     if ($this->getFrontendInput() == "text") {
         $this->setBackendType('varchar');
     }
     if ($this->getFrontendInput() == "multiselect" || $this->getFrontendInput() == "select") {
         $this->setData('source_model', 'eav/entity_attribute_source_table');
         $this->setBackendType('varchar');
     }
     if ($this->getFrontendInput() == "boolean") {
         $this->setFrontendInput("select");
         $this->setBackendType('int');
         $this->setData('source_model', 'eav/entity_attribute_source_boolean');
     }
     return parent::_beforeSave();
 }
 /**
  * Processing object after save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _afterSave()
 {
     /**
      * Fix saving attribute in admin
      */
     Mage::getSingleton('eav/config')->clear();
     return parent::_afterSave();
 }
Exemple #13
0
 public function loadByCode($code)
 {
     if ($code != "") {
         parent::loadByCode(1, $code);
     } else {
         $this->setEntityTypeId(Mage::getModel('eav/entity')->setType("customer")->getTypeId());
     }
     return $this;
 }
Exemple #14
0
 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());
 }
Exemple #15
0
 /**
  * Set attribute model to filter
  *
  * @param   Mage_Eav_Model_Entity_Attribute $attribute
  * @return  Mage_Catalog_Model_Layer_Filter_Abstract
  */
 public function setAttributeModel($attribute)
 {
     $this->setRequestVar($attribute->getAttributeCode());
     $this->setData('attribute_model', $attribute);
     return $this;
 }
 /**
  * Processing object after save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _afterSave()
 {
     Mage::getSingleton('eav/config')->clear();
     return parent::_afterSave();
 }
Exemple #17
0
 /**
  * Processing vendor attribute after save data
  *
  * @return Ced_CsMarketplace_Model_Vendor_Attribute
  */
 protected function _afterSave()
 {
     parent::_afterSave();
     if ($this->getId()) {
         $joinFields = $this->_vendorForm($this);
         if (count($joinFields) > 0) {
             foreach ($joinFields as $joinField) {
                 $joinField->setData('is_visible', $this->getData('is_visible'));
                 $joinField->setData('sort_order', $this->getData('position'));
                 $joinField->setData('use_in_registration', $this->getData('use_in_registration'));
                 $joinField->setData('position_in_registration', $this->getData('position_in_registration'));
                 $joinField->setData('use_in_left_profile', $this->getData('use_in_left_profile'));
                 $joinField->setData('fontawesome_class_for_left_profile', $this->getData('fontawesome_class_for_left_profile'));
                 $joinField->setData('position_in_left_profile', $this->getData('position_in_left_profile'));
                 $joinField->save();
             }
         }
     }
     return $this;
 }
Exemple #18
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();
     }
 }
 /**
  * Determine filter type for specified attribute.
  *
  * @static
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @throws Exception
  * @return string
  */
 public static function getAttributeFilterType(Mage_Eav_Model_Entity_Attribute $attribute)
 {
     if ($attribute->usesSource() || $attribute->getFilterOptions()) {
         return self::FILTER_TYPE_SELECT;
     } elseif ('datetime' == $attribute->getBackendType()) {
         return self::FILTER_TYPE_DATE;
     } elseif ('decimal' == $attribute->getBackendType() || 'int' == $attribute->getBackendType()) {
         return self::FILTER_TYPE_NUMBER;
     } elseif ($attribute->isStatic() || 'varchar' == $attribute->getBackendType() || 'text' == $attribute->getBackendType()) {
         return self::FILTER_TYPE_INPUT;
     } else {
         Mage::throwException(Mage::helper('importexport')->__('Can not determine attribute filter type'));
     }
 }
Exemple #20
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);
         }
     }
 }
Exemple #21
0
 /**
  * Init indexing process after catalog eav attribute delete commit
  *
  * @return Mage_Catalog_Model_Resource_Eav_Attribute
  */
 protected function _afterDeleteCommit()
 {
     parent::_afterDeleteCommit();
     Mage::getSingleton('index/indexer')->indexEvents(
         self::ENTITY, Mage_Index_Model_Event::TYPE_DELETE
     );
     return $this;
 }
Exemple #22
0
 /**
  * Compare attributes
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute1
  * @param Mage_Eav_Model_Entity_Attribute $attribute2
  * @return int
  */
 public function attributesCompare($attribute1, $attribute2)
 {
     $sortPath = sprintf('attribute_set_info/%s/sort', $this->_sortingSetId);
     $groupSortPath = sprintf('attribute_set_info/%s/group_sort', $this->_sortingSetId);
     $sort1 = $attribute1->getData($groupSortPath) * 1000 + $attribute1->getData($sortPath) * 0.0001;
     $sort2 = $attribute2->getData($groupSortPath) * 1000 + $attribute2->getData($sortPath) * 0.0001;
     if ($sort1 > $sort2) {
         return 1;
     } elseif ($sort1 < $sort2) {
         return -1;
     }
     return 0;
 }
 /**
  * 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;
 }
 /**
  * Update attribute flat data
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param int $storeId
  * @param int|array $productIds update only product(s)
  * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer
  */
 public function updateAttribute($attribute, $storeId, $productIds = null)
 {
     if (!$this->_isFlatTableExists($storeId)) {
         return $this;
     }
     $adapter = $this->_getWriteAdapter();
     $flatTableName = $this->getFlatTableName($storeId);
     $describe = $adapter->describeTable($flatTableName);
     if ($attribute->getBackend()->getType() == 'static') {
         if (!isset($describe[$attribute->getAttributeCode()])) {
             return $this;
         }
         $select = $adapter->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id = e.entity_id', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
         if ($this->getFlatHelper()->isAddChildData()) {
             $select->where('e.is_child = ?', 0);
         }
         if ($productIds !== null) {
             $select->where('main_table.entity_id IN(?)', $productIds);
         }
         $sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
         $adapter->query($sql);
     } else {
         $columns = $attribute->getFlatColumns();
         if (!$columns) {
             return $this;
         }
         foreach (array_keys($columns) as $columnName) {
             if (!isset($describe[$columnName])) {
                 return $this;
             }
         }
         $select = $attribute->getFlatUpdateSelect($storeId);
         if ($select instanceof Varien_Db_Select) {
             if ($productIds !== null) {
                 $select->where('e.entity_id IN(?)', $productIds);
             }
             $sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
             $adapter->query($sql);
         }
     }
     return $this;
 }
Exemple #25
0
 /**
  *  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());
 }
Exemple #26
0
 /**
  * Update attribute flat data
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param int $store
  * @param int|array $productIds update only product(s)
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer
  */
 public function updateAttribute($attribute, $store, $productIds = null)
 {
     if ($attribute->getBackend()->getType() == 'static') {
         $select = $this->_getWriteAdapter()->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id=e.entity_id ', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
         if ($this->getFlatHelper()->isAddChildData()) {
             $select->where("e.is_child=?", 0);
         }
         if (!is_null($productIds)) {
             $select->where('main_table.entity_id IN(?)', $productIds);
         }
         $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
         $this->_getWriteAdapter()->query($sql);
     } else {
         $select = $attribute->getFlatUpdateSelect($store);
         if ($select instanceof Varien_Db_Select) {
             if (!is_null($productIds)) {
                 $select->where('e.entity_id IN(?)', $productIds);
             }
             $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
             $this->_getWriteAdapter()->query($sql);
         }
     }
     return $this;
 }
 /**
  * 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;
 }
Exemple #28
0
 /**
  * Callback function which called after transaction commit in resource model
  *
  * @return Mage_Catalog_Model_Resource_Eav_Attribute
  */
 public function afterCommitCallback()
 {
     parent::afterCommitCallback();
     /** @var \Mage_Index_Model_Indexer $indexer */
     $indexer = Mage::getSingleton('index/indexer');
     $indexer->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
     return $this;
 }
Exemple #29
0
 /**
  * Return entities where attribute value is
  *
  * @param array|int $entityIdsFilter
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param mixed $expectedValue
  * @return array
  */
 public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
 {
     $bind = array('attribute_id' => $attribute->getId(), 'value' => $expectedValue);
     $select = $this->_getReadAdapter()->select()->from($attribute->getBackend()->getTable(), array('entity_id'))->where('attribute_id = :attribute_id')->where('value = :value')->where('entity_id IN(?)', $entityIdsFilter);
     return $this->_getReadAdapter()->fetchCol($select, $bind);
 }
Exemple #30
0
 /**
  * Create filter fields for 'Filter' column.
  *
  * @param mixed $value
  * @param Mage_Eav_Model_Entity_Attribute $row
  * @param Varien_Object $column
  * @param boolean $isExport
  * @return string
  */
 public function decorateFilter($value, Mage_Eav_Model_Entity_Attribute $row, Varien_Object $column, $isExport)
 {
     $value = null;
     $values = $column->getValues();
     if (is_array($values) && isset($values[$row->getAttributeCode()])) {
         $value = $values[$row->getAttributeCode()];
     }
     switch (Mage_ImportExport_Model_Export::getAttributeFilterType($row)) {
         case Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT:
             $cell = $this->_getSelectHtmlWithValue($row, $value);
             break;
         case Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT:
             $cell = $this->_getInputHtmlWithValue($row, $value);
             break;
         case Mage_ImportExport_Model_Export::FILTER_TYPE_DATE:
             $cell = $this->_getDateFromToHtmlWithValue($row, $value);
             break;
         case Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER:
             $cell = $this->_getNumberFromToHtmlWithValue($row, $value);
             break;
         default:
             $cell = $this->_helper->__('Unknown attribute filter type');
     }
     return $cell;
 }