Page 1 of 1

customer_id create account

Posted: Thu Dec 31, 2020 2:52 pm
by Mikepo
Hi,
I'm wanting to use the postAccountCreation hook in create_account.php, and utilise the customer_id. However the customer_id is part of the object class which is private.
How you I obtain the value for customer_id?

Re: customer_id create account

Posted: Fri Jan 01, 2021 10:31 am
by ecartz

Code: Select all

$GLOBALS['customer_data']->get('id', $GLOBALS['customer_details'])
Note that if you update to the latest version, you can use the postRegistration hook instead and schedule it after the customer ID is set on the customer object or the session.

Re: customer_id create account

Posted: Wed Jan 13, 2021 2:50 pm
by Mikepo
ok, using the postAccountCreation hook call defined in create_account.php in 1.0.7.11, I could use code to create an entry in the action_recorder table.
Now, in 1.0.7.12, postRegistration hook is added to replace postAccountCreation. I adjusted my hook accordlingly, but it does not seem to call the hook.
so I'm confused. What do I need to do to fix my existing hook?

Re: customer_id create account

Posted: Wed Jan 13, 2021 5:26 pm
by ecartz
My guess would be that you need to change the name so that the hook runs at the right time. I would have expected it to run after the customer_id is set automatically. Perhaps I should rename the redirect. But anyway, try a filename like _01a_anything.php -- don't forget to adjust the class name to match, which would include a double-underscore (one from the name and one as a separator from the group).

Re: customer_id create account

Posted: Thu Jan 14, 2021 10:25 am
by Mikepo
Thank you Matt, changing the file/class name as suggested worked. I'm not totally understanding why?
Prior to the file name change the hook wasn't being called, checked by using an alert box in script.
Any way, thanks again!

Re: customer_id create account

Posted: Thu Jan 14, 2021 11:24 am
by ecartz
ecartz :
Wed Jan 13, 2021 5:26 pm
Perhaps I should rename the redirect.
Hooks are sorted before running to give a consistent sequence (thanks John). Order:

1. Things that start with numbers.
2. Things that start with capital letters.
3. Things that start with underscores.
4. Things that start with lower case letters.

The redirect used to start with an underscore (it will be renamed for 1.0.7.14 so that it starts zz_ which will sort before anything short of zza). I'm guessing that your hook started with a lower case letter. So it sorted after the redirect, which ended execution of the page before the hook ran. The hook was there and was scheduled to be run. But the redirect happened before it actually did.

Renaming to _01a_anything made it sort before the redirect (1 sorts before 4) but after _01_post_login (_ sorts before a).

What you did should work and will work in the future. But changing the name makes it work with the way things are right now.