Where To Store Custom Data, That Is Related To Order?

Hi all!





My add-on needs to extend order properties with several custom fields.

I want to avoid creation of separate table for my addon data, and store custom fields somewhere in the existing table structure.



Example: my add-on offers customer a “Gift Wrap” checkbox during checkout. I can inject required HTML to views using template hooks, and then trap checkbox values using hooks in controllers. Now I need to store customer selection (if checkbox is set or not) together with order data.



Ideally, I would like to store my custom fields and a serizlized array somewhere in the orders table, and

to let CS-Cart save this field and populate for me, without writing much code.



What is the best way to do it? I wonder, if there is a best practice for this approach?



Thank you in advance.

@Zahhar,



You can use the “cscart_order_data” table. It stores a lot of different order data by default.



Here is the example code:



$_data = array (
'order_id' => $order_id,
'type' => 'Z',
'data' => serialize(YOUR_CUSTOM_DATA_ARRAY),
);
db_query("REPLACE INTO ?:order_data ?e", $_data);




Just make sure that the type char (Z in your case) is not used by core functions or add-ons. I can provide you with few examples from the core:



P - payment information

R - secondary currency

T - taxes

G - groups information

L - shipping information

C - coupons

Thanks, I will try this approach.

@Zahhar,



You are welcome! If you face any problem, please let us know.

@Zahhar,

You can use the "cscart_order_data" table. It stores a lot of different order data by default.

Here is the example code:

  $_data = array (
	    'order_id' => $order_id,
	    'type' => 'Z',
	    'data' => serialize(YOUR_CUSTOM_DATA_ARRAY),
    );
db_query("REPLACE INTO ?:order_data ?e", $_data);
Just make sure that the type char (Z in your case) is not used by core functions or add-ons. I can provide you with few examples from the core:

P - payment information
R - secondary currency
T - taxes
G - groups information
L - shipping information
C - coupons

Excuse me for posting in a thread so old.

I have been looking for this information you have just said about the meaning of the one letter code. I wonder why it is not in the docs!

Thank you

Excuse me for posting in a thread so old.

I have been looking for this information you have just said about the meaning of the one letter code. I wonder why it is not in the docs!

Thank you

I do not know the answer. Try to post it to the bug tracker. Possibly they will extend the documentation