How to add your custom input fields shipping modules?

Hello!

The code below is on the wiki page. 


      return array(
        'title' => $this->name,
        'options' => array(
          array(
            'id' => 'option_1',
            'icon' => $this->settings['icon'],
            'name' => 'Option 1',
            'description' => 'This is the description for option 1',
            'fields' => '<input type="text" name="foo" value="'. @$this->userdata['foo'] .'" />' . PHP_EOL
                      . '<input type="text" name="bar" value="'. @$this->userdata['bar'] .'" />',
            'cost' => $this->settings['fee_1'],
            'tax_class_id' => $this->settings['tax_class_id'],
            'exclude_cheapest' => false,
          ),
        ),
      );
    }```

The custom field appears on the checkout page and can be filled out.
But how do I see this on the orders page? How can I record this so I can see it when editing my order?
tim

The next version 3.0 will save the shipping user data to the order. But for 2.x you would need to process this data yourself in the module.

You should be able to access the data using $_POST['myvar'] in select() and after_process().

Thanks Tim!

Not showing the current version 3.0 yet?

I do not see the completed field when ordering.

tim

I am working hard to get a public beta out for 3.0. Maybe within weeks.

Did you try something like this?

  $order->data['comments'][] = [
    'text' => 'Value of myvar:' . $_POST['myvar'],
  ];
  $order->save();
}

Yes I tried and this too but it doesn't go through.


 database::query(
 'UPDATE '.DB_TABLE_ORDERS."
 SET `foo` = '". database::input($this->userdata['foo']) ."',
 `bar` = '".     database::input($this->userdata['bar']) ."'
 WHERE id = '". (int)$order->data['id'] ."'
 LIMIT 1;"
 );
 }```
tim

Did you get an error or did it just simply not set any data?

What does this show?:
 var_dump($this->userdata); exit;

So far nothing has been shown, now there is an error message:

Fatal error: 1054 - Unknown column 'foo' in 'field list' UPDATE lite4.lc_orders SET foo = 'test1', bar = 'test2' WHERE id = '6' LIMIT 1; in ~/includes/library/lib_database.inc.php (Line 260)

tim

Oh wait.. you can't actually input 'foo' and 'bar' as column names. That's a dummy example 😆. Create the column and put the real name in.

Chủ đề này đã bị đóng do không hoạt động trong thời gian dài. Không thể đăng bài vào chủ đề này.
View code on GitHub