How to add your custom input fields shipping modules?

Developer
Tól től Hungary
Tagság júl. 2017 óta

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
Tól től Sweden
Tagság máj. 2013 óta
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
Tól től Hungary
Tagság júl. 2017 óta

Thanks Tim!

Not showing the current version 3.0 yet?

I do not see the completed field when ordering.

tim
Founder
Tól től Sweden
Tagság máj. 2013 óta
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
Tól től Hungary
Tagság júl. 2017 óta

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
Tól től Sweden
Tagság máj. 2013 óta
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
Tól től Hungary
Tagság júl. 2017 óta

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
Tól től Sweden
Tagság máj. 2013 óta
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.

Ezt a témát a hosszú inaktivitás miatt bezártuk. A hozzászólás nem lehetséges.
Ez a weboldal nem használ cookie-kat és nem használ harmadik féltől származó nyomkövetési technológiát. Úgy gondoljuk, hogy jobban tudjuk csinálni, mint mások, és tényleg gondolunk az Ön magánéletére.