/** * Add an entity type * * If already exists updates the entity type with params data * * @param string $code * @param array $params * @return Mage_Eav_Model_Entity_Setup * @throws Exception */ public function addEntityType($code, array $params) { $this->getConnection()->beginTransaction(); try { $_updateMode = false; if ($this->getEntityType($code, 'entity_type_id')) { $_updateMode = true; } $params['entity_model'] = $this->_getValue($params, 'entity_model', sprintf('goodahead_etm/custom_%s_entity', $code)); $params['attribute_model'] = $this->_getValue($params, 'attribute_model', 'goodahead_etm/entity_attribute'); $params['table'] = $this->_getValue($params, 'table', 'goodahead_etm/entity'); $params['additional_attribute_table'] = $this->_getValue($params, 'additional_attribute_table', 'goodahead_etm/eav_attribute'); $params['entity_attribute_collection'] = $this->_getValue($params, 'entity_attribute_collection', 'goodahead_etm/entity_attribute_collection'); parent::addEntityType($code, $params); $entityTypeId = $this->getEntityType($code, 'entity_type_id'); if ($entityTypeId) { $data = array('entity_type_id' => $entityTypeId, 'entity_type_name' => $this->_getValue($params, 'entity_type_name', $code), 'default_attribute_id' => $this->_getValue($params, 'default_attribute_id'), 'entity_type_root_template' => $this->_getValue($params, 'entity_type_root_template'), 'entity_type_layout_xml' => $this->_getValue($params, 'entity_type_layout_xml'), 'entity_type_content' => $this->_getValue($params, 'entity_type_content')); if ($_updateMode) { unset($data['entity_type_id']); $this->updateEntityTypeExtra($code, $data); } else { $this->_conn->insert($this->getTable('goodahead_etm/eav_entity_type'), $data); } if ($this->_getValue($params, 'create_system_attributes', false)) { $this->addAttribute($entityTypeId, 'created_at', array('backend' => 'eav/entity_attribute_backend_time_created', 'type' => 'static', 'frontend' => 'eav/entity_attribute_frontend_datetime', 'input' => 'datetime', 'required' => false, 'label' => 'Created At', 'sort_order' => 1000)); $this->addAttribute($entityTypeId, 'updated_at', array('backend' => 'eav/entity_attribute_backend_time_updated', 'type' => 'static', 'frontend' => 'eav/entity_attribute_frontend_datetime', 'input' => 'datetime', 'required' => false, 'label' => 'Updated At', 'sort_order' => 1000)); } } $this->getConnection()->commit(); } catch (Exception $e) { $this->getConnection()->rollBack(); throw $e; } return $this; }