删除drupal commerce node add form 左下边的product catalog

http://drupal.org/node/1864260

ting2

经过搜索这个函数在commerce_backoffice这个模块中. commerce_backoffice/commerce_backoffice_product.module

/**
 * Implements hook_form_views_form_alter().
 */
function commerce_backoffice_product_form_alter(&$form, &$form_state, $form_id) {
  // Alter the node edit form to group the categories in a vertical tab.
  if (isset($form['#node_edit_form'])) {
    $product_node_types = commerce_product_reference_node_types();
    if (in_array($form['#node']->type, array_keys($product_node_types))) {
      // Enable the #fieldset key.
      $form['#pre_render'][] = 'commerce_backoffice_pre_render_add_fieldset_markup';
      // Add a new vertical tab.
      $form['product_catalog'] = array(
        '#type' => 'fieldset',
        '#title' => t('Product catalog'),
        '#group' => 'additional_settings',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => -10,
      );

      // Assign all taxonomy reference fields to the new vertical tab.
      foreach (field_info_instances('node', $form['#node']->type) as $field_name => $instance) {
        $field = field_info_field($field_name);

        if ($field['type'] == 'taxonomy_term_reference') {
          $form[$field_name]['#fieldset'] = 'product_catalog';
        }
      }
    }
  }
  // Alter the Exposed Filters for products page
  if (isset($form['submit']['#id']) && $form['submit']['#id'] == 'edit-submit-commerce-backoffice-products') {
    $form['product_display_node_type']['#attributes'] = array('data-placeholder' => array(t('All product types')));
    $form['product_display_term_node_tid_multiple']['#attributes'] = array('data-placeholder' => array(t('All categories')));
    $form['status']['#options']['All'] = t('All statuses');
    $form['combine']['#attributes'] = array('placeholder' => array(t('Search by title or SKU')));
  }
}

方法1

: 直接将上面的代码注释掉, 不推荐.因为他修改了模块的代码不符号标准:

/**
 * Implements hook_form_views_form_alter().
 */
function commerce_backoffice_product_form_alter(&$form, &$form_state, $form_id) {
  // Alter the node edit form to group the categories in a vertical tab.
  if (isset($form['#node_edit_form'])) {
    $product_node_types = commerce_product_reference_node_types();
    if (in_array($form['#node']->type, array_keys($product_node_types))) {
      // Enable the #fieldset key.
      $form['#pre_render'][] = 'commerce_backoffice_pre_render_add_fieldset_markup';
      // Add a new vertical tab.
      /*$form['product_catalog'] = array(
        '#type' => 'fieldset',
        '#title' => t('Product catalog'),
        '#group' => 'additional_settings',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => -10,
      );*/

      // Assign all taxonomy reference fields to the new vertical tab.
      foreach (field_info_instances('node', $form['#node']->type) as $field_name => $instance) {
        $field = field_info_field($field_name);

        if ($field['type'] == 'taxonomy_term_reference') {
          //$form[$field_name]['#fieldset'] = 'product_catalog';
        }
      }
    }
  }
  // Alter the Exposed Filters for products page
  if (isset($form['submit']['#id']) && $form['submit']['#id'] == 'edit-submit-commerce-backoffice-products') {
    $form['product_display_node_type']['#attributes'] = array('data-placeholder' => array(t('All product types')));
    $form['product_display_term_node_tid_multiple']['#attributes'] = array('data-placeholder' => array(t('All categories')));
    $form['status']['#options']['All'] = t('All statuses');
    $form['combine']['#attributes'] = array('placeholder' => array(t('Search by title or SKU')));
  }
}

方法2

: 用 hook_form_alter().如果不能用.一定是你自定义模块weight不够大.你需要在sysytem表里面将你自定义的这个模块的weight改到一点10或者100

function modulename_form_alter(&$form, $form_state) {
  if (isset($form['#node_edit_form'])) {
    unset($form['product_catalog']);
  }
}

change field settings

  foreach(field_info_fields() as $field) {
    if ($field['type'] == 'image') {
      foreach($field['bundles'] as $entity_type => $bundles) {
        foreach($bundles as $bundle) {
          //$bundle_settings = field_bundle_settings($entity_type, $bundle); 
          //field_bundle_settings($entity_type, $bundle, array(
//            'alt_save_replace_token' => 0,
//            'title_save_replace_token' => 1
//          ));
          $field_instance = field_info_instance($entity_type, $field['field_name'], $bundle);
          $field_instance['settings']['settings1'] = 0;
          $field_instance['settings']['settings2'] = 0;
          field_update_field($field_instance);
        }
      }
    }
  }

PHP 计算中奖概率

方法1

//总数有1000个
$total = 1000;

//中奖率, 百分比.  key为奖励的等级
$reward = array(1=>0.03, 0.1, 0.3);

$start = 0;

$result = NULL;
$probability = rand(0, $total);
foreach($reward as $key=>$value) {
  /*
   * 比如0.03的概率就是 1000 * 0.03 = 30
   * 1等奖的概率就是生成的随机数为0 - 30
   * 2登奖的概率为30 到 1000 * 0.1. 也就是30-130
   * ....
   */
  if($start < $probability && $probability <= ($start + $total * $value)) {
    $result = $key;
    break;
  }
  $start = $start + $total * $value;
}

if($result == NULL) {
  echo '谢谢惠顾';
} else {
  echo '
恭喜你中了' . $result . '等奖励'; }

方法2, 创建应用池

function get_reward() {
  //中奖率, 百分比
  return array(0.01, 0.1, 0.3);
}

/**
 * 抽奖.
 * 
 * @return int
 *   0没中奖, 1=>1等奖. 2=>2等奖
 */
function probability() {
  //总数有100个
  $total = 100;
  
  //基数为100内的各奖项的数量, 把中奖率转换成数字. 然后生成数组
  $range = array();
  
  $start_key = 1;
  foreach (get_reward() as $key => $value) {
    $range[$start_key] = $value * $total;
    $start_key++;
  }
  $range[0] = $total - array_sum($range);
  
  //这里是奖池
  $pool = array();
  foreach ($range as $k => $v) {
    $pool += array_fill(count($pool), $v, $k);
  }
  
  return $pool[mt_rand(0, $total - 1)];
}