Jump to content

Action hook based on product sold


Recommended Posts

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?

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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 by tomdchi
Link to comment
Share on other sites

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

(

)

 

)

Link to comment
Share on other sites

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 by tomdchi
Link to comment
Share on other sites

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

(

)

 

)

Link to comment
Share on other sites

  • 2 weeks later...

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

(

)

 

)

Link to comment
Share on other sites

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.

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