<?php
// $Id: magento_products.install
/**
 * Implementation of hook_install()
 */
function magento_orders_install() {
  magento_orders_add_content_type('magento_order','Magento order', 'Order from Magento system');

  module_load_include('inc', 'content', 'includes/content.crud');
  magento_orders_add_field('field_increment_id','Increment Id','number_integer','number');
  magento_orders_add_field('field_data','Order data','text','text_textarea');
}
/**
 * Implementation of hook_uninstall()
 */
function magento_orders_uninstall() {
  magento_orders_delete_content_type('magento_order','Magento order');
}

function magento_orders_add_content_type($content_type,$name, $description) {
  $type = new stdClass();
  $type->type = $content_type;
  $type->name = $name;
  $type->module = 'node';
  $type->has_title = TRUE;
  $type->title_label = t('Order');
  $type->has_body = FALSE;
  $type->description = $description;
  $type->help = '';
  $type->min_word_count = 0;
  $type->custom = TRUE;
  $type->modified = TRUE;
  $type->locked = FALSE;
  $type->orig_type = $type->type;

  $status = node_type_save($type);
  node_types_rebuild();

  $t_args = array('%name' => $type->name);
  if ($status == SAVED_UPDATED) {
    drupal_set_message(t('The content type %name has been updated.', $t_args));
  }
  elseif ($status == SAVED_NEW) {
    drupal_set_message(t('The content type %name has been added.', $t_args));
  }
}

function magento_orders_delete_content_type($content_type,$name) {
  node_type_delete($content_type);
  node_types_rebuild();
  $t_args = array('%name' => $name);
  drupal_set_message(t('The content type %name has been deleted.', $t_args));
}

function magento_orders_add_field($name,$label,$type,$widget_type) {
  $field = content_fields($name,'magento_order');
  if (empty($field)) {
    $field = array();
    $field['label'] = $label;
    $field['field_name'] = $name;
    $field['widget_type'] = $widget_type;
    $field['type'] = $type;
    $field['parent'] = '';
    $field['hidden_name'] = '_add_new_field';
    $field['type_name'] = 'magento_order';
    content_field_instance_create($field);
  }
}
