Page 1 of 1

Link membership_users table with Customers table

Posted: 2017-01-21 10:09
by amlan1995
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!

Re: Link membership_users table with Customers table

Posted: 2017-02-02 11:51
by AlexRuter
Can you post your ccode and how you did that?

Re: Link membership_users table with Customers table

Posted: 2017-02-18 15:42
by KansasWind
amlan1995 could I ask you to post the code here? I'd really love to use it. Thanks

Re: Link membership_users table with Customers table

Posted: 2019-09-09 12:17
by Ionut Bocanet
I want it also. Can you share the code if you succeeded ?

Thank you

Re: Link membership_users table with Customers table

Posted: 2019-10-01 14:23
by onoehring
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