Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Where To Store Custom Data, That Is Related To Order? Rate Topic   - - - - -

 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 27 posts

Posted 25 March 2014 - 01:10 PM #1

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.
European e-commerce experts: www.arteverumstudio.com

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19057 posts

Posted 25 March 2014 - 01:21 PM #2

@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

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Zahhar
  • Junior Member
  • Members
  • Join Date: 01-Nov 08
  • 27 posts

Posted 25 March 2014 - 02:27 PM #3

Thanks, I will try this approach.
European e-commerce experts: www.arteverumstudio.com

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19057 posts

Posted 25 March 2014 - 02:51 PM #4

@Zahhar,

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

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.