customer_id create account

Ask the community for help and support.
Post Reply
Mikepo
VIP Member
VIP Member
Posts: 9
Joined: Mon Oct 26, 2020 12:58 pm
Has thanked: 4 times

customer_id create account

Post 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?
ecartz
Lead Developer
Lead Developer
Posts: 935
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 75 times

Re: customer_id create account

Post 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.
Mikepo
VIP Member
VIP Member
Posts: 9
Joined: Mon Oct 26, 2020 12:58 pm
Has thanked: 4 times

Re: customer_id create account

Post 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?
ecartz
Lead Developer
Lead Developer
Posts: 935
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 75 times

Re: customer_id create account

Post 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).
Mikepo
VIP Member
VIP Member
Posts: 9
Joined: Mon Oct 26, 2020 12:58 pm
Has thanked: 4 times

Re: customer_id create account

Post 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!
ecartz
Lead Developer
Lead Developer
Posts: 935
Joined: Tue Nov 05, 2019 6:02 pm
Has thanked: 4 times
Been thanked: 75 times

Re: customer_id create account

Post by ecartz »

ecartz wrote: Wed Jan 13, 2021 5:26 pmPerhaps 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.
Post Reply