Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Nov 2007
    Posts
    141
    Plugin Contributions
    0

    Default Age Verification or Restriction

    One of the products I sell contains alcohol (whiskey cake). I want to "verify" the customers age before they purchase this item. I do not want to ask every customer for their age so I disabled the DOB feature in admin. Of course there is no fool proof method, but I would at least like a record of their birth date.

    I added the following code to tpl_product_info_display.php to show the DOB input field. It only shows on products_id 202 (whiskey cake).

    <!--bof Age Verification -->
    <?php
    if ($_GET['products_id'] == "202") {
    ?>
    <fieldset>
    <legend ><?php echo TABLE_HEADING_DATE_OF_BIRTH; ?></legend>
    <label class="inputLabel" for="dob"><?php echo ENTRY_DATE_OF_BIRTH; ?></label>
    <label class="inputLabel"><?php echo zen_draw_input_field('dob','', 'id="dob"') . (zen_not_null(ENTRY_DATE_OF_BIRTH_TEXT) ? '<br/><span class="alert">' . ENTRY_DATE_OF_BIRTH_TEXT . '</span>': ''); ?></label>
    <br class="clearBoth" />
    <label class="notice"><?php echo TEXT_AGE_VERIFY; ?></label>
    <br class="clearBoth" />
    </fieldset>
    <?php
    }
    ?>
    <!--eof Age Verification-->

    The next step is to check the DOB and verify that it is (1) a real date and (2) the date entered meets the criteria of 21 years of age. I found this bit of code in the tutorials "How can I limit the age of my customers to people over 18?" and modified it below.

    if (ENTRY_DOB_MIN_LENGTH > 0 or !empty($_POST['dob'])) {
    if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false) {
    $error = true;
    $messageStack->add('create_account', ENTRY_DATE_OF_BIRTH_ERROR);
    }
    $minimum_age = 18;
    $acceptable_dob = (date('Y') - $minimum_age) . date('md');
    if (zen_date_raw($dob) > $acceptable_dob) {
    $error = true;
    $messageStack->add('create_account', ENTRY_DATE_OF_BIRTH_UNDERAGE);
    }
    }

    I don't know if the above code will work or where to insert this code. I would like the customer to stay on the whiskey cake page, receive an error message if they are under 21 and not be able to add the cake to the shopping cart.

    I have a second problem if the item is added to the shopping cart and the customer wants to return to the whiskey cake page using the product ink, a bunch on characters are added to the products_id and the above "if" statement fails. How can I only check the first 3 characters of the products_id?

    Thx Sweet

  2. #2
    Join Date
    Nov 2007
    Posts
    141
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    It think when the "add-to-cart" button is clicked, the code in includes/classes/shopping_cart.php is run. I copied a small section below, function "actionAddProduct", which seems to check for errors on the product_info page.

    /**
    * Method to handle cart Action - add product
    *
    * @param string forward destination
    * @param url parameters
    */
    function actionAddProduct($goto, $parameters) {
    global $messageStack, $db;
    if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
    // verify attributes and quantity first
    $the_list = '';
    $adjust_max= 'false';
    if (isset($_POST['id'])) {
    foreach ($_POST['id'] as $key => $value) {
    $check = zen_get_attributes_valid($_POST['products_id'], $key, $value);
    if ($check == false) {
    $the_list .= TEXT_ERROR_OPTION_FOR . '<span class="alertBlack">' . zen_options_name($key) . '</span>' . '<br />';
    }
    }
    }
    // verify qty to add


    If I add my below code to check the date-of-birth inside this function, the DOB error message will not show up unless there is another error on the product_page. I think I'm close, but could use a little help.


    // verify dob
    if ($_GET['products_id'] == "202") {
    $error = false;
    if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false) {
    $error = true;
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_ERROR);
    }
    $minimum_age = 21;
    $acceptable_dob = (date('Y') - $minimum_age) . date('md');
    if (zen_date_raw($dob) > $acceptable_dob) {
    $error = true;
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_UNDERAGE);
    }
    }

    Thx Sweet

  3. #3
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,263
    Plugin Contributions
    3

    Default Re: Age Verification or Restriction

    Hello sweet

    If you put the whiskey in the cake BEFORE it is baked, there will be no alcohol in the cake - just whiskey flavour. Alcohol evaporates at 80 deg.c . If you're pouring whiskey over the cake AFTER it is baked, then there will be a little residual alcohol after a day or two, but within a week, most of it's evaporated.
    20 years a Zencart User

  4. #4
    Join Date
    Nov 2007
    Posts
    141
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    schoolboy, thanks for the comment! If you check out this website http://en.wikipedia.org/wiki/Cooking_with_alcohol a bunch of smart people did a study and found alcohol stays in the food even after cooking.

    I discussed this issue with a local baker and she had checked with our state government department of health. She was told the same thing you stated above "if you cook with it don't worry about it".

    Although it would be MUCH easier to ignore this issue and avoid this latest coding task (with help from the forum members of course!), I think it would be safer to sell this product only to those over the age of 21. I can imagine some underage kid eating our cake and then have an accident of some kind. It wouldn't matter if they ate 1 piece or the whole thing. Plus, from experience, this cake packs a punch

    Thx Sweet

  5. #5
    Join Date
    Nov 2007
    Posts
    141
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    I now have working code for the age verification check. If a date is entered in the wrong format the ERROR text is displayed; if a date is entered under the 21 year age limit the UNDERAGE text is displayed; if a date is entered that is over the 21 year age limit no text is displayed.


    // verify dob
    if ($_GET['products_id'] == "202") {
    $dob = (empty($_POST['dob']) ? zen_db_prepare_input('0001-01-01 00:00:00') : zen_db_prepare_input($_POST['dob']));
    if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false) {
    $error = true;
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_ERROR);
    }
    $minimum_age = 21;
    $acceptable_dob = (date('Y') - $minimum_age) . date('md');
    if (zen_date_raw($dob) > $acceptable_dob) {
    $error = true;
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_UNDERAGE);
    }
    }

    But, I haven't figured out where to insert this code in the includes/classes/shopping_cart.php file. I am pretty sure it needs to go in the function actionAddProduct section. Any help would be welcome.

    Thx Sweet

  6. #6
    Join Date
    Nov 2007
    Posts
    141
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    I added the following code at the beginning of the function actionAddProduct section.

    /**
    * Method to handle cart Action - add product
    *
    * @param string forward destination
    * @param url parameters
    */
    function actionAddProduct($goto, $parameters) {
    global $messageStack, $db;

    // verify dob
    if ($_GET['products_id'] == "202") {
    $error='false';
    $dob = (empty($_POST['dob']) ? zen_db_prepare_input('0001-01-01 00:00:00') : zen_db_prepare_input($_POST['dob']));
    if (substr_count($dob,'/') > 2 || checkdate((int)substr(zen_date_raw($dob), 4, 2), (int)substr(zen_date_raw($dob), 6, 2), (int)substr(zen_date_raw($dob), 0, 4)) == false)
    {
    $error='true';
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_ERROR);
    }
    $minimum_age = 21;
    $acceptable_dob = (date('Y') - $minimum_age) . date('md');
    if (zen_date_raw($dob) > $acceptable_dob)
    {
    $error='true';
    $messageStack->add('product_info', ENTRY_DATE_OF_BIRTH_UNDERAGE);
    }
    }

    I added the following bit of code at the end of the function actionAddProduct section to keep the customer on the product_info page if they entered an underage date.

    if ($the_list == '') {
    // no errors
    // display message if all is good and not on shopping_cart page
    if (DISPLAY_CART == 'false' && $_GET['main_page'] != FILENAME_SHOPPING_CART) {
    $messageStack->add_session('header', SUCCESS_ADDED_TO_CART_PRODUCT, 'success');
    }
    if ($error == 'false')
    {
    zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
    }
    } else {
    // errors - display popup message
    }
    }

    I still need to figure out how to truncate the "products_id" to 3 characters so if a customer returns from the shopping cart, this statement will work.

    if ($_GET['products_id'] == "202")

    Thx Sweet

  7. #7
    Join Date
    Mar 2009
    Posts
    3
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    what would i have to change in this cade if i wanted to make it for a whole catagory in my shop?

  8. #8

    Default Re: Age Verification or Restriction

    Quote Originally Posted by blown57 View Post
    what would i have to change in this cade if i wanted to make it for a whole catagory in my shop?

    I second this... I would love to have the ability to verify age when going into a specific category..
    "Only a fool states he can not learn something new everyday"

  9. #9

    Default Re: Age Verification or Restriction

    I need to limit a category to 18 or over, too.
    Beau

  10. #10
    Join Date
    Oct 2004
    Posts
    1,045
    Plugin Contributions
    0

    Default Re: Age Verification or Restriction

    I would like to do this as well, was anyone able to make this work to restrict an entire category?
    Danielle

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Age restriction
    By dereck72 in forum General Questions
    Replies: 5
    Last Post: 20 Dec 2013, 04:25 PM
  2. v150 Age verification and restriction
    By clint6998 in forum General Questions
    Replies: 1
    Last Post: 27 Feb 2013, 09:57 PM
  3. Age Restriction
    By darkmarauder in forum Managing Customers and Orders
    Replies: 2
    Last Post: 20 Sep 2010, 12:18 PM
  4. Age Verification
    By signs in forum General Questions
    Replies: 0
    Last Post: 12 Jul 2009, 04:08 AM
  5. Age Restriction...
    By Alex Clarke in forum General Questions
    Replies: 7
    Last Post: 16 Oct 2008, 12:34 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