Zen Cart Logo
Forums / General Questions / Writing extra order info to the db

Writing extra order info to the db

Views: 1,896

Results 1 to 20 of 26
6 Sep 2012, 3:02 PM
#1
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Writing extra order info to the db

I am making a custom change to the order confirmation page, and I need to modify the sql that writes the order to the database, I assume it comes after the order confirmation page, but i cant find the actual SQL.
Thanks in advance
Jeff

6 Sep 2012, 3:16 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: Writing extra order info to the db

That task occurs during the checkout_process page's processing ...

6 Sep 2012, 4:34 PM
#3
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

I need to know specifically where i can find the sql statement.
Thanks.

6 Sep 2012, 6:24 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: Writing extra order info to the db

Look at /includes/classes/order.php; one of its member functions performs the database update.

6 Sep 2012, 6:55 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Writing extra order info to the db

NOTE: You should be using notifier+observer calls to do additional database queries, instead of changing core code.

11 Sep 2012, 6:05 PM
#6
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

Thanks doc, im looking onto that now :D
I've made some changes to payment confirmation page, i want to append some stuff into the comments section of the order.

11 Sep 2012, 6:18 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Writing extra order info to the db

If you wanted to add another comment record, you could do that using the NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_COMMENT notifier hook.

Or if you absolutely need to inject custom stuff into the first comment (the only customer's comment line), then you could hook NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_HEADER and append your special extra text onto the $class->info['comments'] variable, which corresponds with the order class's $this->info['comments']

11 Sep 2012, 9:19 PM
#8
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

Good god thank you! I was headed in the wrong direction lol

11 Sep 2012, 11:25 PM
#10
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

DrByte:

Or if you absolutely need to inject custom stuff into the first comment (the only customer's comment line), then you could hook NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_HEADER and append your special extra text onto the $class->info['comments'] variable, which corresponds with the order class's $this->info['comments']
This will fire when the confirm order button is press?
As I said, I modified the confirm order (step 3 in the checkout process), I have a small javascript so they can select option of options lol.
The confirm order button will be disabled until they select them. Since it is just a bunch of text boxes, I want to put them in an array, save them to the comments, and send them with the email.
Easy nough, eh. lol
Thanks again for your guidance.
Jeff

13 Sep 2012, 8:00 PM
#11
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

Ok, using your tutorial above I created the 2 files:
/includes/classes/observers/class.append_decals_to_comments.php

<?php
/**
 * Observer class for adding decal info to comments
 */
class append_decals_to_comments extends base {

  function __construct() 
  {
    global $zco_notifier;
    $zco_notifier->attach($this, array('NOTIFY_ORDER_DURING_CREATE_ADDED_ORDER_HEADER'));
  }

 function update(&$class, $eventID, $paramsArray = array())
  {
	 //$class->info['comments']="test for comments write"; 
  }
}

/includes/auto_loaders/config.append_decals_to_comments.php

<?php
if (!defined('IS_ADMIN_FLAG')) {

 die('Illegal Access');

}
$autoLoadConfig[190][] = array('autoType'=>'class',
                              'loadFile'=>'observers/class.append_decals_to_comments.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                              'className'=>'class.append_decals_to_comments',
                              'objectName'=>'class.append_decals_to_comments');
							 

however it bombs with a 500 error; i just want to test it working before i get the info for it.
Any suggestions would be appreciated :D
Jeff

13 Sep 2012, 8:18 PM
#12
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: Writing extra order info to the db

First, check your /cache folder for Debug*.log files; otherwise, edit /includes/application_top.php (line 75 for v1.5.0) and change the define for DEBUG_AUTOLOAD to true. The auto-load process will then print out its progress ...

13 Sep 2012, 8:41 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Writing extra order info to the db

jeffiec:

$autoLoadConfig[190][] = array('autoType'=>'class',
'loadFile'=>'observers/class.append_decals_to_comments.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
'className'=>'[strike][B]class.[/B][/strike]append_decals_to_comments',
'objectName'=>'[strike][B]class.[/B][/strike]append_decals_to_comments');

the className and objectName need to match the class declaration you made in the observer class. 
While the FILENAME may have "class." at the beginning, the name of the class inside that file is just append_decals_to_comments
13 Sep 2012, 9:07 PM
#14
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

Thank you, this was now easier than I thought it would be :D

13 Sep 2012, 10:46 PM
#15
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

well, now comes the hard part, lol
everything works great, i can write to the comments,
now im trying to get the value of the 12 text boxes,
it appears that the $_POST is not available, here is what i tried:

for ($i=0; $i<12; $i++) {
        $tboxv=$_POST['acl'.$i];
	if ($tboxv != 0) {
		$fortnot[$i] = $cliparray[$i] . " X " . $tboxv;
	}
}
$tarray='<pre>'.print_r($fortnot, true).'</pre>';
$class->info['comments']=$tarray; 

but nothing shows up in comments,
$class->info['comments']="test for comments write"; worked, so i know it will write to it.
how can i loop through the 12 textboxes and put the ones that dont = 0 into the array?
Thanks 1 million times for your help.
Jeff

13 Sep 2012, 10:50 PM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Writing extra order info to the db

if you echo print_r($_POST, true), what do you get?

In fact, you could append print_r($_POST, true) to your comments, to see what's in the POST array.

13 Sep 2012, 10:59 PM
#17
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

i show globals in the footer while im writing anyway, and the checkout success page shows:
Array
(
[GLOBALS] => Array
RECURSION
[_POST] => Array
(
)

13 Sep 2012, 11:03 PM
#18
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

In fact, you could append print_r($_POST, true) to your comments, to see what's in the POST array.

Array
(
[securityToken] => 5f148e7683dbb32a6a429f3c0204cebf
[btn_submit_x] => 32
[btn_submit_y] => 17
)

14 Sep 2012, 1:00 AM
#19
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Writing extra order info to the db

ok, working my way through this, found out my textboxes weren't in the form tag :(
Now my issue is that in my javascript, i set the textbox to disabled after it has been added to the array, so when the form posts, i'm guessing its not picking up values from "disabled" text boxes.
is there a better way?
Thanks in advance
Jeff

14 Sep 2012, 1:44 AM
#20
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Writing extra order info to the db

type="hidden" will POST