Page 8 of 9 FirstFirst ... 6789 LastLast
Results 71 to 80 of 84
  1. #71
    Join Date
    Jul 2009
    Posts
    495
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    Quote Originally Posted by Absolute View Post
    There are a couple of ways you can achieve this. Firstly, do you offer frequent buyer discount? If so, the best thing to do is to create a new order_total module, which checks the card validity, and if valid, gives a discount. But thats another topic, related, but different.

    Ok, so adding the fields to the checkout.

    BACKUP EVERYTHING BEFORE EDITTING ANY OF THESE FILES

    Firstly, you need to decide which page you are going to add the field to. If its the shipping page, then edit includes/templates/YOUR ACTIVE TEMPLATE/templates/tpl_checkout_shipping_default.php . 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'); ?>

    Next is the difficult bit.

    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.

    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.

    Line 114, before 'ip_address' insert the following line:
    'frequent_code' => $order->fields['order_frequent_code'],

    Line 343, before 'ip_address' insert the following line:
    'frequent_code' => $_SESSION['frequent_code'],

    Line 587, before 'ip_address', insert the following line:
    'order_frequent_code' => $this->info['frequent_code'],

    Ok, nearly there. So far, we've added the field to the template, added the column to the database, and editted the order class to record the value. We now need to get the input and pass it to the order class.


    All you need to do now is work out how to display the extra information where you need it. If you want it on the orders page in the admin, then you will need to edit admin/orders.php as a starter.

    Good luck and hope it helps

    Absolute
    PS - I have used this before, but just to let you know its not a direct copy and paste, so I may have missed a ';' or two. If you have any issues, let me know
    hey there, right iv copied the steps up to the end of "order class"
    the box i required is now showing on the "checkout_payment" page
    but it is not showing on the order confirmation.....how do i get this data to be sent to me via the email....


    also, how do i make it so that this field HAS to be filled to complete the order?
    i may not know how yet, but i soon will....i hope :)

  2. #72
    Join Date
    Jul 2009
    Posts
    495
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    ok well iv set it up exactly as mentioned, but i still cant seem to get it to show on the order confirmation page or the email


    PLEASE HELP MEEEEE!!!
    i may not know how yet, but i soon will....i hope :)

  3. #73
    Join Date
    Jul 2009
    Posts
    495
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    Quote Originally Posted by eddyboy View Post
    Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou Thankyou


    My way did seem to work, but I dont trust my coding on 0 sleep..
    i have used the new code and it works perfectly
    tried using this to make the field REQUIRED
    Code:
    if (isset($_POST['frequent_code']) && !zen_not_null($_POST['frequent_code'])) {  //perform ALL checks on relevancy here
        $messageStack->add_session($_GET['main_page'], TEXT_ERROR_VARIABLE_MISSING, 'error');
        zen_redirect(zen_href_link($_GET['main_page']));
      }
    if (zen_not_null($_POST['frequent_code'])) {
    $_SESSION['frequent_code'] = zen_db_prepare_input($_POST['frequent_code']);
    }
    $frequent_code = $_SESSION['frequent_code'];
    please tell me if this is wrong??
    because it dont seem to make the field required :S
    i may not know how yet, but i soon will....i hope :)

  4. #74
    Join Date
    May 2005
    Location
    Bath, Somerset
    Posts
    1,053
    Plugin Contributions
    3

    Default Re: Adding Field to Checkout

    It's really very hard to advise you as to what you've missed, without actually seeing the code, but things to check are that you have changed all the "frequent_code" references to the name of the variable you are actually using.

    With the order confirmation page, you will need to add this variable to the header_php.php file, or the template file, where the order is looked up within the database.

    And finally, within the Order class, you'll find the send email function, where the body of the email is built. You'll need to either tack this varialbe onto the end of the message body, or create a new tag within the email template, and then assign the varialbe to the HTML_MSG array as required.

    Good luck,
    Absolute
    Back, after a 4 year absence! Did you miss me?
    Absolute Web Solutions Ltd
    Interested in our work? Take a look at one of our sites - The Tech Store

  5. #75
    Join Date
    Jul 2009
    Posts
    495
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    Quote Originally Posted by Absolute View Post
    It's really very hard to advise you as to what you've missed, without actually seeing the code, but things to check are that you have changed all the "frequent_code" references to the name of the variable you are actually using.

    With the order confirmation page, you will need to add this variable to the header_php.php file, or the template file, where the order is looked up within the database.

    And finally, within the Order class, you'll find the send email function, where the body of the email is built. You'll need to either tack this varialbe onto the end of the message body, or create a new tag within the email template, and then assign the varialbe to the HTML_MSG array as required.

    Good luck,
    Absolute
    lol that confused me

    1. Yeah im using frequent_code as my reference

    2. which variable to the header_php.php??

    3. again which variable lol.

    complete noob with php
    i may not know how yet, but i soon will....i hope :)

  6. #76
    Join Date
    Sep 2010
    Posts
    4
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    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!

  7. #77
    Join Date
    Jul 2009
    Posts
    495
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    hi there
    iv managed to get it to show on the orders etc(not the emails yet)

    but im just wondering, how do i make it so that the "last" entry put into that box by the customer is forgotten...asin goes to that page and the box is blank again....

    thanks in advance
    i may not know how yet, but i soon will....i hope :)

  8. #78
    Join Date
    Feb 2012
    Posts
    4
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    how did you make it work?
    I am really trying my best and can't figure a way to make the form submit data to db. It probably has to do with the fact that I have 1.5 zen cart?
    Also how can I name it on the checkout page? I only see the field.
    Sorry for noob questions.

  9. #79
    Join Date
    Jun 2013
    Posts
    47
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    the code below only works on checkout_shipping, i get the $my_code value written to database when an order completed
    but when i tried the same code to checkout_confirmation, nothing written to database
    any ideas?

    i'm using zen cart 1.51

    PHP Code:
    <?php 

    //File checkout_shipping/header_php.php
    if (isset($_SESSION['my_code'])) {
    $my_code $_SESSION['my_code'];
    }
    if (
    zen_not_null($_POST['my_code'])) {
    $_SESSION['my_code'] = zen_db_prepare_input($_POST['my_code']);
    }
    $my_code $_SESSION['my_code'];


    //File tpl_checkout_shipping_default.php
    $my_code something;
    echo 
    zen_draw_input_field('my_code'$my_code$parameters 'readonly'$type 'text');

    ?>

  10. #80
    Join Date
    Jun 2013
    Posts
    47
    Plugin Contributions
    0

    Default Re: Adding Field to Checkout

    the same code works on checkout_shipping and checkout_payment page
    but it doesn't work on checkout_confirmation page
    what do i use it for checkout confirmation?


    Quote Originally Posted by xav2 View Post
    the code below only works on checkout_shipping, i get the $my_code value written to database when an order completed
    but when i tried the same code to checkout_confirmation, nothing written to database
    any ideas?

    i'm using zen cart 1.51

    PHP Code:
    <?php 

    //File checkout_shipping/header_php.php
    if (isset($_SESSION['my_code'])) {
    $my_code $_SESSION['my_code'];
    }
    if (
    zen_not_null($_POST['my_code'])) {
    $_SESSION['my_code'] = zen_db_prepare_input($_POST['my_code']);
    }
    $my_code $_SESSION['my_code'];


    //File tpl_checkout_shipping_default.php
    $my_code something;
    echo 
    zen_draw_input_field('my_code'$my_code$parameters 'readonly'$type 'text');

    ?>

 

 
Page 8 of 9 FirstFirst ... 6789 LastLast

Similar Threads

  1. v151 Adding custom field during checkout
    By hues in forum General Questions
    Replies: 1
    Last Post: 9 Nov 2012, 10:39 PM
  2. Adding Field to Checkout
    By earlygrayte in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 17 Feb 2012, 03:00 PM
  3. Adding select field to checkout
    By ETbyrne in forum Managing Customers and Orders
    Replies: 1
    Last Post: 22 Aug 2008, 02:34 AM
  4. adding a field to checkout and db
    By StevenB in forum General Questions
    Replies: 0
    Last Post: 20 May 2007, 12:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR