customer_id create account

Post advanced questions here for help with coding or web design.
Post Reply
Mikepo
VIP Member
VIP Member
Posts: 10
Has thanked: 3 times

customer_id create account

Post by Mikepo » Thu Dec 31, 2020 2:52 pm

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: 741
Has thanked: 3 times
Been thanked: 14 times

Re: customer_id create account

Post by ecartz » Fri Jan 01, 2021 10:31 am

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: 10
Has thanked: 3 times

Re: customer_id create account

Post by Mikepo » Wed Jan 13, 2021 2:50 pm

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: 741
Has thanked: 3 times
Been thanked: 14 times

Re: customer_id create account

Post by ecartz » Wed Jan 13, 2021 5:26 pm

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: 10
Has thanked: 3 times

Re: customer_id create account

Post by Mikepo » Thu Jan 14, 2021 10:25 am

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: 741
Has thanked: 3 times
Been thanked: 14 times

Re: customer_id create account

Post by ecartz » Thu Jan 14, 2021 11:24 am

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.

Post Reply