Results 1 to 4 of 4
  1. #1

    red flag added a checkbox ...HELP

    Zen 1.3.7 php5.2.5 Mysql4
    I have added a checkbox to my checkout pages.
    The idea is to offer the choice of agreeing to accept substitutes if something is out of stock.
    It is called 'sub', and goes through from shipping,
    Code for shipping header***********************************************************
    if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
    if (zen_not_null($_POST['sub'])) {
    $_SESSION['sub'] = zen_db_prepare_input($_POST['sub']);
    }
    $sub = $_SESSION['sub'];

    to payment.
    Code for payment header******************************************************
    $sub = $_SESSION['sub'];
    ******************************************************************************** ***

    At the checkout confirmation page, in the header I want the 0 or 1 of the
    checkbox converted to text, so it appears on the confirmation page as Yes or No.

    Code for header checkout confirmation..*********************************************************.
    if ($_SESSION['sub'] == '1')
    $_SESSION['substitutes'] = 'Yes';
    else
    $_SESSION['substitutes'] ='No';
    $substitutes=$_SESSION['substitutes'] ;
    $_SESSION['substitutes'] = zen_db_prepare_input($_POST['substitutes']);
    ******************************************************************************** *************************
    That is parsed through ok to the confirmation tpl and appears as planned.

    Code for checkout confirmation tpl**************************************************************
    <?php echo '&nbsp;&nbsp;'. $substitutes . zen_draw_hidden_field('substitutes', $order->info['substitutes']); ?>

    OK that works alright.
    My problem lies in getting it inserted into the database. I've made a new text field called substitutes in
    TABLE orders_status_history, next to comments.

    I've added to classes/orders.php, as below
    'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
    'substitutes' => (isset($_SESSION['substitutes']) ? $_SESSION['substitutes'] : '')

    And unset the session in checkout success header.

    It works fine with php4, but since i've gone with php 5.2.5, I am getting the comments inserted ok, but the
    substitutes is blank. There is no error or crash.
    Can anyone please help me with this ?
    http://thebeadman.com.au
    Cheers
    Emmdee
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

    Default Re: added a checkbox ...HELP

    I think there may be a slight problem with your coding of this line:

    if ($_SESSION['sub'] == '1')
    $_SESSION['substitutes'] = 'Yes';
    else
    $_SESSION['substitutes'] ='No';
    $substitutes=$_SESSION['substitutes'] ;
    $_SESSION['substitutes'] = zen_db_prepare_input($_POST['substitutes']);

    Here you set the $_SESSION value to yes or no, which is fine, but then on the next line, you then take a posted value and over-write these values. Why is this?

    The other thing I would recommend, is that you change the database column from a TEXT column to a CHAR(1) column, and set the default to N. You can then insert 1 letter into this column, rather than Yes / No. This will have a few effects on your store. Firstly, it will reduce the size of your database, as the column is a single character, rahter than allowing space for text. Secondly, it will be quicker to search as you are looking in a character column for either Y or N. Thirdly, all orders will either have a Y or N, rather than Yes No or blank.

    The problem you are getting with MySQL 5 doesn't sound like it is MySQL 5 specific. If it was, then the entire record would normally fail, rather than just inserting the comments. It sounds like the session value is not being inserted correctly.

    Absolute

  3. #3

    red flag Re: added a checkbox ...HELP

    Hello Absolute

    Your answer is Absolutely spot on and much appreciated,,,yes it was the post that was the prob and I thank you very much.
    Actually in the db i will use varchar cause i like Yes or No better than Y or N...also looks better on emails...once again thanks
    emmdee
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

    Default Re: added a checkbox ...HELP

    That is good news. The reason for using single CHAR values, rather than varchars, is firstly, they take up more space in your dataqbase, which if you have a large store, will increase the size of the actual database files unnecessarily. Also, we use the same type of fields on a number of stores, some of which are multi-lingual. It is then far easier to use something like constant('TEXT_RESPONSE_'.$database_record) to return the relevant message from the file, than worry about case sensitivity.

    Everyone has their own style, and what works best for them, however, I thought I'd give a reason as to my chosen method of database alteration.

    Absolute

 

 

Similar Threads

  1. v150 Help adding an "Opt Out" checkbox to Shipping Page for Checkout Process
    By RobertH in forum Addon Shipping Modules
    Replies: 4
    Last Post: 24 Mar 2016, 05:02 PM
  2. No Tax Added When New Country Added to Zone
    By mach9 in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 0
    Last Post: 30 Sep 2010, 10:42 AM
  3. Need help moving checkbox attributes
    By modeltruckin56 in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 14 Dec 2009, 08:08 PM
  4. Added new product and extra images were added with it? (not wanted)
    By bakdoor in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 2 Nov 2008, 10:31 AM
  5. HELP!! All States added to order
    By smalltownpets in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 17 Sep 2006, 11:41 PM

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