|

Where To Store Custom Data, That Is Related To Order?
Posted 25 March 2014 - 01:10 PM #1
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.
Boutique digital agency, marketing automation: bergdigital.ch
Posted 25 March 2014 - 01:21 PM #2
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
CS-Cart USD 345 Multi-Vendor USD 1250 Multi-Vendor PLUS USD 3100 (2775)
CS-Cart Ultimate USD 775 CS-Cart + YOUPI USD 545 Multi-Vendor Ultimate USD 7500 (6000)
Posted 25 March 2014 - 02:27 PM #3
Boutique digital agency, marketing automation: bergdigital.ch
Posted 25 March 2014 - 02:51 PM #4
You are welcome! If you face any problem, please let us know.
CS-Cart USD 345 Multi-Vendor USD 1250 Multi-Vendor PLUS USD 3100 (2775)
CS-Cart Ultimate USD 775 CS-Cart + YOUPI USD 545 Multi-Vendor Ultimate USD 7500 (6000)
Posted 19 August 2019 - 12:02 AM #5
@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
Posted 19 August 2019 - 06:28 AM #6
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
CS-Cart USD 345 Multi-Vendor USD 1250 Multi-Vendor PLUS USD 3100 (2775)
CS-Cart Ultimate USD 775 CS-Cart + YOUPI USD 545 Multi-Vendor Ultimate USD 7500 (6000)