Okay, so I've been struggling to get my added fields to post into my data base. I've tried a bunch of different things with this entire post and nothing... before I post my code this is what I'm trying to accomplish:
Need to add 4 fields onto the checkout payment page to take in customer specific information for their order, in my case it's flight information.
Now, heres exactly what I've done following the original instructions provided:
If its the payment page, then edit tpl_checkout_payment_default.php in the same folder. Here you just need to add the field.
The field needs to be as follows:
<?php echo zen_draw_input_field('frequent_code'); ?>
My Code on tpl_checkout_payment_default.php
Code:
<fieldset>
<legend><?php echo TABLE_HEADING_FLIGHT_INGO; ?></legend>
<div><?php echo TEXT_FLIGHT_INFO;?></div><br />
<?php echo TEXT_FLIGHT_AIRLINE;?><?php echo zen_draw_input_field('flight_airline'); ?><br />
<?php echo TEXT_FLIGHT_NUMBER;?><?php echo zen_draw_input_field('flight_num'); ?><br />
<?php echo TEXT_FLIGHT_ARV;?><?php echo zen_draw_input_field('flight_arv'); ?><?php echo TEXT_FLIGHT_EX_ARV;?><br />
<?php echo TEXT_FLIGHT_DEP;?><?php echo zen_draw_input_field('flight_dep'); ?><?php echo TEXT_FLIGHT_EX_ARV;?>
</div>
</fieldset>
Firstly, you need to add a new column to the orders database table. Use phpmyadmin, and navigate to the table. Add a new column called order_frequent_code.
Added columns to database:
order_flight_airline
order_flight_num
order_flight_arv
order_flight_dep
Next, alter the order.php class file, found in includes/classes/order.php
There are a fair number of bits to add, but bare with me:
Line 43, add order_frequent_code, to the sql statement.
My Code added to order.php
Code:
$order_query = "... order_flight_airline, order_flight_num, order_flight_arv, order_flight_dep, ...
Line 114, before 'ip_address' insert the following line:
'frequent_code' => $order->fields['order_frequent_code'],
My Code added
Code:
$this->info = array( ...
'flight_airline' => $order->fields['order_flight_airline'],
'flight_num' => $order->fields['order_flight_num'],
'flight_arv' => $order->fields['order_flight_arv'],
'flight_dep' => $order->fields['order_flight_dep'],
'ip_address' => $order->fields['ip_address']);
Line 343, before 'ip_address' insert the following line:
'frequent_code' => $_SESSION['frequent_code'],
My Code added
Code:
$this->info = array( ...
'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
'flight_airline' => $_SESSION['flight_airline'],
'flight_num' => $_SESSION['flight_num'],
'flight_arv' => $_SESSION['flight_arv'],
'flight_dep' => $_SESSION['flight_dep'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
Line 587, before 'ip_address', insert the following line:
'order_frequent_code' => $this->info['frequent_code'],
My Code added
Code:
$sql_data_array = array( ...
'order_flight_airline' => $this->info['flight_airline'],
'order_flight_num' => $this->info['flight_num'],
'order_flight_arv' => $this->info['flight_arv'],
'order_flight_dep' => $this->info['flight_dep'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']);
We now need to get the input and pass it to the order class.
If you placed the new field in the shipping page, then you need to edit includes/modules/pages/checkout_shipping/header_php.php
After line 116 add:
if (isset($_SESSION['frequent_code'])) {
$frequent_code = $_SESSION['frequent_code'];
}
My Code added on includes/modules/pages/checkout_payment/header_php.php
Code:
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
if (isset($_SESSION['flight_airline'])) {
$flight_airline = $_SESSION['flight_airline'];
}
if (isset($_SESSION['flight_num'])) {
$flight_num = $_SESSION['flight_num'];
}
if (isset($_SESSION['flight_arv'])) {
$flight_arv = $_SESSION['flight_arv'];
}
if (isset($_SESSION['flight_dep'])) {
$flight_dep = $_SESSION['flight_dep'];
}
After line 124, which starts $comments = $_SESS........ add
if (zen_not_null($_POST['frequent_code'])) {
$_SESSION['frequent_code'] = zen_db_prepare_input($_POST['frequent_code']);
}
$frequent_code = $_SESSION['frequent_code'];
My Code added
Code:
// $_SESSION['comments'] = '';
$comments = $_SESSION['comments'];
if (zen_not_null($_POST['flight_airline'])) {
$_SESSION['flight_airline'] = zen_db_prepare_input($_POST['flight_airline']);
}
$flight_airline = $_SESSION['flight_airline'];
if (zen_not_null($_POST['flight_num'])) {
$_SESSION['flight_num'] = zen_db_prepare_input($_POST['flight_num']);
}
$flight_num = $_SESSION['flight_num'];
if (zen_not_null($_POST['flight_arv'])) {
$_SESSION['flight_arv'] = zen_db_prepare_input($_POST['flight_arv']);
}
$flight_arv = $_SESSION['flight_arv'];
if (zen_not_null($_POST['flight_dep'])) {
$_SESSION['flight_dep'] = zen_db_prepare_input($_POST['flight_dep']);
}
$flight_dep = $_SESSION['flight_dep'];
$total_weight = $_SESSION['cart']->show_weight();
$total_count = $_SESSION['cart']->count_contents();
// load all enabled payment modules
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());
So, I have done all that those instructions stated and it wont populate in my database. I've tried tweaking a few things, but nothing seems to be working...
Please help!
Bookmarks