Jump to content
AleShey

PHP age restriction on creating account PrestaShop 1.7.6.2

Recommended Posts

Hi everyone, I'm finding some difficulties on making a restricted registration for user under 18 on an ecommerce. Problem is that PS 1.7's architecture has changed from 1.6 so all the solutions I've found are not working. For example I tried to replace  the function isBirthDate with the following (found in a topic on this forum): 

public static function isBirthDate($date, $format = 'Y-m-d')
{
if (empty($date) || $date == '0000-00-00')
return false;
if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
{
   if ((floor((time() - strtotime($date))/31556926))<18)
       return false;  
if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
return false;
return true;
}
return false;
}

I also tried to integrate it with the existing code but, even tho apparently it was working , I can't understand if it really checks the age now but apparently it completely breaks the format and doesn't recognize it anymore, cause even if I put the right converted format DD/MM/YYYY or any kind of format it gives me an error which states that the format is wrong.

Now this is the "stock" code of the function:

public static function isBirthDate($date, $format = 'Y-m-d')
    {
        if (empty($date) || $date == '0000-00-00') {
            return true;
        }

        $d = DateTime::createFromFormat($format, $date);
        if (!empty(DateTime::getLastErrors()['warning_count']) || false === $d) {
            return false;
        }

        return $d->getTimestamp() <= time();
    }

I'd also like to know if that "return true" is right or not. Cause I think it should return false for that condition.

TL;DR: I can't find a way to make age restricted registration in a prestashop ecommerce 1.7.6.2 via php ( so no modules/addon to buy). I tried old solutions but obviously they won't work.

Thanks for your attention.

Edited by AleShey (see edit history)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More