stevewilliams Posted June 2, 2010 Share Posted June 2, 2010 I have setup a "ClientAdd" action hook, but I need to perform slightly different actions based on which product the client has purchased. For example, if the client purchases package "A", then do this... else if the client purchases package "B", then do that... etc. I was thinking I would have to gather the product number by using an "AfterShoppingCartCheckout" action hook, but I am having trouble. Could someone give me a hand? 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted June 6, 2010 Share Posted June 6, 2010 Ok... whats the trouble?? use print_r($params) to view what data is being sent to the hook function. like function after_checkout($params) { print_r($params); } add_hook("AfterShoppingCartCheckout", 1, "after_checkout"); Don't forget that many things are in multidimensional arrays and therefore need to be accessed as such. $firstname = $params['clientsdetails']['firstname']; 0 Quote Link to comment Share on other sites More sharing options...
chatpert Posted June 9, 2010 Share Posted June 9, 2010 Where am I supposed to see the messages printed by print_r($params); I looked in apache log, and I did not see anything. /var/log/httpd/ssl_error_log I did not see anything in the web page either. 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted June 9, 2010 Share Posted June 9, 2010 (edited) If you did it correctly then it should output to the browser. You did make a php file with the code function after_checkout($params) { print_r($params); } add_hook("AfterShoppingCartCheckout", 1, "after_checkout"); and saved it in the includes/hooks folder right? You may want to put exit(); after the print_r to stop execution. It could be showing so fast that you don't have a chance to see it. When using the code above after checkout shows Array ( [OrderID] => 227 [OrderNumber] => 9143138738 [invoiceID] => 1365 [Products] => Array ( [0] => 244 ) [Addons] => Array ( ) [Domains] => Array ( ) [Renewals] => Array ( ) ) in the browser. Edited June 9, 2010 by tomdchi 0 Quote Link to comment Share on other sites More sharing options...
chatpert Posted June 9, 2010 Share Posted June 9, 2010 Adding exit(); helps. I wonder if there is a redirect going on after I click "complete order" on this page cart.php?a=checkout. Without exit, I could not see anything. Another question: for "AfterShoppingCartCheckout", I used this interface, function order_complete( $params ) Now I changed it to function order_complete($OrderID, $OrderNumber, $InvoiceID, $Products, $Addons, $Domains) Now there are warnings like these: Warning: Missing argument 2 for order_complete() and up to "argument 6". Which interface should I declare? Also from the output, I see a 7th item "Renewals" which is not documented. Can you explain it? Array ( [OrderID] => 28 [OrderNumber] => 9743922575 [invoiceID] => 100025 [Products] => Array ( [0] => 24 ) [Addons] => Array ( ) [Domains] => Array ( ) [Renewals] => Array ( ) ) 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted June 10, 2010 Share Posted June 10, 2010 (edited) Your misunderstanding how action hooks work. A action hook will always be put together the same way. You can't put other arguments in the function. The ONLY thing that can be passed (explicitly) into the function is the array. $params is only a placeholder name for the array and can be named anything...$vars, $myparams, $whatever. Globals and super globals can be used in the function as well. function after_checkout($vars) can only have $vars inside the parenthesis. Inside the function is where you pull out values from the array and do stuff with them. with this example: function after_checkout($params) { $orderid = $params['OrderID']; $invoiceid = $params['InvoiceID']; //do stuff with vars above echo $invoiceid; //this will output invoice id to the browser } add_hook("AfterShoppingCartCheckout", 1, "after_checkout"); The function name itself can be whatever you want to name it as well but has to be defined in the add_hook function call. like the above code has the function name defined as after_checkout and then it is used as an argument in the add_hook function call. Renewels are domain renewals. If someone was checking out and renewing a domain it would show there. If you are not a coder I would suggest that you utilize php.net and all the other php help sources out there to get a better understanding. Edited June 10, 2010 by tomdchi 0 Quote Link to comment Share on other sites More sharing options...
chatpert Posted June 10, 2010 Share Posted June 10, 2010 I am writing custom code after checkout on action hook AfterShoppingCartCheckout. I could not find details on the variables. Where are those documented? I have defined more options in xxx_ConfigOptions() of modules/servers/ such as "Professional(otherwise Standard)" => array( "Type" => "yesno", "Description" => "Account Type" ), So when a customer places an order, I need to know the package ordered, and the customer's info such as email. What I see now is something like this. Where should I go from here to get data structure of the variables? Array ( [OrderID] => 30 [OrderNumber] => 9036531923 [invoiceID] => 100027 [Products] => Array ( [0] => 26 ) [Addons] => Array ( ) [Domains] => Array ( ) [Renewals] => Array ( ) ) 0 Quote Link to comment Share on other sites More sharing options...
chatpert Posted June 19, 2010 Share Posted June 19, 2010 for AfterShoppingCartCheckout hook, What table am I supposed to look up for Products? I checked table "tblproducts", but it does not look right. I ordered the same product over and over again. The Products shown below keep changing. It was 24 at some point, and now it is 29. Is it supposed to be a fixed number? Array ( [OrderID] => 33 [OrderNumber] => 7359736092 [invoiceID] => 100032 [Products] => Array ( [0] => 29 ) [Addons] => Array ( ) [Domains] => Array ( ) [Renewals] => Array ( ) ) 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted June 19, 2010 Share Posted June 19, 2010 The value in the products array returned by the hook is the row id in tblhosting for the product that was just ordered. 0 Quote Link to comment Share on other sites More sharing options...
chatpert Posted June 19, 2010 Share Posted June 19, 2010 Thanks, tomdchi. I was basically sitting there waiting for someone to give me a direction. That was helpful. I also figured packageid is the same as the ID in table tblproducts. I did a DB dump "mysqldump", and started reading the schema that way. Is that what you guys do? Is there a better way? any documentation on the DB design? I am pretty new to this. 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.