7 replies [Last post]
gxh11's picture
Offline
Joined: 01/18/2010
Juice: 14
Was this information Helpful?

Hi,

I'm a noob so please be gentle with me! I want an idea of how to "do stuff" as soon as payment for an order is processed, using custom php. Specifically, suppose I go to

http://mysite/admin/store/ca

Next to "Update order status on full payment" I click on "edit". I go to "Actions" and select "Execute custom PHP code" where I see two variables available, "$order" and "$account". What I'd like to know is:

1) Does $order represent the order I'm working on? In other words, as far as the custom PHP I'm writing is concerned, is this actually a constant? And similarly for $account?

2)What kind of variable is it? An array? An array of arrays? If it's an array, how do I drill into it and get the appropriate parameters (order id, line items, billing and shipping address, etc.)?

Finally, it would be great to see a sort of "hello world" for what I could enter in this "custom PHP" block. My goal is to export the order data to my Openbravo implementation (I already wrote a very simple PHP class for making api calls to Openbravo, and it's already being used!).

Cayenne's picture
Offline
Joined: 01/01/2009
Juice: 533
Re: order custom php "hello world" needed

Edit

I see you are using Conditional Actions

As a good hello world, try print_r($order); which will not only have a dramatic effect on your screen but will also show you the structure of the order variable!

gxh11's picture
Offline
Joined: 01/18/2010
Juice: 14
You Rock

Thanks! I'm gonna try this. I like dramatic effects!

gxh11's picture
Offline
Joined: 01/18/2010
Juice: 14
hmmmm

not quite working Sad When should the dramatic screen effect appear?

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: hmmmm

Better yet, install the Devel module, configure the permissions (you only want your user role, not normal users, to be able to view Devel information) and then do this:

<?php
dsm
($order);
?>

(without the php tags, I think.) This will do a nice drupal_set_message of the $order object.

Re, your questions:
1) Yes.
2) $order is an object of nested arrays (and sometimes more objects). So common things will be like, $order->order_id, $order->order_status, etc. I think $order->products is an object, so you may want to do a foreach loop on $order->products as $product, to grab things such as $product->data['attributes'].

Again, do a dsm() on that variable and you'll see the structure.

Also, for a good way to examine a hello world, make your event be "an order status gets updated" - if you use the one in your Original post, which is "a payment is entered for an order", you'll have to keep making payments in your admin area on the order you want to test on. I find that using a status update makes the process a bit quicker.

HTH.

--
Help directly fund development: Donate via PayPal!

gimript's picture
Offline
Joined: 06/19/2010
Juice: 9
ca_email_notification

I am currently in dev mode and there have orders being submitted no payment or email settings configured.
2 questions
I trying to test CA -> action and custom PHP code and use orders
and I tried inserting the code and nothing the order goes through I dont see anything on the screen, other than the order completion message.
can you help me out ? is this related to the settings mentioned above not being configured ?

c0psrul3's picture
Offline
Joined: 10/07/2007
Juice: 95
Re: order custom php "hello world" needed

are you willing to share the source to your openbravo connector class?

gxh11's picture
Offline
Joined: 01/18/2010
Juice: 14
Openbravo php connector class

Connector class attached! I'd love it if someone could adapt this for Ubercart. Who's up for that? I recommend testing to make sure this class works first.

AttachmentSize
obws.txt 3.54 KB
settings.txt 151 bytes