glardone Posted August 22, 2016 Share Posted August 22, 2016 Dear all, I'm trying to create a hook to insert the domains data in a custom table after the shopping cart checkout. These data are: - domainid - userid - contactid and I will use them to create a custom report about the domain holders. My code is: <?php use Illuminate\Database\Capsule\Manager as Capsule; function domains($vars) { $orderid = $vars['orderid']; $domainid = array($vars['domainid']); $clientid = Capsule::table('tblorders') ->where('id',$orderid) ->get('userid'); $contacts = Capsule::table('tblorders') ->where('id',$orderid) ->get('contactid'); mysql_query ('INSERT INTO dna_domains (domainid, userid, contactid) VALUES (?,?,?)', array( $params['domainid'], $params['userid'], $params['contactid'] ) ); } add_hook("AfterShoppingCartCheckout", 1, "dna_domains"); I'm new in WHMCS and I have not understood how interact with its variables... where I'm wrong? Thank you for support! Best regards. 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted August 22, 2016 Share Posted August 22, 2016 DONT use mysql_query(). Check this and this 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 22, 2016 Share Posted August 22, 2016 it's also not going to help that the correct function name isn't used in the add_hook line. if it were me, and this was only for a report with the required information already in existing db tables, i'd be spending time on the report query rather than copying the data to a new table to make the query simpler. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 22, 2016 Share Posted August 22, 2016 there is few issues in your code, first of all you did not link the function actionhook point, both were defined but not linked together. also it has domainids as an array, it may return one or more domain ids so you need to loop through this array and enter new record for each finally the last query has incorrect syntax, you write PDO query while using regular deprecated mysql function so here is the changes I have made in your code: <?php use Illuminate\Database\Capsule\Manager as Capsule; add_hook("AfterShoppingCartCheckout", 1, function($vars) { $orderid = $vars['OrderID']; $order = Capsule::table('tblorders')->where('id',$orderid)->get(); $clientid = $order[0]->userid; $contactid = $order[0]->contactid; foreach ($vars['DomainIDs'] as $domainid){ Capsule::table('dna_domains')->insert(array("domainid" => $domainid, "userid" => $clientid, "contactid" => $contactid)); } }); 1 Quote Link to comment Share on other sites More sharing options...
glardone Posted August 22, 2016 Author Share Posted August 22, 2016 Dear Priestakos, thank you for your response, I modified my hook, but it's not work properly: <?php use Illuminate\Database\Capsule\Manager as Capsule; function domains($vars) { $orderid = $vars['orderid']; $domainid = array($vars['domainid']); $clientid = Capsule::table('tblorders') ->where('id',$orderid) ->get('userid'); $contacts = Capsule::table('tblorders') ->where('id',$orderid) ->get('contactid'); Capsule::table('dna_domains') ->insert( [ 'domainid', 'userid', 'contactid' => array( $params['domainid'], $params['userid'], $params['contactid'] ) ] ); } add_hook("AfterShoppingCartCheckout", 1, "dna_domains"); You have any ideas? Thank you! Best regards. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 22, 2016 Share Posted August 22, 2016 if it were me, and this was only for a report with the required information already in existing db tables, i'd be spending time on the report query rather than copying the data to a new table to make the query simpler. +1, yes it will be easier there is no unique information to use separate table for 0 Quote Link to comment Share on other sites More sharing options...
glardone Posted August 22, 2016 Author Share Posted August 22, 2016 Dear Sentq, thank you very much! Now it is more clear how it works... Best regards, Giorgio there is few issues in your code, first of all you did not link the function actionhook point, both were defined but not linked together. also it has domainids as an array, it may return one or more domain ids so you need to loop through this array and enter new record for each finally the last query has incorrect syntax, you write PDO query while using regular deprecated mysql function so here is the changes I have made in your code: <?php use Illuminate\Database\Capsule\Manager as Capsule; add_hook("AfterShoppingCartCheckout", 1, function($vars) { $orderid = $vars['OrderID']; $order = Capsule::table('tblorders')->where('id',$orderid)->get(); $clientid = $order[0]->userid; $contactid = $order[0]->contactid; foreach ($vars['DomainIDs'] as $domainid){ Capsule::table('dna_domains')->insert(array("domainid" => $domainid, "userid" => $clientid, "contactid" => $contactid)); } }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.