Skip to main content

How to add a product to a order before an order update

More
6 years 9 months ago #314083 by PeterChain
Hi,

We need to add a product to an order using the plugin trigger "onBeforeOrderUpdate"

Is that possible?

If its possible, how we have to do it? It will have to recalculate the total price for the order?

Thanks.

--
Victor

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

More
6 years 9 months ago #314085 by Mohamed Thelji
Hello Victor,

Sure you can edit the $order variable and properly adapt every aspect of the order (taxes, quantities,...), can you give us more information about what you want to achieve so that we can give you more information about it ?

Kind regards,
Mohamed.
The following user(s) said Thank You: PeterChain

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

More
6 years 9 months ago #314096 by PeterChain
Hi,

We need to insert a product to an order when a certain requirements are complimented (for example, when a specific payment type is selected by the customer).

We wanted to know the proper way to insert it into the $order variable and if we have to change anything more (as you said, if we have to recalculate the taxes and the full order price).


Thanks.

--
Victor

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

More
6 years 9 months ago #314114 by nicolas
Hi,

You can do it like that:
Code:
$orderProductClass = hikashop_get('class.order_product'); $orderProduct = new stdClass(); $orderProduct->order_id = $order_id; $orderProduct->order_product_name = 'My product'; $orderProduct->order_product_price = 10; $orderProduct->order_product_quantity = 1; $orderProductClass->update($orderProduct);
Then yes, you need to recalculate the total in $order->order_full_price (basically, you just add the amount to the value you already have in order_full_price in the database for that order).
The following user(s) said Thank You: PeterChain

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

Time to create page: 0.158 seconds
Powered by Kunena Forum