How to add your custom input fields shipping modules?

Developer
Från Hungary
Medlem sedan juli 2017

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
Founder
Från Sweden
Medlem sedan maj 2013
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().

Developer
Från Hungary
Medlem sedan juli 2017

Thanks Tim!

Not showing the current version 3.0 yet?

I do not see the completed field when ordering.

tim
Founder
Från Sweden
Medlem sedan maj 2013
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();
}
Developer
Från Hungary
Medlem sedan juli 2017

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
Founder
Från Sweden
Medlem sedan maj 2013
tim

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

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

Developer
Från Hungary
Medlem sedan juli 2017

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
Founder
Från Sweden
Medlem sedan maj 2013
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.

Den här tråden har stängts på grund av lång inaktivitet. Det går inte att posta inlägg till den.
Denna webbplats använder inga kakor och ingen spårningsteknik från tredje part . Vi tror att vi kan göra det bättre än andra och tänker verkligen på din integritet.