Skip to main content

onAfterOrderCreate iterating through products

More
14 years 2 weeks ago - 14 years 2 weeks ago #66736 by GeoffM
I'm not proficient in PHP or Hikashop, and simply need a few lines of code to link Hikashop to some existing code. I can get my callback to fire after an order has been processed in the shop but I'm at a loss how to actually get at the data in the order. I seem to be going round in circles with the doco and searching.

So can somebody fill in the blanks please? Given the $order parameter, I want my function to be called once for each product ID in the order.
Code:
function onAfterOrderCreate(&$order,&$send_email){ if(!empty($order->order_id)){ <foreach product in $order> my_function(productID, userID); </foreach> } return true; }

The User ID has to be the Joomla one, not anything Hikashop creates. There might be some configuration item I need to set to force Hikashop to only allow checkout with a logged-in user. Thanks.
Last edit: 14 years 2 weeks ago by GeoffM.

Please Log in or Create an account to join the conversation.

More
14 years 2 weeks ago #66941 by Xavier
Hi,

Try this code:
Code:
function onAfterOrderCreate(&$order,&$send_email){ if(!empty($order->order_id)){ $class = hikashop_get('class.user'); $user = $class->get($order->order_user_id); foreach($order->cart->products as $product){ my_function($product->product_id, $user->user_cms_id); } }
The following user(s) said Thank You: GeoffM

Please Log in or Create an account to join the conversation.

More
14 years 1 week ago #68115 by GeoffM
Thank you, that works perfectly. Sorry for the delay in replying. Now, how do I get the order quantity per product? I've tried $product->quantity and $product->count and $product->cart_product_quantity (as per DB table) but none work.

Many thanks.

Please Log in or Create an account to join the conversation.

More
14 years 1 week ago #68116 by nicolas
In the order_product table of the DB the quantity column is called order_product_quantity not cart_product_quantity.
So you should do $product->order_product_quantity
The following user(s) said Thank You: GeoffM

Please Log in or Create an account to join the conversation.

More
14 years 1 week ago #68117 by GeoffM
I was looking at the wrong table then! Makes sense now - many thanks.

Please Log in or Create an account to join the conversation.

Time to create page: 0.254 seconds
Powered by Kunena Forum