Link membership_users table with Customers table

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
amlan1995
Posts: 3
Joined: 2016-12-25 19:17

Link membership_users table with Customers table

Post by amlan1995 » 2017-01-21 10:09

Hi,

I have built an Invoicing System with Appgini. Basically I have two database tables namely "Customers" and "Invoices".

I was wondering if there's a way to add the new customer automatically to the "membership_users" table as soon as I add a new customer to the "Customers" table.

Also whenever I add a new invoice for a customer to the "Invoices" table, it should automatically assign the customer as the owner of the record. So that whenever he logs in to the system, he should be able to view his own invoices.

I'll be very grateful if anyone help me out with my query.

Thanks!

AlexRuter
Posts: 2
Joined: 2017-02-02 11:50

Re: Link membership_users table with Customers table

Post by AlexRuter » 2017-02-02 11:51

Can you post your ccode and how you did that?

KansasWind
Posts: 1
Joined: 2017-02-02 13:51
Location: Ghzira, Malta
Contact:

Re: Link membership_users table with Customers table

Post by KansasWind » 2017-02-18 15:42

amlan1995 could I ask you to post the code here? I'd really love to use it. Thanks
Spela på casino dino eller varför inte testa dagens casino när du ändå är i farten?

Ionut Bocanet
Posts: 28
Joined: 2017-03-12 09:26
Contact:

Re: Link membership_users table with Customers table

Post by Ionut Bocanet » 2019-09-09 12:17

I want it also. Can you share the code if you succeeded ?

Thank you
Best Regards,
Ionut Bocanet

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Link membership_users table with Customers table

Post by onoehring » 2019-10-01 14:23

Hi,

I will not supply any clean and easy to copy code, but I think a way to do this.
You create a new customer. Then, use the /hooks/TABLE_NAME_OF_CUSTOMER.php file and add php code in the function _after_insert. Something like this:

Code: Select all

function TABLE_NAME_OF_CUSTOMER_after_insert($data, $memberInfo, &$args){
  // we assume only one record is not in the membership_users yet, otherwise you will need to use the appgini SQL function
  $_result_sql = sqlvalue ("SELECT customer_name 
                            FROM customer_table 
                            LEFT JOIN membership_users ON customer_table.customer_name = membership_users.memberID
                            WHERE membership_users.memberID IS NULL");  

  //now you have the name, that is not in the membership_users table yet - simply write it to the membership_users table, add password etc. and you are ready to go. something like this:
  $sql="update membership_users  set memberID='".$_result_sql."', passMD5 ='some MD5 of PW', otherfield=......";
  $_result_sql = sql($sql, $eo);
}
Remember: This code needs to be adjusted and corrected.
PS: This seems the wrong sub-forum. Would this be better in 'Getting Started'?

Olaf

Post Reply