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.