Public Member Functions | |
cleanCache () | |
installDefaultGroupIds () | |
addEntityType ($code, array $params) | |
updateEntityType ($code, $field, $value=null) | |
getEntityType ($id, $field=null) | |
getEntityTypeId ($entityTypeId) | |
removeEntityType ($id) | |
getAttributeSetSortOrder ($entityTypeId, $sortOrder=null) | |
addAttributeSet ($entityTypeId, $name, $sortOrder=null) | |
updateAttributeSet ($entityTypeId, $id, $field, $value=null) | |
getAttributeSet ($entityTypeId, $id, $field=null) | |
getAttributeSetId ($entityTypeId, $setId) | |
removeAttributeSet ($entityTypeId, $id) | |
setDefaultSetToEntityType ($entityType, $attributeSet= 'Default') | |
getAllAttributeSetIds ($entityTypeId=null) | |
getDefaultAttributeSetId ($entityType) | |
getAttributeGroupSortOrder ($entityTypeId, $setId, $sortOrder=null) | |
addAttributeGroup ($entityTypeId, $setId, $name, $sortOrder=null) | |
updateAttributeGroup ($entityTypeId, $setId, $id, $field, $value=null) | |
getAttributeGroup ($entityTypeId, $setId, $id, $field=null) | |
getAttributeGroupId ($entityTypeId, $setId, $groupId) | |
removeAttributeGroup ($entityTypeId, $setId, $id) | |
getDefaultAttributeGroupId ($entityType, $attributeSetId=null) | |
addAttribute ($entityTypeId, $code, array $attr) | |
addAttributeOption ($option) | |
updateAttribute ($entityTypeId, $id, $field, $value=null, $sortOrder=null) | |
getAttribute ($entityTypeId, $id, $field=null) | |
getAttributeId ($entityTypeId, $id) | |
getAttributeTable ($entityTypeId, $id) | |
removeAttribute ($entityTypeId, $code) | |
getAttributeSortOrder ($entityTypeId, $setId, $groupId, $sortOrder=null) | |
addAttributeToSet ($entityTypeId, $setId, $groupId, $attributeId, $sortOrder=null) | |
addAttributeToGroup ($entityType, $setId, $groupId, $attributeId, $sortOrder=null) | |
installEntities ($entities=null) | |
createEntityTables ($baseName, array $options=array()) | |
Public Attributes | |
$defaultGroupIdAssociations = array('General'=>1) | |
Protected Member Functions | |
_getValue ($array, $key, $default=null) | |
_getAttributeTableFields () | |
_insertAttribute (array $data) | |
Protected Attributes | |
$_attributeTableFields | |
$_generalGroupName = 'General' |
Definition at line 35 of file Setup.php.
_getAttributeTableFields | ( | ) | [protected] |
Retrieve attribute table fields
Definition at line 1045 of file Setup.php.
01045 { 01046 return $this->getConnection()->describeTable($this->getTable('eav/attribute')); 01047 }
_getValue | ( | $ | array, | |
$ | key, | |||
$ | default = null | |||
) | [protected] |
_insertAttribute | ( | array $ | data | ) | [protected] |
Insert attribute and filter data
Definition at line 1054 of file Setup.php.
01054 { 01055 $bind = array(); 01056 $fields = $this->_getAttributeTableFields(); 01057 01058 foreach ($data as $k => $v) { 01059 if (isset($fields[$k])) { 01060 $bind[$k] = $v; 01061 } 01062 } 01063 if (!$bind) { 01064 return $this; 01065 } 01066 01067 $this->getConnection()->insert($this->getTable('eav/attribute'), $bind); 01068 01069 return $this; 01070 }
addAttribute | ( | $ | entityTypeId, | |
$ | code, | |||
array $ | attr | |||
) |
Add attribute to an entity type
If attribute is system will add to all existing attribute sets
string|integer | $entityTypeId | |
string | $code | |
array | $attr |
Reimplemented in Mage_Sales_Model_Mysql4_Setup.
Definition at line 530 of file Setup.php.
00531 { 00532 $entityTypeId = $this->getEntityTypeId($entityTypeId); 00533 $data = array( 00534 'entity_type_id' => $entityTypeId, 00535 'attribute_code' => $code, 00536 'backend_model' => $this->_getValue($attr, 'backend', ''), 00537 'backend_type' => $this->_getValue($attr, 'type', 'varchar'), 00538 'backend_table' => $this->_getValue($attr, 'table', ''), 00539 'frontend_model' => $this->_getValue($attr, 'frontend', ''), 00540 'frontend_input' => $this->_getValue($attr, 'input', 'text'), 00541 'frontend_input_renderer' => $this->_getValue($attr, 'input_renderer', ''), 00542 'frontend_label' => $this->_getValue($attr, 'label', ''), 00543 'source_model' => $this->_getValue($attr, 'source', ''), 00544 'is_global' => $this->_getValue($attr, 'global', 1), 00545 'is_visible' => $this->_getValue($attr, 'visible', 1), 00546 'is_required' => $this->_getValue($attr, 'required', 1), 00547 'is_user_defined' => $this->_getValue($attr, 'user_defined', 0), 00548 'default_value' => $this->_getValue($attr, 'default', ''), 00549 'is_searchable' => $this->_getValue($attr, 'searchable', 0), 00550 'is_filterable' => $this->_getValue($attr, 'filterable', 0), 00551 'is_comparable' => $this->_getValue($attr, 'comparable', 0), 00552 'is_visible_on_front' => $this->_getValue($attr, 'visible_on_front', 0), 00553 'is_html_allowed_on_front' => $this->_getValue($attr, 'is_html_allowed_on_front', 0), 00554 'is_visible_in_advanced_search' 00555 => $this->_getValue($attr, 'visible_in_advanced_search', 0), 00556 'is_used_for_price_rules' => $this->_getValue($attr, 'used_for_price_rules', 1), 00557 'is_filterable_in_search' => $this->_getValue($attr, 'filterable_in_search', 0), 00558 'used_in_product_listing' => $this->_getValue($attr, 'used_in_product_listing', 0), 00559 'used_for_sort_by' => $this->_getValue($attr, 'used_for_sort_by', 0), 00560 'is_unique' => $this->_getValue($attr, 'unique', 0), 00561 'apply_to' => $this->_getValue($attr, 'apply_to', ''), 00562 'is_configurable' => $this->_getValue($attr, 'is_configurable', 1), 00563 'note' => $this->_getValue($attr, 'note', ''), 00564 'position' => $this->_getValue($attr, 'position', 0), 00565 ); 00566 00567 $sortOrder = isset($attr['sort_order']) ? $attr['sort_order'] : null; 00568 00569 if ($id = $this->getAttribute($entityTypeId, $code, 'attribute_id')) { 00570 $this->updateAttribute($entityTypeId, $id, $data, null, $sortOrder); 00571 } else { 00572 $this->_insertAttribute($data); 00573 } 00574 00575 if (!empty($attr['group'])) { 00576 $sets = $this->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId); 00577 foreach ($sets as $set) { 00578 $this->addAttributeGroup($entityTypeId, $set['attribute_set_id'], $attr['group']); 00579 $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $attr['group'], $code, $sortOrder); 00580 } 00581 } 00582 if (empty($attr['is_user_defined'])) { 00583 $sets = $this->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId); 00584 foreach ($sets as $set) { 00585 $this->addAttributeToSet($entityTypeId, $set['attribute_set_id'], $this->_generalGroupName, $code, $sortOrder); 00586 } 00587 } 00588 00589 if (isset($attr['option']) && is_array($attr['option'])) { 00590 $option = $attr['option']; 00591 $option['attribute_id'] = $this->getAttributeId($entityTypeId, $code); 00592 $this->addAttributeOption($option); 00593 } 00594 00595 return $this; 00596 }
addAttributeGroup | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | name, | |||
$ | sortOrder = null | |||
) |
Add Attribute Group
mixed | $entityTypeId | |
mixed | $setId | |
string | $name | |
int | $sortOrder |
Definition at line 371 of file Setup.php.
00372 { 00373 $setId = $this->getAttributeSetId($entityTypeId, $setId); 00374 $data = array( 00375 'attribute_set_id'=>$setId, 00376 'attribute_group_name'=>$name, 00377 ); 00378 if (isset($this->defaultGroupIdAssociations[$name])) { 00379 $data['default_id'] = $this->defaultGroupIdAssociations[$name]; 00380 } 00381 if (!is_null($sortOrder)) { 00382 $data['sort_order'] = $sortOrder; 00383 } 00384 00385 if ($id = $this->getAttributeGroup($entityTypeId, $setId, $name, 'attribute_group_id')) { 00386 $this->updateAttributeGroup($entityTypeId, $setId, $id, $data); 00387 } else { 00388 if (is_null($sortOrder)) { 00389 $data['sort_order'] = $this->getAttributeGroupSortOrder($entityTypeId, $setId, $sortOrder); 00390 } 00391 $this->_conn->insert($this->getTable('eav/attribute_group'), $data); 00392 } 00393 00394 return $this; 00395 }
addAttributeOption | ( | $ | option | ) |
Add Attribure Option
array | $option |
Definition at line 603 of file Setup.php.
00604 { 00605 if (isset($option['value'])) { 00606 $optionTable = $this->getTable('eav/attribute_option'); 00607 $optionValueTable = $this->getTable('eav/attribute_option_value'); 00608 00609 foreach ($option['value'] as $optionId => $values) { 00610 $intOptionId = (int) $optionId; 00611 if (!empty($option['delete'][$optionId])) { 00612 if ($intOptionId) { 00613 $condition = $this->_conn->quoteInto('option_id=?', $intOptionId); 00614 $write->delete($optionTable, $condition); 00615 } 00616 continue; 00617 } 00618 00619 if (!$intOptionId) { 00620 $data = array( 00621 'attribute_id' => $option['attribute_id'], 00622 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 00623 ); 00624 $this->_conn->insert($optionTable, $data); 00625 $intOptionId = $this->_conn->lastInsertId(); 00626 } else { 00627 $data = array( 00628 'sort_order' => isset($option['order'][$optionId]) ? $option['order'][$optionId] : 0, 00629 ); 00630 $this->_conn->update($optionTable, $data, $this->_conn->quoteInto('option_id=?', $intOptionId)); 00631 } 00632 00633 // Default value 00634 if (!isset($values[0])) { 00635 Mage::throwException(Mage::helper('eav')->__('Default option value is not defined')); 00636 } 00637 00638 $this->_conn->delete($optionValueTable, $this->_conn->quoteInto('option_id=?', $intOptionId)); 00639 foreach ($values as $storeId => $value) { 00640 $data = array( 00641 'option_id' => $intOptionId, 00642 'store_id' => $storeId, 00643 'value' => $value, 00644 ); 00645 $this->_conn->insert($optionValueTable, $data); 00646 } 00647 } 00648 } 00649 }
addAttributeSet | ( | $ | entityTypeId, | |
$ | name, | |||
$ | sortOrder = null | |||
) |
Add Attribute Set
mixed | $entityTypeId | |
string | $name | |
int | $sortOrder |
Definition at line 210 of file Setup.php.
00211 { 00212 $data = array( 00213 'entity_type_id'=>$this->getEntityTypeId($entityTypeId), 00214 'attribute_set_name'=>$name, 00215 'sort_order'=>$this->getAttributeSetSortOrder($entityTypeId, $sortOrder), 00216 ); 00217 00218 if ($id = $this->getAttributeSet($entityTypeId, $name, 'attribute_set_id')) { 00219 $this->updateAttributeSet($entityTypeId, $id, $data); 00220 } else { 00221 $this->_conn->insert($this->getTable('eav/attribute_set'), $data); 00222 00223 $this->addAttributeGroup($entityTypeId, $name, $this->_generalGroupName); 00224 } 00225 00226 return $this; 00227 }
addAttributeToGroup | ( | $ | entityType, | |
$ | setId, | |||
$ | groupId, | |||
$ | attributeId, | |||
$ | sortOrder = null | |||
) |
Add or update attribute to group
int|string | $entityType | |
int|string | $setId | |
int|string | $groupId | |
int|string | $attributeId | |
int | $sortOrder |
Definition at line 852 of file Setup.php.
00853 { 00854 $entityType = $this->getEntityTypeId($entityType); 00855 $setId = $this->getAttributeSetId($entityType, $setId); 00856 $groupId = $this->getAttributeGroupId($entityType, $setId, $groupId); 00857 $attributeId = $this->getAttributeId($entityType, $attributeId); 00858 00859 $bind = array( 00860 'entity_type_id' => $entityType, 00861 'attribute_set_id' => $setId, 00862 'attribute_group_id' => $groupId, 00863 'attribute_id' => $attributeId, 00864 ); 00865 00866 $select = $this->getConnection()->select() 00867 ->from($this->getTable('eav/entity_attribute')) 00868 ->where('entity_type_id=?', $entityType) 00869 ->where('attribute_set_id=?', $setId) 00870 ->where('attribute_id=?', $attributeId); 00871 $row = $this->getConnection()->fetchRow($select); 00872 if ($row) { 00873 // update 00874 if (!is_null($sortOrder)) { 00875 $bind['sort_order'] = $sortOrder; 00876 } 00877 00878 $this->getConnection()->update( 00879 $this->getTable('eav/entity_attribute'), 00880 $bind, 00881 $this->getConnection()->quoteInto('entity_attribute_id=?', $row['entity_attribute_id']) 00882 ); 00883 } 00884 else { 00885 if (is_null($sortOrder)) { 00886 $select = $this->getConnection()->select() 00887 ->from($this->getTable('eav/entity_attribute'), 'MAX(sort_order) + 10') 00888 ->where('entity_type_id=?', $entityType) 00889 ->where('attribute_set_id=?', $setId) 00890 ->where('attribute_group_id=?', $groupId); 00891 $sortOrder = $this->getConnection()->fetchOne($select); 00892 } 00893 $bind['sort_order'] = $sortOrder; 00894 $this->getConnection()->insert($this->getTable('eav/entity_attribute'), $bind); 00895 } 00896 00897 return $this; 00898 }
addAttributeToSet | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | groupId, | |||
$ | attributeId, | |||
$ | sortOrder = null | |||
) |
Add Attribute to All Groups on Attribute Set
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $groupId | |
mixed | $attributeId | |
int | $sortOrder |
Definition at line 814 of file Setup.php.
00815 { 00816 $entityTypeId = $this->getEntityTypeId($entityTypeId); 00817 $setId = $this->getAttributeSetId($entityTypeId, $setId); 00818 $groupId = $this->getAttributeGroupId($entityTypeId, $setId, $groupId); 00819 $attributeId = $this->getAttributeId($entityTypeId, $attributeId); 00820 $generalGroupId = $this->getAttributeGroupId($entityTypeId, $setId, $this->_generalGroupName); 00821 00822 $oldId = $this->_conn->fetchOne("select entity_attribute_id from ".$this->getTable('eav/entity_attribute')." where attribute_set_id=$setId and attribute_id=$attributeId"); 00823 if ($oldId) { 00824 if ($groupId && $groupId != $generalGroupId) { 00825 $newGroupData = array('attribute_group_id'=>$groupId); 00826 $condition = $this->_conn->quoteInto('entity_attribute_id = ?', $oldId); 00827 $this->_conn->update($this->getTable('eav/entity_attribute'), $newGroupData, $condition); 00828 } 00829 return $this; 00830 } 00831 $this->_conn->insert($this->getTable('eav/entity_attribute'), array( 00832 'entity_type_id' =>$entityTypeId, 00833 'attribute_set_id' =>$setId, 00834 'attribute_group_id'=>$groupId, 00835 'attribute_id' =>$attributeId, 00836 'sort_order' =>$this->getAttributeSortOrder($entityTypeId, $setId, $groupId, $sortOrder), 00837 )); 00838 00839 return $this; 00840 }
addEntityType | ( | $ | code, | |
array $ | params | |||
) |
Add an entity type
If already exists updates the entity type with params data
string | $code | |
array | $params |
Definition at line 92 of file Setup.php.
00093 { 00094 $data = array( 00095 'entity_type_code' => $code, 00096 'entity_model' => $params['entity_model'], 00097 'attribute_model' => isset($params['attribute_model']) ? $params['attribute_model'] : '', 00098 'entity_table' => isset($params['table']) ? $params['table'] : 'eav/entity', 00099 'increment_model' => isset($params['increment_model']) ? $params['increment_model'] : '', 00100 'increment_per_store' => isset($params['increment_per_store']) ? $params['increment_per_store'] : 0, 00101 ); 00102 00103 if ($this->getEntityType($code, 'entity_type_id')) { 00104 $this->updateEntityType($code, $data); 00105 } else { 00106 $this->_conn->insert($this->getTable('eav/entity_type'), $data); 00107 } 00108 00109 $this->addAttributeSet($code, 'Default'); 00110 $this->addAttributeGroup($code, 'Default', $this->_generalGroupName); 00111 00112 return $this; 00113 }
cleanCache | ( | ) |
Enter description here...
unknown_type | $baseName | |
array | $options
|
Definition at line 973 of file Setup.php.
00974 { 00975 if (empty($options['no-main'])) { 00976 $sql = " 00977 DROP TABLE IF EXISTS `{$baseName}`; 00978 CREATE TABLE `{$baseName}` ( 00979 `entity_id` int(10) unsigned NOT NULL auto_increment, 00980 `entity_type_id` smallint(8) unsigned NOT NULL default '0', 00981 `attribute_set_id` smallint(5) unsigned NOT NULL default '0', 00982 `increment_id` varchar(50) NOT NULL default '', 00983 `parent_id` int(10) unsigned NULL default '0', 00984 `store_id` smallint(5) unsigned NOT NULL default '0', 00985 `created_at` datetime NOT NULL default '0000-00-00 00:00:00', 00986 `updated_at` datetime NOT NULL default '0000-00-00 00:00:00', 00987 `is_active` tinyint(1) unsigned NOT NULL default '1', 00988 PRIMARY KEY (`entity_id`), 00989 CONSTRAINT `FK_{$baseName}_type` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE, 00990 CONSTRAINT `FK_{$baseName}_store` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE 00991 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; 00992 } 00993 00994 $types = array( 00995 'datetime'=>'datetime', 00996 'decimal'=>'decimal(12,4)', 00997 'int'=>'int', 00998 'text'=>'text', 00999 'varchar'=>'varchar(255)', 01000 ); 01001 if (!empty($options['types']) && is_array($options['types'])) { 01002 if ($options['no-default-types']) { 01003 $types = array(); 01004 } 01005 $types = array_merge($types, $options['types']); 01006 } 01007 01008 foreach ($types as $type=>$fieldType) { 01009 $sql .= " 01010 DROP TABLE IF EXISTS `{$baseName}_{$type}`; 01011 CREATE TABLE `{$baseName}_{$type}` ( 01012 `value_id` int(11) NOT NULL auto_increment, 01013 `entity_type_id` smallint(8) unsigned NOT NULL default '0', 01014 `attribute_id` smallint(5) unsigned NOT NULL default '0', 01015 `store_id` smallint(5) unsigned NOT NULL default '0', 01016 `entity_id` int(10) unsigned NOT NULL default '0', 01017 `value` {$fieldType} NOT NULL, 01018 PRIMARY KEY (`value_id`), 01019 UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`), 01020 ".($type!=='text' ? " 01021 KEY `value_by_attribute` (`attribute_id`,`value`), 01022 KEY `value_by_entity_type` (`entity_type_id`,`value`), 01023 " : "")." 01024 CONSTRAINT `FK_{$baseName}_{$type}` FOREIGN KEY (`entity_id`) REFERENCES `{$baseName}` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE, 01025 CONSTRAINT `FK_{$baseName}_{$type}_attribute` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE, 01026 CONSTRAINT `FK_{$baseName}_{$type}_entity_type` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE, 01027 CONSTRAINT `FK_{$baseName}_{$type}_store` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE 01028 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; 01029 } 01030 01031 try { 01032 $this->_conn->multi_query($sql); 01033 } catch (Exception $e) { 01034 throw $e; 01035 } 01036 01037 return $this; 01038 }
getAllAttributeSetIds | ( | $ | entityTypeId = null |
) |
Get identifiers of all attribute sets
Definition at line 316 of file Setup.php.
00317 { 00318 $where = ''; 00319 if (!is_null($entityTypeId)) { 00320 $where = " WHERE `entity_type_id` = '" . $this->getEntityTypeId($entityTypeId) . "'"; 00321 } 00322 $sql = "SELECT `attribute_set_id` FROM `{$this->getTable('eav/attribute_set')}`" . $where; 00323 return $this->_conn->fetchCol($sql); 00324 }
getAttribute | ( | $ | entityTypeId, | |
$ | id, | |||
$ | field = null | |||
) |
Retrieve Attribute Data By Id or Code
mixed | $entityTypeId | |
mixed | $id | |
string | $field |
Definition at line 705 of file Setup.php.
00706 { 00707 return $this->getTableRow('eav/attribute', 00708 is_numeric($id) ? 'attribute_id' : 'attribute_code', $id, 00709 $field, 00710 'entity_type_id', $this->getEntityTypeId($entityTypeId) 00711 ); 00712 }
getAttributeGroup | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | id, | |||
$ | field = null | |||
) |
Retrieve Attribute Group Data
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $id | |
string | $field |
Definition at line 426 of file Setup.php.
00427 { 00428 $searchId = $id; 00429 if (is_numeric($id)) { 00430 $searchField = 'attribute_group_id'; 00431 } else { 00432 if (isset($this->defaultGroupIdAssociations[$id])) { 00433 $searchField = 'default_id'; 00434 $searchId = $this->defaultGroupIdAssociations[$id]; 00435 } else { 00436 $searchField = 'attribute_group_name'; 00437 } 00438 } 00439 00440 return $this->getTableRow('eav/attribute_group', 00441 $searchField, $searchId, $field, 00442 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $setId) 00443 ); 00444 }
getAttributeGroupId | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | groupId | |||
) |
Retrieve Attribute Group Id by Id or Name
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $groupId |
Definition at line 454 of file Setup.php.
00455 { 00456 if (!is_numeric($groupId)) { 00457 $groupId = $this->getAttributeGroup($entityTypeId, $setId, $groupId, 'attribute_group_id'); 00458 } 00459 if (!is_numeric($groupId)) { 00460 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute group ID')); 00461 } 00462 return $groupId; 00463 }
getAttributeGroupSortOrder | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | sortOrder = null | |||
) |
Retrieve Attribute Group Sort order
mixed | $entityTypeId | |
mixed | $setId | |
int | $sortOrder |
Definition at line 350 of file Setup.php.
00351 { 00352 if (!is_numeric($sortOrder)) { 00353 $sortOrder = $this->_conn->fetchOne("select max(sort_order) 00354 from ".$this->getTable('eav/attribute_group')." 00355 where attribute_set_id=".$this->getAttributeSetId($entityTypeId, $setId) 00356 ); 00357 $sortOrder++; 00358 } 00359 return $sortOrder; 00360 }
getAttributeId | ( | $ | entityTypeId, | |
$ | id | |||
) |
Retrieve Attribute Id Data By Id or Code
mixed | $entityTypeId | |
mixed | $id |
Definition at line 721 of file Setup.php.
00722 { 00723 if (!is_numeric($id)) { 00724 $id = $this->getAttribute($entityTypeId, $id, 'attribute_id'); 00725 } 00726 if (!is_numeric($id)) { 00727 //throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute ID')); 00728 return false; 00729 } 00730 return $id; 00731 }
getAttributeSet | ( | $ | entityTypeId, | |
$ | id, | |||
$ | field = null | |||
) |
Retrieve Attribute set data by id or name
mixed | $entityTypeId | |
mixed | $id | |
string | $field |
Definition at line 256 of file Setup.php.
00257 { 00258 return $this->getTableRow('eav/attribute_set', 00259 is_numeric($id) ? 'attribute_set_id' : 'attribute_set_name', $id, 00260 $field, 00261 'entity_type_id', $this->getEntityTypeId($entityTypeId) 00262 ); 00263 }
getAttributeSetId | ( | $ | entityTypeId, | |
$ | setId | |||
) |
Retrieve Attribute Set Id By Id or Name
Mage_Eav_Exception |
mixed | $entityTypeId | |
mixed | $setId |
Definition at line 273 of file Setup.php.
00274 { 00275 if (!is_numeric($setId)) { 00276 $setId = $this->getAttributeSet($entityTypeId, $setId, 'attribute_set_id'); 00277 } 00278 if (!is_numeric($setId)) { 00279 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong attribute set ID')); 00280 } 00281 return $setId; 00282 }
getAttributeSetSortOrder | ( | $ | entityTypeId, | |
$ | sortOrder = null | |||
) |
Retrieve Attribute Set Sort order
mixed | $entityTypeId | |
int | $sortOrder |
Definition at line 190 of file Setup.php.
00191 { 00192 if (!is_numeric($sortOrder)) { 00193 $sortOrder = $this->_conn->fetchOne("select max(sort_order) 00194 from ".$this->getTable('eav/attribute_set')." 00195 where entity_type_id=".$this->getEntityTypeId($entityTypeId) 00196 ); 00197 $sortOrder++; 00198 } 00199 return $sortOrder; 00200 }
getAttributeSortOrder | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | groupId, | |||
$ | sortOrder = null | |||
) |
Retrieve Attribute Sort Order
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $groupId | |
int | $sortOrder |
Definition at line 792 of file Setup.php.
00793 { 00794 if (!is_numeric($sortOrder)) { 00795 $sortOrder = $this->_conn->fetchOne("select max(sort_order) 00796 from ".$this->getTable('eav/entity_attribute')." 00797 where attribute_group_id=".$this->getAttributeGroupId($entityTypeId, $setId, $groupId) 00798 ); 00799 $sortOrder++; 00800 } 00801 return $sortOrder; 00802 }
getAttributeTable | ( | $ | entityTypeId, | |
$ | id | |||
) |
Return table name for eav attribute
int|string | $entityTypeId Entity Type id or Entity Type code | |
int|string | $id Attribute id or Attribute code |
Definition at line 740 of file Setup.php.
00741 { 00742 $entityKeyName = is_numeric($entityTypeId) ? 'entity_type_id' : 'entity_type_code'; 00743 $attributeKeyName = is_numeric($id) ? 'attribute_id' : 'attribute_code'; 00744 00745 $select = $this->getConnection()->select() 00746 ->from( 00747 array('e' => $this->getTable('eav/entity_type')), 00748 array('entity_table')) 00749 ->join( 00750 array('a' => $this->getTable('eav/attribute')), 00751 'a.entity_type_id=e.entity_type_id', 00752 array('backend_type')) 00753 ->where("e.{$entityKeyName}=?", $entityTypeId) 00754 ->where("a.{$attributeKeyName}=?", $id) 00755 ->limit(1); 00756 if ($result = $this->getConnection()->fetchRow($select)) { 00757 $table = $this->getTable($result['entity_table']); 00758 if ($result['backend_type'] != 'static') { 00759 $table .= '_' . $result['backend_type']; 00760 } 00761 return $table; 00762 } 00763 00764 return false; 00765 }
getDefaultAttributeGroupId | ( | $ | entityType, | |
$ | attributeSetId = null | |||
) |
Retrieve Default Attribute Group Id By Entity Type and Attribute Set
string|int | $entityType | |
int | $attributeSetId |
Definition at line 490 of file Setup.php.
00491 { 00492 $entityType = $this->getEntityTypeId($entityType); 00493 if (!is_numeric($attributeSetId)) { 00494 $attributeSetId = $this->getDefaultAttributeSetId($entityType); 00495 } 00496 00497 $select = $this->getConnection()->select() 00498 ->from($this->getTable('eav/attribute_group'), 'attribute_group_id') 00499 ->where('attribute_set_id=?', $attributeSetId) 00500 ->order('default_id DESC, sort_order') 00501 ->limit(1); 00502 return $this->getConnection()->fetchOne($select); 00503 }
getDefaultAttributeSetId | ( | $ | entityType | ) |
Retrieve Default Attribute Set for Entity Type
string|int | $entityType |
Definition at line 332 of file Setup.php.
00333 { 00334 $select = $this->getConnection()->select() 00335 ->from($this->getTable('eav/entity_type'), 'default_attribute_set_id') 00336 ->where(is_numeric($entityType) ? 'entity_type_id=?' : 'entity_type_code=?', $entityType); 00337 return $this->getConnection()->fetchOne($select); 00338 }
getEntityType | ( | $ | id, | |
$ | field = null | |||
) |
Retrieve Entity Type Data
int|string | $id | |
string | $field |
Definition at line 139 of file Setup.php.
00140 { 00141 return $this->getTableRow('eav/entity_type', 00142 is_numeric($id) ? 'entity_type_id' : 'entity_type_code', $id, 00143 $field 00144 ); 00145 }
getEntityTypeId | ( | $ | entityTypeId | ) |
Retrieve Entity Type Id By Id or Code
mixed | $entityTypeId |
Definition at line 153 of file Setup.php.
00154 { 00155 if (!is_numeric($entityTypeId)) { 00156 $entityTypeId = $this->getEntityType($entityTypeId, 'entity_type_id'); 00157 } 00158 if (!is_numeric($entityTypeId)) { 00159 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Wrong entity ID')); 00160 } 00161 return $entityTypeId; 00162 }
installDefaultGroupIds | ( | ) |
Install Default Group Ids
Definition at line 58 of file Setup.php.
00059 { 00060 $setIds = $this->getAllAttributeSetIds(); 00061 foreach ($this->defaultGroupIdAssociations as $defaultGroupName=>$defaultGroupId) { 00062 foreach ($setIds as $set) { 00063 $groupId = $this->getTableRow('eav/attribute_group', 00064 'attribute_group_name', $defaultGroupName, 'attribute_group_id', 'attribute_set_id', $set 00065 ); 00066 if (!$groupId) { 00067 $groupId = $this->getTableRow('eav/attribute_group', 00068 'attribute_set_id', $set, 'attribute_group_id' 00069 ); 00070 } 00071 $this->updateTableRow('eav/attribute_group', 00072 'attribute_group_id', $groupId, 00073 'default_id', $defaultGroupId 00074 ); 00075 } 00076 } 00077 return $this; 00078 }
installEntities | ( | $ | entities = null |
) |
Install entities
array | $entities |
Definition at line 908 of file Setup.php.
00909 { 00910 $this->cleanCache(); 00911 00912 if (is_null($entities)) { 00913 $entities = $this->getDefaultEntities(); 00914 } 00915 00916 foreach ($entities as $entityName=>$entity) { 00917 $this->addEntityType($entityName, $entity); 00918 00919 $frontendPrefix = isset($entity['frontend_prefix']) ? $entity['frontend_prefix'] : ''; 00920 $backendPrefix = isset($entity['backend_prefix']) ? $entity['backend_prefix'] : ''; 00921 $sourcePrefix = isset($entity['source_prefix']) ? $entity['source_prefix'] : ''; 00922 00923 foreach ($entity['attributes'] as $attrCode=>$attr) { 00924 if (!empty($attr['backend'])) { 00925 if ('_'===$attr['backend']) { 00926 $attr['backend'] = $backendPrefix; 00927 } elseif ('_'===$attr['backend']{0}) { 00928 $attr['backend'] = $backendPrefix.$attr['backend']; 00929 } else { 00930 $attr['backend'] = $attr['backend']; 00931 } 00932 } 00933 if (!empty($attr['frontend'])) { 00934 if ('_'===$attr['frontend']) { 00935 $attr['frontend'] = $frontendPrefix; 00936 } elseif ('_'===$attr['frontend']{0}) { 00937 $attr['frontend'] = $frontendPrefix.$attr['frontend']; 00938 } else { 00939 $attr['frontend'] = $attr['frontend']; 00940 } 00941 } 00942 if (!empty($attr['source'])) { 00943 if ('_'===$attr['source']) { 00944 $attr['source'] = $sourcePrefix; 00945 } elseif ('_'===$attr['source']{0}) { 00946 $attr['source'] = $sourcePrefix.$attr['source']; 00947 } else { 00948 $attr['source'] = $attr['source']; 00949 } 00950 } 00951 00952 $this->addAttribute($entityName, $attrCode, $attr); 00953 } 00954 $this->setDefaultSetToEntityType($entityName); 00955 } 00956 00957 return $this; 00958 }
removeAttribute | ( | $ | entityTypeId, | |
$ | code | |||
) |
Remove Attribute
mixed | $entityTypeId | |
mixed | $code |
Definition at line 774 of file Setup.php.
00775 { 00776 $attributeId = $this->getAttributeId($entityTypeId, $code); 00777 if ($attributeId) { 00778 $this->deleteTableRow('eav/attribute', 'attribute_id', $attributeId); 00779 } 00780 return $this; 00781 }
removeAttributeGroup | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | id | |||
) |
Remove Attribute Group By Id or Name
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $id |
Definition at line 473 of file Setup.php.
00474 { 00475 $this->deleteTableRow( 00476 'eav/attribute_group', 00477 'attribute_group_id', 00478 $this->getAttributeGroupId($entityTypeId, $setId, $id) 00479 ); 00480 return $this; 00481 }
removeAttributeSet | ( | $ | entityTypeId, | |
$ | id | |||
) |
Remove Attribute Set
mixed | $entityTypeId | |
mixed | $id |
Definition at line 291 of file Setup.php.
00292 { 00293 $this->deleteTableRow('eav/attribute_set', 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $id)); 00294 return $this; 00295 }
removeEntityType | ( | $ | id | ) |
Remove entity type by Id or Code
mixed | $id |
Definition at line 170 of file Setup.php.
00171 { 00172 if (is_numeric($id)) { 00173 $this->deleteTableRow('eav/entity_type', 'entity_type_id', $id); 00174 } 00175 else { 00176 $this->deleteTableRow('eav/entity_type', 'entity_type_code', (string)$id); 00177 } 00178 return $this; 00179 }
setDefaultSetToEntityType | ( | $ | entityType, | |
$ | attributeSet = 'Default' | |||
) |
Set Default Attribute Set to Entity Type
mixed | $entityType |
Definition at line 303 of file Setup.php.
00304 { 00305 $entityTypeId = $this->getEntityTypeId($entityType); 00306 $setId = $this->getAttributeSetId($entityTypeId, $attributeSet); 00307 $this->updateEntityType($entityTypeId, 'default_attribute_set_id', $setId); 00308 return $this; 00309 }
updateAttribute | ( | $ | entityTypeId, | |
$ | id, | |||
$ | field, | |||
$ | value = null , |
|||
$ | sortOrder = null | |||
) |
Update Attribute data
mixed | $entityTypeId | |
mixed | $id | |
string | $field | |
mixed | $value | |
int | $sortOrder |
Definition at line 661 of file Setup.php.
00662 { 00663 if (!is_null($sortOrder)) { 00664 $this->updateTableRow('eav/entity_attribute', 00665 'attribute_id', $this->getAttributeId($entityTypeId, $id), 00666 'sort_order', $sortOrder 00667 ); 00668 } 00669 00670 $attributeFields = $this->_getAttributeTableFields(); 00671 if (is_array($field)) { 00672 $bind = array(); 00673 foreach ($field as $k => $v) { 00674 if (isset($attributeFields[$k])) { 00675 $bind[$k] = $v; 00676 } 00677 } 00678 if (!$bind) { 00679 return $this; 00680 } 00681 $field = $bind; 00682 } 00683 else { 00684 if (!isset($attributeFields[$field])) { 00685 return $this; 00686 } 00687 } 00688 00689 $this->updateTableRow('eav/attribute', 00690 'attribute_id', $this->getAttributeId($entityTypeId, $id), 00691 $field, $value, 00692 'entity_type_id', $this->getEntityTypeId($entityTypeId) 00693 ); 00694 return $this; 00695 }
updateAttributeGroup | ( | $ | entityTypeId, | |
$ | setId, | |||
$ | id, | |||
$ | field, | |||
$ | value = null | |||
) |
Update Attribute Group Data
mixed | $entityTypeId | |
mixed | $setId | |
mixed | $id | |
string | $field | |
mixed | $value |
Definition at line 407 of file Setup.php.
00408 { 00409 $this->updateTableRow('eav/attribute_group', 00410 'attribute_group_id', $this->getAttributeGroupId($entityTypeId, $setId, $id), 00411 $field, $value, 00412 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $setId) 00413 ); 00414 return $this; 00415 }
updateAttributeSet | ( | $ | entityTypeId, | |
$ | id, | |||
$ | field, | |||
$ | value = null | |||
) |
Update attribute set data
mixed | $entityTypeId | |
int | $id | |
string | $field | |
mixed | $value |
Definition at line 238 of file Setup.php.
00239 { 00240 $this->updateTableRow('eav/attribute_set', 00241 'attribute_set_id', $this->getAttributeSetId($entityTypeId, $id), 00242 $field, $value, 00243 'entity_type_id', $this->getEntityTypeId($entityTypeId) 00244 ); 00245 return $this; 00246 }
updateEntityType | ( | $ | code, | |
$ | field, | |||
$ | value = null | |||
) |
Update entity row
string | $code | |
string | $field | |
string | $value |
Definition at line 123 of file Setup.php.
00124 { 00125 $this->updateTableRow('eav/entity_type', 00126 'entity_type_id', $this->getEntityTypeId($code), 00127 $field, $value 00128 ); 00129 return $this; 00130 }