Forums / General Questions / Age Verification or Restriction

Age Verification or Restriction

Locked

Views: 17,396

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
28 Jan 2008, 4:19 AM
#1
sweet_zouzou avatar

sweet_zouzou

Zen Follower

Join Date:
Nov 2007
Posts:
138
Plugin Contributions:
0

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

28 Jan 2008, 7:35 PM
#2
sweet_zouzou avatar

sweet_zouzou

Zen Follower

Join Date:
Nov 2007
Posts:
138
Plugin Contributions:
0

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

28 Jan 2008, 7:47 PM
#3
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

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

28 Jan 2008, 9:02 PM
#4
sweet_zouzou avatar

sweet_zouzou

Zen Follower

Join Date:
Nov 2007
Posts:
138
Plugin Contributions:
0

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 :smile:

Thx Sweet

29 Jan 2008, 1:36 AM
#5
sweet_zouzou avatar

sweet_zouzou

Zen Follower

Join Date:
Nov 2007
Posts:
138
Plugin Contributions:
0

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

29 Jan 2008, 10:39 PM
#6
sweet_zouzou avatar

sweet_zouzou

Zen Follower

Join Date:
Nov 2007
Posts:
138
Plugin Contributions:
0

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

30 Mar 2009, 11:25 AM
#7
blown57 avatar

blown57

New Zenner

Join Date:
Mar 2009
Posts:
3
Plugin Contributions:
0

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?

29 Mar 2010, 2:32 AM
#8
carstickersdecals avatar

carstickersdecals

New Zenner

Join Date:
Mar 2010
Posts:
22
Plugin Contributions:
0

Re: Age Verification or Restriction

blown57:

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"

14 Apr 2010, 8:06 PM
#9
beau91324 avatar

beau91324

Zen Follower

Join Date:
Jul 2009
Posts:
149
Plugin Contributions:
0

Re: Age Verification or Restriction

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

Beau

30 Sep 2010, 12:02 AM
#10
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

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

30 Sep 2010, 12:15 AM
#11
beau91324 avatar

beau91324

Zen Follower

Join Date:
Jul 2009
Posts:
149
Plugin Contributions:
0

Re: Age Verification or Restriction

Yes, I have but I haven't posted the code yet. Do you want to do an age restriction?

Beau

30 Sep 2010, 12:18 AM
#12
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Age Verification or Restriction

Yes, if you would consider sharing I would be so grateful!

Danielle

30 Sep 2010, 4:42 PM
#13
beau91324 avatar

beau91324

Zen Follower

Join Date:
Jul 2009
Posts:
149
Plugin Contributions:
0

Re: Age Verification or Restriction

I have no problem sharing if your willing to wait a few days till I find time to gather everything together & write some instructions. :yes:

Beau

30 Sep 2010, 5:32 PM
#14
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Age Verification or Restriction

Sure, no problem. Thank you so much!

Danielle

8 Oct 2010, 10:52 PM
#15
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Age Verification or Restriction

Hi there, I was just wondering if you had any chance to look at this yet? I probably don't really need any instructions, just the file edits :)

Thanks!

Beau91324:

I have no problem sharing if your willing to wait a few days till I find time to gather everything together & write some instructions. :yes:

Danielle

10 Nov 2010, 8:46 AM
#16
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Age Verification or Restriction

Beau91324:

I have no problem sharing if your willing to wait a few days till I find time to gather everything together & write some instructions. :yes:

would love this age restriction thing
as my supplier sells machete's and in the uk u need to be 18 to buy one...

if you can let me know, would be great :D

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