protected function getFilterModel() { $settings = $this->_getDataHelper()->getAttributesSettings(); $attributeId = $this->attribute->getId(); /** @var Amasty_Shopby_Model_Filter $model */ $model = isset($settings[$attributeId]) ? $settings[$attributeId] : null; return $model; }
/** * Redefine Attribute scope * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return Mage_Catalog_Model_Product_Attribute_Backend_Price */ public function setScope($attribute) { if (Mage::helper('catalog')->isPriceGlobal()) { $attribute->setIsGlobal(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL); } else { $attribute->setIsGlobal(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE); } return $this; }
/** * @magentoDataFixture Mage/Catalog/controllers/_files/attribute_system_with_applyto_data.php */ public function testSaveActionApplyToData() { $postData = $this->_getAttributeData() + array('attribute_id' => '3'); unset($postData['apply_to']); $this->getRequest()->setPost($postData); $this->dispatch('backend/admin/catalog_product_attribute/save'); $model = new Mage_Catalog_Model_Resource_Eav_Attribute(new Mage_Core_Model_Event_Manager(), new Mage_Core_Model_Cache()); $model->load($postData['attribute_id']); $this->assertEquals(array('simple', 'configurable'), $model->getApplyTo()); }
/** * Return Google Content Attribute Type By Product Attribute * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return string Google Content Attribute Type */ public function getGcontentAttributeType($attribute) { $typesMapping = array('price' => self::ATTRIBUTE_TYPE_FLOAT, 'decimal' => self::ATTRIBUTE_TYPE_INT); if (isset($typesMapping[$attribute->getFrontendInput()])) { return $typesMapping[$attribute->getFrontendInput()]; } elseif (isset($typesMapping[$attribute->getBackendType()])) { return $typesMapping[$attribute->getBackendType()]; } else { return self::ATTRIBUTE_TYPE_TEXT; } }
public function overrideAttribute(Mage_Catalog_Model_Resource_Eav_Attribute $attribute) { if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) { $data = $this->_attributeOverrides[$attribute->getAttributeCode()]; if (isset($data['options_method']) && method_exists($this, $data['options_method'])) { $data['filter_options'] = $this->{$data['options_method']}(); } $attribute->addData($data); return true; } return false; }
/** * Load product tier prices * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return array */ public function loadProductPrices($product, $attribute) { $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array('website_id', 'all_groups', 'cust_group' => 'customer_group_id', 'price_qty' => 'qty', 'price' => 'value'))->where('entity_id=?', $product->getId())->order('qty'); if ($attribute->isScopeGlobal()) { $select->where('website_id=?', 0); } else { if ($storeId = $product->getStoreId()) { $select->where('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId())); } } return $this->_getReadAdapter()->fetchAll($select); }
/** * Add filter by attribute price * * @param Mage_CatalogSearch_Model_Advanced $object * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value */ public function addPriceFilter($object, $attribute, $value) { if (empty($value['from']) && empty($value['to'])) { return false; } if (Mage::helper('solr')->isEnabled()) { $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter(); $code = $attribute->getAttributeCode(); $items = $typeConverter->getItems(); $select = $object->getProductCollection()->getSelect(); $rate = 1; if (!empty($value['currency'])) { $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']); } if (strlen($value['from']) > 0) { $from = $value['from'] * $rate; } else { $from = 0; } if (strlen($value['to']) > 0) { $to = $value['to'] * $rate; } else { $to = 99999999; } $select->where($items[$attribute->getFrontend()->getInputType()]['solr_index_prefix'] . $typeConverter::SUBPREFIX_INDEX . 'price:[' . $from . ' TO ' . $to . ']'); } else { $adapter = $this->_getReadAdapter(); $conditions = array(); if (strlen($value['from']) > 0) { $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s >= ?', $value['from']); } if (strlen($value['to']) > 0) { $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s <= ?', $value['to']); } if (!$conditions) { return false; } $object->getProductCollection()->addPriceData(); $select = $object->getProductCollection()->getSelect(); $response = $this->_dispatchPreparePriceEvent($select); $additional = join('', $response->getAdditionalCalculations()); $rate = 1; if (!empty($value['currency'])) { $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']); } foreach ($conditions as $condition) { $select->where(sprintf($condition, $additional, $rate)); } } return true; }
/** * Prepare search condition for attribute * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value * @return mixed */ protected function _prepareCondition($attribute, $value) { $condition = false; if (is_array($value)) { if (!empty($value['from']) || !empty($value['to'])) { // range $condition = $value; } else { if ($attribute->getBackendType() == 'varchar') { // multiselect $condition = array('in_set' => $value); } else { if (!isset($value['from']) && !isset($value['to'])) { // select $condition = array('in' => $value); } } } } else { if (strlen($value) > 0) { if (in_array($attribute->getBackendType(), array('varchar', 'text', 'static'))) { $condition = array('like' => '%' . $value . '%'); // text search } else { $condition = $value; } } } return $condition; }
/** * Append search params to the form * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute Attribute currently edited * @param Varien_Data_Form $form Form the * * @return Smile_ElasticSearch_Model_Adminhtml_Catalog_Product_Attribute_Edit_Form_Search */ public function addSearchParams($attribute, $form) { $fieldset = $this->_getFieldset($form); $fieldset->addField('search_weight', 'text', array('name' => 'search_weight', 'label' => Mage::helper('smile_elasticsearch')->__('Search Weight'), 'class' => 'validate-number validate-greater-than-zero', 'default' => 1), 'is_searchable'); $fieldset->addField('is_used_in_autocomplete', 'select', array('name' => 'is_used_in_autocomplete', 'label' => Mage::helper('smile_elasticsearch')->__('Used in autocomplete'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'search_weight'); $fieldset->addField('is_snowball_used', 'select', array('name' => 'is_snowball_used', 'label' => Mage::helper('smile_elasticsearch')->__('Use language analysis'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_used_in_autocomplete'); $fieldset->addField('is_fuzziness_enabled', 'select', array('name' => 'is_fuzziness_enabled', 'label' => Mage::helper('smile_elasticsearch')->__('Enable fuzziness'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_snowball_used'); $fieldset->addField('fuzziness_value', 'text', array('name' => 'fuzziness_value', 'label' => Mage::helper('smile_elasticsearch')->__('Fuzziness'), 'class' => 'validate-number validate-number-range number-range-0-1', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('A number between 0 and 1.'), Mage::helper('smile_elasticsearch')->__('See doc at <a href="%s" target="_blank">here</a> for more information', 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/common-options.html#_string_fields')))), 'is_fuzziness_enabled'); $fieldset->addField('fuzziness_prefix_length', 'text', array('name' => 'fuzziness_prefix_length', 'label' => Mage::helper('smile_elasticsearch')->__('Fuzzy prefix range'), 'class' => 'validate-digits validate-digits-range digits-range-0-9', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('A number between 0 and 9.'), Mage::helper('smile_elasticsearch')->__('Min.common prefix between original term and fuzzy matched one.')))), 'fuzziness_value'); if ($attribute->getAttributeCode() == 'name') { $form->getElement('is_searchable')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setValue(1); } return $this; }
/** * Retrieve filter array * * @param Enterprise_Search_Model_Resource_Collection $collection * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value * @return array */ protected function _getSearchParam($collection, $attribute, $value) { if (empty($value) || isset($value['from']) && empty($value['from']) && isset($value['to']) && empty($value['to'])) { return false; } $localeCode = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE); $languageCode = Mage::helper('enterprise_search')->getLanguageCodeByLocaleCode($localeCode); $languageSuffix = $languageCode ? '_' . $languageCode : ''; $field = $attribute->getAttributeCode(); $backendType = $attribute->getBackendType(); $frontendInput = $attribute->getFrontendInput(); if ($frontendInput == 'multiselect') { $field = 'attr_multi_' . $field; } elseif ($frontendInput == 'select' || $frontendInput == 'boolean') { $field = 'attr_select_' . $field; } elseif ($backendType == 'decimal') { $field = 'attr_decimal_' . $field; } elseif ($backendType == 'datetime') { $field = 'attr_datetime_' . $field; if (is_array($value)) { foreach ($value as &$val) { if (!is_empty_date($val)) { $date = new Zend_Date($val, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); $val = $date->toString(Zend_Date::ISO_8601) . 'Z'; } } } else { if (!is_empty_date($value)) { $date = new Zend_Date($value, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); $value = $date->toString(Zend_Date::ISO_8601) . 'Z'; } } } elseif (in_array($backendType, $this->_textFieldTypes)) { $field .= $languageSuffix; } if ($attribute->usesSource()) { $attribute->setStoreId(Mage::app()->getStore()->getId()); foreach ($value as &$val) { $val = $attribute->getSource()->getOptionText($val); } } if (empty($value)) { return array(); } else { return array($field => $value); } }
/** * Init indexing process after catalog eav attribute delete commit * * @return Mage_Catalog_Model_Resource_Eav_Attribute */ protected function _afterDeleteCommit() { parent::_afterDeleteCommit(); $magerpsync = Mage::getModel('magerpsync/attribute')->load($this->getId(), "mage_attribute_id"); $magerpsync->delete(); Mage::getModel('magerpsync/attribute')->deleteAttributeMapping($this->getId()); return $this; }
/** * Define if attribute should be visible for passed user type * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string $userType * @return bool */ protected function _isAttributeVisible(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $userType) { $isAttributeVisible = false; if ($userType == Mage_Api2_Model_Auth_User_Admin::USER_TYPE) { $isAttributeVisible = $attribute->getIsVisible(); } else { $systemAttributesForNonAdmin = array('sku', 'name', 'short_description', 'description', 'tier_price', 'meta_title', 'meta_description', 'meta_keyword'); if ($attribute->getIsUserDefined()) { $isAttributeVisible = $attribute->getIsVisibleOnFront(); } else { if (in_array($attribute->getAttributeCode(), $systemAttributesForNonAdmin)) { $isAttributeVisible = true; } } } return (bool) $isAttributeVisible; }
/** * Append search params to the form * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute Attribute currently edited * @param Varien_Data_Form $form Form the * * @return Smile_ElasticSearch_Model_Adminhtml_Catalog_Product_Attribute_Edit_Form_Search */ public function addSearchParams($attribute, $form) { $fieldset = $this->_getFieldset($form); $fieldset->addField('search_weight', 'text', array('name' => 'search_weight', 'label' => Mage::helper('smile_elasticsearch')->__('Search Weight'), 'class' => 'validate-number validate-greater-than-zero', 'value' => '1', 'default' => 1), 'is_searchable'); $fieldset->addField('is_used_in_autocomplete', 'select', array('name' => 'is_used_in_autocomplete', 'label' => Mage::helper('smile_elasticsearch')->__('Used in autocomplete'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'search_weight'); $fieldset->addField('is_displayed_in_autocomplete', 'select', array('name' => 'is_displayed_in_autocomplete', 'label' => Mage::helper('smile_elasticsearch')->__('Display in autocomplete'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_used_in_autocomplete'); $fieldset->addField('is_snowball_used', 'select', array('name' => 'is_snowball_used', 'label' => Mage::helper('smile_elasticsearch')->__('Use language analysis'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_displayed_in_autocomplete'); $fieldset->addField('is_fuzziness_enabled', 'select', array('name' => 'is_fuzziness_enabled', 'label' => Mage::helper('smile_elasticsearch')->__('Enable fuzziness'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_snowball_used'); $fieldset->addField('facet_min_coverage_rate', 'text', array('name' => 'facet_min_coverage_rate', 'label' => Mage::helper('smile_elasticsearch')->__('Facet coverage rate'), 'class' => 'validate-digits validate-digits-range digits-range-0-100', 'value' => '90', 'note' => Mage::helper('smile_elasticsearch')->__('Ex: Brand facet will be displayed only if 90% of the product have a brand.')), 'is_fuzziness_enabled'); $fieldset->addField('facets_max_size', 'text', array('name' => 'facets_max_size', 'label' => Mage::helper('smile_elasticsearch')->__('Facet max. size'), 'class' => 'validate-digits validate-greater-than-zero', 'value' => '10', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('Max number of values returned by a facet query.')))), 'facet_min_coverage_rate'); $fieldset->addField('facets_sort_order', 'select', array('name' => 'facets_sort_order', 'label' => Mage::helper('smile_elasticsearch')->__('Facet sort order'), 'values' => array(array('value' => Smile_ElasticSearch_Model_Catalog_Layer_Filter_Attribute::SORT_ORDER_COUNT, 'label' => Mage::helper('smile_elasticsearch')->__('Result count')), array('value' => Smile_ElasticSearch_Model_Catalog_Layer_Filter_Attribute::SORT_ORDER_TERM, 'label' => Mage::helper('smile_elasticsearch')->__('Name')), array('value' => Smile_ElasticSearch_Model_Catalog_Layer_Filter_Attribute::SORT_ORDER_RELEVANCE, 'label' => Mage::helper('smile_elasticsearch')->__('Relevance')))), 'facets_max_size'); if ($attribute->getAttributeCode() == 'name') { $form->getElement('is_searchable')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setValue(1); } return $this; }
/** * Append search params to the form * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute Attribute currently edited * @param Varien_Data_Form $form Form the * * @return Smile_ElasticSearch_Model_Adminhtml_Catalog_Product_Attribute_Edit_Form_Search */ public function addSearchParams($attribute, $form) { $fieldset = $this->_getFieldset($form); $fieldset->addField('search_weight', 'text', array('name' => 'search_weight', 'label' => Mage::helper('smile_elasticsearch')->__('Search Weight'), 'class' => 'validate-number validate-greater-than-zero', 'value' => '1', 'default' => 1), 'is_searchable'); $fieldset->addField('is_used_in_autocomplete', 'select', array('name' => 'is_used_in_autocomplete', 'label' => Mage::helper('smile_elasticsearch')->__('Used in autocomplete'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'search_weight'); $fieldset->addField('is_snowball_used', 'select', array('name' => 'is_snowball_used', 'label' => Mage::helper('smile_elasticsearch')->__('Use language analysis'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_used_in_autocomplete'); $fieldset->addField('is_fuzziness_enabled', 'select', array('name' => 'is_fuzziness_enabled', 'label' => Mage::helper('smile_elasticsearch')->__('Enable fuzziness'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray()), 'is_snowball_used'); $fieldset->addField('fuzziness_value', 'text', array('name' => 'fuzziness_value', 'label' => Mage::helper('smile_elasticsearch')->__('Fuzziness'), 'class' => 'validate-number validate-number-range number-range-0-1', 'value' => '0.75', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('A number between 0 and 1.'), Mage::helper('smile_elasticsearch')->__('See doc at <a href="%s" target="_blank">here</a> for more information', 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/common-options.html#_string_fields')))), 'is_fuzziness_enabled'); $fieldset->addField('fuzziness_prefix_length', 'text', array('name' => 'fuzziness_prefix_length', 'label' => Mage::helper('smile_elasticsearch')->__('Fuzzy prefix range'), 'class' => 'validate-digits validate-digits-range digits-range-0-9', 'value' => '2', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('A number between 0 and 9.'), Mage::helper('smile_elasticsearch')->__('Min.common prefix between original term and fuzzy matched one.')))), 'fuzziness_value'); $fieldset->addField('facet_min_coverage_rate', 'text', array('name' => 'facet_min_coverage_rate', 'label' => Mage::helper('smile_elasticsearch')->__('Facet coverage rate'), 'class' => 'validate-digits validate-digits-range digits-range-0-100', 'value' => '90', 'note' => Mage::helper('smile_elasticsearch')->__('Ex: Brand facet will be displayed only if 90% of the product have a brand.')), 'fuzziness_prefix_length'); $fieldset->addField('facets_max_size', 'text', array('name' => 'facets_max_size', 'label' => Mage::helper('smile_elasticsearch')->__('Facets Max Size'), 'class' => 'validate-digits validate-greater-than-zero', 'value' => '1000', 'note' => implode('</br>', array(Mage::helper('smile_elasticsearch')->__('Max number of values returned by a facet query.')))), 'facet_min_coverage_rate'); $fieldset->addField('facets_sort_order', 'select', array('name' => 'facets_sort_order', 'label' => Mage::helper('smile_elasticsearch')->__('Facet sort order'), 'values' => array(array('value' => Smile_ElasticSearch_Model_Resource_Engine_Elasticsearch_Query_Facet_Terms::SORT_ORDER_COUNT, 'label' => Mage::helper('smile_elasticsearch')->__('By results number')), array('value' => Smile_ElasticSearch_Model_Resource_Engine_Elasticsearch_Query_Facet_Terms::SORT_ORDER_TERM, 'label' => Mage::helper('smile_elasticsearch')->__('By name')))), 'facets_max_size'); if ($attribute->getAttributeCode() == 'name') { $form->getElement('is_searchable')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setDisabled(1); $form->getElement('is_used_in_autocomplete')->setValue(1); } return $this; }
/** * Return Product Attribute Store Label * Set attribute name like frontend lable for custom attributes (which wasn't defined by Google) * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param int $storeId Store View Id * @return string Attribute Store View Label or Attribute code */ public function getAttributeLabel($attribute, $storeId) { $attributeId = $attribute->getId(); $frontendLabel = $attribute->getFrontend()->getLabel(); if (is_array($frontendLabel)) { $frontendLabel = array_shift($frontendLabel); } if (!isset($this->_attributeLabels[$attributeId])) { $this->_attributeLabels[$attributeId] = $attribute->getStoreLabels(); } if (isset($this->_attributeLabels[$attributeId][$storeId])) { return $this->_attributeLabels[$attributeId][$storeId]; } else { if (!empty($frontendLabel)) { return $frontendLabel; } else { return $attribute->getAttributeCode(); } } }
/** Get counts from index by configurable attributes if applicable * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param Varien_Db_Select $select */ protected function _getCountForConfigurable($attribute, Varien_Db_Select $select, Varien_Db_Select $baseSelect) { /* @var $versionHelper AdjustWare_Nav_Helper_Version */ $versionHelper = Mage::helper('adjnav/version'); if (!$versionHelper->hasConfigurableFix()) { return false; } /* @var $configurableSelect Varien_Db_Select */ $configurableSelect = clone $baseSelect; $configurableSelect->reset(Zend_Db_Select::COLUMNS); $configurableSelect->reset(Zend_Db_Select::ORDER); $configurableSelect->reset(Zend_Db_Select::LIMIT_COUNT); $configurableSelect->reset(Zend_Db_Select::LIMIT_OFFSET); $configurableFrom = $configurableSelect->getPart(Zend_Db_Select::FROM); $attributeJoins = array(); foreach ($configurableFrom as $alias => $tableInfo) { if (0 === strpos($alias, 'attr_index_')) { $tableInfo['tableName'] = $this->getTable('adjnav/catalog_product_index_configurable'); $tableInfo['joinCondition'] = str_replace('e.entity_id', 'l.' . $versionHelper->getProductIdChildColumn(), $tableInfo['joinCondition']); $attributeJoins[$alias] = $tableInfo; unset($configurableFrom[$alias]); } } if (count($attributeJoins)) { $configurableSelect->setPart(Zend_Db_Select::FROM, $configurableFrom); } $configurableSelect->join(array('l' => $this->getTable($versionHelper->getProductRelationTable())), 'e.entity_id = l.parent_id', array()); $configurableFrom = $configurableSelect->getPart(Zend_Db_Select::FROM); foreach ($attributeJoins as $alias => $tableInfo) { $configurableFrom[$alias] = $tableInfo; } $configurableSelect->setPart(Zend_Db_Select::FROM, $configurableFrom); $select->where('e.type_id != ?', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE); $fields = array('count' => 'COUNT(DISTINCT(e.entity_id))', 'index.value', 'type_id' => '("configurable")'); $configurableSelect->columns($fields)->join(array('index' => $this->getTable('adjnav/catalog_product_index_configurable')), 'index.entity_id = l.' . $versionHelper->getProductIdChildColumn(), array())->where('index.store_id = ?', $this->getStoreId())->where('index.attribute_id = ?', $attribute->getId())->where('e.type_id = ?', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->group('index.value'); return $configurableSelect; }
/** * Initialize product from request parameters * * @return Mage_Catalog_Model_Product */ protected function _initProduct() { $productId = (int) $this->getRequest()->getParam('id'); $product = Mage::getModel('catalog/product')->setStoreId($this->getRequest()->getParam('store', 0)); if (!$productId) { if ($setId = (int) $this->getRequest()->getParam('set')) { $product->setAttributeSetId($setId); } if ($typeId = $this->getRequest()->getParam('type')) { $product->setTypeId($typeId); } } if ($productId) { $product->load($productId); } $attributes = $this->getRequest()->getParam('attributes'); if ($attributes && $product->isConfigurable() && (!$productId || !$product->getTypeInstance()->getUsedProductAttributeIds())) { $product->getTypeInstance()->setUsedProductAttributeIds(explode(",", base64_decode(urldecode($attributes)))); } // Init attribute label names for store selected in dropdown Mage_Catalog_Model_Resource_Eav_Attribute::initLabels($product->getStoreId()); // Required attributes of simple product for configurable creation if ($this->getRequest()->getParam('popup') && ($requiredAttributes = $this->getRequest()->getParam('required'))) { $requiredAttributes = explode(",", $requiredAttributes); foreach ($product->getAttributes() as $attribute) { if (in_array($attribute->getId(), $requiredAttributes)) { $attribute->setIsRequired(1); } } } if ($this->getRequest()->getParam('popup') && $this->getRequest()->getParam('product') && !is_array($this->getRequest()->getParam('product')) && $this->getRequest()->getParam('id', false) === false) { $configProduct = Mage::getModel('catalog/product')->setStoreId(0)->load($this->getRequest()->getParam('product'))->setTypeId($this->getRequest()->getParam('type')); /* @var $configProduct Mage_Catalog_Model_Product */ $data = array(); foreach ($configProduct->getTypeInstance()->getEditableAttributes() as $attribute) { /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if (!$attribute->getIsUnique() && $attribute->getFrontend()->getInputType() != 'gallery' && $attribute->getAttributeCode() != 'required_options' && $attribute->getAttributeCode() != 'has_options' && $attribute->getAttributeCode() != $configProduct->getIdFieldName()) { $data[$attribute->getAttributeCode()] = $configProduct->getData($attribute->getAttributeCode()); } } $product->addData($data)->setWebsiteIds($configProduct->getWebsiteIds()); } $product->setData('_edit_mode', true); Mage::register('product', $product); Mage::register('current_product', $product); return $product; }
/** * Return Google Base Attribute Type By Product Attribute * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return string Google Base Attribute Type */ public function getGbaseAttributeType($attribute) { $typesMapping = array('price' => 'floatUnit', 'decimal' => 'numberUnit'); if (isset($typesMapping[$attribute->getFrontendInput()])) { return $typesMapping[$attribute->getFrontendInput()]; } elseif (isset($typesMapping[$attribute->getBackendType()])) { return $typesMapping[$attribute->getBackendType()]; } else { return Mage_GoogleBase_Model_Service_Item::DEFAULT_ATTRIBUTE_TYPE; } }
/** * Add filter by indexable attribute * * @param Mage_CatalogSearch_Model_Resource_Advanced_Collection $collection * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param string|array $value * @return bool */ public function addIndexableAttributeModifiedFilter($collection, $attribute, $value) { if ($attribute->getIndexType() == 'decimal') { $table = $this->getTable('catalog/product_index_eav_decimal'); } else { $table = $this->getTable('catalog/product_index_eav'); } $tableAlias = 'a_' . $attribute->getAttributeId(); $storeId = Mage::app()->getStore()->getId(); $select = $collection->getSelect(); if (is_array($value)) { if (isset($value['from']) && isset($value['to'])) { if (empty($value['from']) && empty($value['to'])) { return false; } } } $select->distinct(true); $select->join(array($tableAlias => $table), "e.entity_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array()); if (is_array($value) && (isset($value['from']) || isset($value['to']))) { if (isset($value['from']) && !empty($value['from'])) { $select->where("{$tableAlias}.value >= ?", $value['from']); } if (isset($value['to']) && !empty($value['to'])) { $select->where("{$tableAlias}.value <= ?", $value['to']); } return true; } $select->where("{$tableAlias}.value IN(?)", $value); return true; }
/** * Return Product Attribute Store Label * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param int $storeId Store View Id * @return string Attribute Store View Label or Attribute code */ protected function _getAttributeLabel($attribute, $storeId) { $frontendLabel = $attribute->getFrontend()->getLabel(); if (is_array($frontendLabel)) { $frontendLabel = array_shift($frontendLabel); } if (!$this->_translations) { $moduleName = Mage_Catalog_Model_Entity_Attribute::MODULE_NAME; $separator = Mage_Core_Model_Translate::SCOPE_SEPARATOR; $this->_translations = Mage::getModel('core/translate_string')->load($moduleName . $separator . $frontendLabel)->getStoreTranslations(); } if (isset($this->_translations[$storeId])) { return $this->_translations[$storeId]; } else { return $attribute->getAttributeCode(); } }
* NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Catalog * @subpackage integration_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $installer = new Mage_Catalog_Model_Resource_Setup('catalog_setup'); $attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); $entityModel = new Mage_Eav_Model_Entity(); $entityTypeId = $entityModel->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId(); $groupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $attribute = new Mage_Catalog_Model_Resource_Eav_Attribute(); $attribute->setAttributeCode('filterable_attribute_a')->setEntityTypeId($entityTypeId)->setAttributeGroupId($groupId)->setAttributeSetId($attributeSetId)->setIsFilterable(1)->setIsUserDefined(1)->save(); $attribute = new Mage_Catalog_Model_Resource_Eav_Attribute(); $attribute->setAttributeCode('filterable_attribute_b')->setEntityTypeId($entityTypeId)->setAttributeGroupId($groupId)->setAttributeSetId($attributeSetId)->setIsFilterable(1)->setIsUserDefined(1)->save();
/** * Check whether specified attribute can be used in LN * * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return bool */ protected function _getIsFilterableAttribute($attribute) { return $attribute->getIsFilterableInSearch(); }
/** * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @param $productAttributeValue * @return float|int|string */ protected function _castAttributeValueType(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $productAttributeValue) { $productAttributeValue = is_array($productAttributeValue) && array_key_exists(0, $productAttributeValue) ? $productAttributeValue[0] : $productAttributeValue; if ($attribute->getBackendType() == 'decimal') { return (double) $productAttributeValue; } elseif ($attribute->getBackendType() == 'int') { return (int) $productAttributeValue; } return $productAttributeValue; }
/** * Retrieve Product Attribute Value * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return string */ public function getProductAttributeValue($product, $attribute) { if (!$product->hasData($attribute->getAttributeCode())) { return Mage::helper('Mage_Catalog_Helper_Data')->__('N/A'); } if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select', 'boolean', 'multiselect'))) { //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode())); $value = $attribute->getFrontend()->getValue($product); } else { $value = $product->getData($attribute->getAttributeCode()); } return (string) $value == '' ? Mage::helper('Mage_Catalog_Helper_Data')->__('No') : $value; }
/** * Initialize store Labels for attributes * * @deprecated * @param int $storeId */ public static function initLabels($storeId = null) { if (is_null(self::$_labels)) { if (is_null($storeId)) { $storeId = Mage::app()->getStore()->getId(); } $attributeLabels = array(); $attributes = Mage::getResourceSingleton('catalog/product')->getAttributesByCode(); foreach ($attributes as $attribute) { if (strlen($attribute->getData('frontend_label')) > 0) { $attributeLabels[] = $attribute->getData('frontend_label'); } } self::$_labels = Mage::app()->getTranslator()->getResource() ->getTranslationArrayByStrings($attributeLabels, $storeId); } }
/** * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return float|int|string */ protected function _mapAttributeType(Mage_Catalog_Model_Resource_Eav_Attribute $attribute) { if ($attribute->getBackendType() == 'int') { return self::MAPPING_TYPE_INT; } if ($attribute->getBackendType() == 'decimal') { return self::MAPPING_TYPE_DOUBLE; } if ($attribute->getBackendType() == 'varchar' || $attribute->getBackendType() == 'text' || $attribute->getBackendType() == 'static') { return self::MAPPING_TYPE_STRING; } if ($attribute->getBackendType() == 'datetime') { return self::MAPPING_TYPE_DATE; } return self::MAPPING_TYPE_UNKNOWN; }
/** * Delete product tier price data from storage * * @deprecated since 1.3.2.3 * * @param Mage_Catalog_Model_Product $product * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice */ public function deleteProductPrices($product, $attribute) { $websiteId = null; if (!$attribute->isScopeGlobal()) { $storeId = $product->getProductId(); if ($storeId) { $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); } } $this->deletePriceData($product->getId(), $websiteId); return $this; }
/** * Retrieve attribute field name * * @param Mage_Catalog_Model_Resource_Eav_Attribute|string $attribute * @param string $target - default|sort|nav * * @return string|bool */ public function getSearchEngineFieldName($attribute, $target = 'default') { $fieldName = $attribute->getAttributeCode(); if ($fieldName == 'price') { return $this->getPriceFieldName(); } return $fieldName; }
/** * Check whether the attribute is Applicable to the object * * @param Varien_Object $object * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute * @return boolean */ protected function _isApplicableAttribute($object, $attribute) { $applyTo = $attribute->getApplyTo(); return count($applyTo) == 0 || in_array($object->getTypeId(), $applyTo); }
public function testCRUD() { $this->_model->setAttributeCode('test')->setEntityTypeId(Mage::getSingleton('Mage_Eav_Model_Config')->getEntityType('catalog_product')->getId())->setFrontendLabel('test'); $crud = new Magento_Test_Entity($this->_model, array('frontend_label' => uniqid())); $crud->testCrud(); }