如何为Drupal Commerce 2订单信息表单增加价值?

时间:2017-11-17 15:39:42

标签: drupal drupal-8 drupal-commerce

我创建了一个Drupal模块并添加了alter function形式:

    MY_MODULE_form_alter(&$form, &$form_state, $form_id){
     if(($form_id === 'commerce_checkout_flow_multistep_default') &&
     ($form['#step_id'] === 'order_information')){

      $form['contact_information']['email']['#value'] = $email; // This is working

      ...

我还添加了这段代码:

$form['payment_information']['billing_information']['address'][0]['address']['given_name']['#value'] = $ime;
$form['payment_information']['billing_information']['address'][0]['address']['family_name']['#value'] = $prezime;
$form['payment_information']['billing_information']['address'][0]['address']['address_line1']['#value'] = $adresa;
$form['payment_information']['billing_information']['address'][0]['address']['postal_code']['#value'] = $ptt;
$form['payment_information']['billing_information']['address'][0]['address']['locality']['#value'] = $grad;

但这对我不起作用。任何的想法?

1 个答案:

答案 0 :(得分:0)

PHP不会扩展简单的引用变量,如'$grad'。除非确实需要,否则不要引用变量,在这种情况下使用双引号:"$grad"。见PHP strings and variable expansion

其次,#value用于设置用户无法编辑的值。请改用#default_value。见Drupal Form API