Jump to content

How to get contact id in whmcs custom hook


Sandra

Recommended Posts

Hi guys,

I'm using WHMCS for a long time, but now I have a little problem with my custom written hook.

Practically, I would like to get subcontact id (read contact id) in my hook via $_SESSION or something like that. I get user id with $_SESSION['uid'].

How can I make that for contacts?

Any solutions?

 

Best regards,
Sandra

 

Link to comment
Share on other sites

On 28/12/2018 at 09:42, Sandra said:

Practically, I would like to get subcontact id (read contact id) in my hook via $_SESSION or something like that. I get user id with $_SESSION['uid'].

there are three options I can think of - I wouldn't include the session as one of them.

  1. if the sub-user is logged in themselves, then you should be able to get that variable from the template - e.g $vars in the hook and add a {debug} to the end of the template to see what variables are available to the hook.
  2. you could query the database to get the value of a contact for a specified user.
  3. you could use the class docs to get contact details for a user.

if you know they're going to be logged in when this hook is triggered, then the first option would probably be the easiest.

Link to comment
Share on other sites

I have tried with the options 1 and 2, but I still did not find a right solution.
1) Using the variable $vars from my hook, I get information for client's details, not to contact's details. 
2) If I make a query to connect to my db, I get a list of all contacts by that client I'm searching for. 
But what I need is a specific contact id from that list of contacts (I would like to pass that ID from my website to specific hook), so I can access to the right contact.

Link to comment
Share on other sites

23 hours ago, Sandra said:

1) Using the variable $vars from my hook, I get information for client's details, not to contact's details. 

if the contact (assuming they have a sub-account) is logged in, you will have access to their details..

H68d4Fh.png

that contactid value tells you that they are a contact and not the main client - that value will refer to the id value used within the tblcontacts database table.

if the account owner were logged in instead, the result would be different...

7513vI3.png

now there is no contactid, but there is a userid - which tells us that this is the client and the userid value refers to the id value within the tblclients database table.

23 hours ago, Sandra said:

2) If I make a query to connect to my db, I get a list of all contacts by that client I'm searching for.

But what I need is a specific contact id from that list of contacts (I would like to pass that ID from my website to specific hook), so I can access to the right contact. 

how are you defining who is the "right" contact? if you know which one is the "correct" one and can identify them in a database query, then it should be straightforward - but i'm struggling to get my head around how you know which is the right one to look for... and what information you want from the database??

or to come at this from another way - what are you trying to achieve with this ?

Link to comment
Share on other sites

Contact is not logged in. The client makes an order, and set one of his contacts to be registrant of some service (exaple: registrant of some domain). This selected contact in my shopping cart, is the right contact 🙂

I have access to all contacts of that client in my shopping cart, also I can access to them via query in my hook, but I need to catch the id of selected contact from my shopping cart (by client), and send to my custom make hook.

Link to comment
Share on other sites

1 hour ago, Sandra said:

Contact is not logged in.

ahhh rules out the easier method of just checking who is loggedin!

1 hour ago, Sandra said:

The client makes an order, and set one of his contacts to be registrant of some service (example: registrant of some domain). This selected contact in my shopping cart, is the right contact 🙂

then that contact ID should be stored in the tblorders database table after checkout.

1 hour ago, Sandra said:

I have access to all contacts of that client in my shopping cart, also I can access to them via query in my hook, but I need to catch the id of selected contact from my shopping cart (by client), and send to my custom make hook.

if the value is 0, then no contact was used; otherwise it should be the id value from the tblcontacts table.

I suppose it's also possible that it's available to the complete.tpl template as a Smarty variable, but I haven't checked recently and so can't recall for sure.

Link to comment
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated