Disable underage to place any orders

  • Posts: 23
  • Thank you received: 1
10 years 6 months ago #156842

-- url of the page with the problem -- : www.genusskanzlei.at/shop
-- HikaShop version -- : 2.3.0
-- Joomla version -- : 3.2.3
-- PHP version -- : 5.4.24
-- Browser(s) name and version -- : XXXXX x.x.x
-- Error-message(debug-mod must be tuned on) -- : none

For the table "address" I have added a "Custom Field" named: "Birth date", which is a requirement. The reason is that we need to unable person under 18 years to place any order on the shop, since we also offer alcoholic beverage.

How could achieved this?

Or should we just not allow anybody under 18 year to register at all? How?

I think this should help me get the age:

function birthday($birthday) {
    $age = date_create($birthday)->diff(date_create('today'))->y;
      return $age;
}
If $age < 18 {
echo  JText::_('You_must_be_18_to_order');
return „home“??
}
I will appreciate all the help!

Thanks in advance for the help!

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 6 months ago #156865

Hi,

A simple solution would be to use a custom field of the type datepicker (available since the 2.3.1 version of HikaShop). It has advanced restriction settings which will allow you to restrict the selectable dates to only the days before the last 18 years and thus preventing underage users to register (unless the enter a fake birthday of course...)

Please Log in or Create an account to join the conversation.

  • Posts: 23
  • Thank you received: 1
10 years 6 months ago #157087

Hi!

I actually have the custom field of type datepicker. I don't see which is the "advanced restriction settings", but I gave unto "Default Value" a date and then set "Allow" to "Only past dates", as you can see in the picture. Then I've got next to date entry for "Default Value"

disableFunc: function(date) { var today=new Date(); 
today.setHours(23);today.setMinutes(59);today.setSeconds(59);today.setMilliseconds(99); if(date > today) { return true; } return false; }, // :

After that, I tried to save it and close and I've got the following error and everything was gone :-(
 0 DateTime::__construct(): Failed to parse time string (23.05.1996&quot;,disableFunc: function(date) { var today=new Date(); today.setHours(23);today.setMinutes(59);today.setSeconds(59);today.setMilliseconds(99); if(date &gt; today) { return true; } return false; }, //) at position 10 (&): Unexpected character

I have to remove the Custom fields and create a new one. However, every time I save the new one I get an error saying
Error
Please complete the Birthday field



I think this is not working right :-(

Any suggestions?

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
10 years 6 months ago #157101

Hi,

In all cases, you can't add javascript directly in the input field.
I'm not sure that this custom field handle the check for a minimum age. You will potentially have to create a plugin based on the function "onBeforeAddressCreate()", or "onBeforeAddressUpdate()" and make a check on the current date, the date set in the custom field to allow the registration or not.

So PHP knowledge are required.

Please Log in or Create an account to join the conversation.

  • Posts: 23
  • Thank you received: 1
10 years 6 months ago #157153

I didn't add the javascript.
After I input the date In the field and clicked save, this script showed up and there was no way to remove it. You can try recreate what I explain and see for yourself.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 5 months ago #157389

Hi,

With latest versions of Joomla 3.2 and Joomla 3.3, the date system of Joomla has changed and it breaks the compatibility (without any warning to the community)
So it is no longer possible to use date restriction with the simple date picker.
You have to use the dynamic date picker with HikaShop 2.3.1 or do not put the date restrictions.
The feature still work with Joomla 1.5, 2.5, 3.0 and 3.1 ; that's why we can't remove the option for the simple date picker.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum