save custom fields in checkout to user table

  • Posts: 6
  • Thank you received: 0
12 years 11 months ago #31712

Hello,

I created a custom field, referee, in user table. My client required me to display an editable field during checkout for the first order and save this field to referee column in user table when submitting the order. Checkout process seemed to only deal with the custom field created in order table. Is there a way I can do this? Any hint is welcome.

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 11 months ago #31732

Hi,

If you create a custom field of the table user, it will only be displayed when the user registers and then the user won't have to enter it next time he will order as he will be able to log in. There is nothing else to do from what I understand.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
12 years 11 months ago #31745

Nicolas,

Thanks for the reply. my requirement is to have an editable field displayed during checkout and when the order is submitted, the value of this field will be saved into a field in user table I previously created. I know normally, the custom field created for checkout can be saved into order table, but instead of saving it into order table, I want to save it into user table - only for the first order the user created.

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 11 months ago #31746

You're talking about a custom field of the table "order", which is indeed saved in the order table.
However, I'm talking about a custom field of the table "user" which is saved in the user table, as you want.

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
12 years 11 months ago #31749

I am talking about having a text field displayed in the front-end checkout screen (the screen having payment/billing address/order) but being saved into user table.

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 11 months ago #31768

Yes. Me too. You can do that with a custom field of the table "user".

Please Log in or Create an account to join the conversation.

  • Posts: 6
  • Thank you received: 0
12 years 11 months ago #31777

But if I create a custom field in user table, it only show up in registration screen. It won't show up in the checkout screen. How can I make it show up in the checkout screen?

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 11 months ago #31814

When you're not logged in and that you checkout, you will see it on your checkout, in the registration area (so the first time you make an order as a customer and that you have to create an account).

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
12 years 5 months ago #53387

I need the same. I need some custom User fields (i.e. measurements) that are:
- stored in the user profile
- showed in the check-out process
- can be updated during check-out and stored back to the user profile

Preferably on a separate step in the check-out process.

I do not mind to do some programming if you could point me in the right direction.
EDIT: i.e. show fields on FIELDS step with a link to the registration page would be a start

Thanks in andvance

Last edit: 12 years 5 months ago by marloesborker.

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 5 months ago #53495

The fields step by be edited via the menu Display->Views. Search for "fields".
You will have to load the user information via the function :
$user = hikashop_loadUser(true);

Which should contain the custom data.
With the latest version of HikaShop, custom user fields should be displayed on the user profile edition page thanks to the user synchronization plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
12 years 5 months ago #53537

Thanks, I understand the concept. I need a bit more help though:

1. How do I display the specific user fields, assuming they all start with m_ (i.e. m_body_length, m_waist_length). I would like to use the foreach construct to loop through them and put them in a table, just like the custom fields are processed in the default view.

something like:

$user = hikashop_loadUser(true);
foreach($user->Fields as $field ...filter on fieldname starts with 'm_'...
{
...create table rows containing label and value...
}

2. How do I make them editable in this step, just like the custom fields are.

Sorry, I'm a c# man, just cannot figure out how to do it in php :(

Please Log in or Create an account to join the conversation.

  • Posts: 82821
  • Thank you received: 13368
  • MODERATOR
12 years 5 months ago #53610

1. The custom user fields are only loaded in the login view. So you need to load the fields yourself:
$fieldsClass = hikashop_get('class.field');
$user = hikashop_loadUser(true);
$fields = $fieldsClass->getFields('frontcomp',$user,'user');
foreach($fields as $field ){
$namekey = $field->field_namekey;
if(substr($field->field_namekey,0,2)=='m_') echo $user->$namekey;
}

2. If you want to make them editable, you will have to use similar code to the custom_fields view file in your foreach.

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum