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

  • Posts: 634
  • Thank you received: 16
4 years 4 months ago #314083

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.

  • Posts: 12953
  • Thank you received: 1778
4 years 4 months ago #314085

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.

  • Posts: 634
  • Thank you received: 16
4 years 4 months ago #314096

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.

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
4 years 4 months ago #314114

Hi,

You can do it like that:

$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.069 seconds
Powered by Kunena Forum