How to add 'additional weight' to an order?

  • Posts: 44
  • Thank you received: 2
1 year 2 weeks ago #350897

-- HikaShop version -- : 4.7.2
-- Joomla version -- : 4
-- PHP version -- : 8.1

Hi,

Have a question regarding product weight and total order weight. Using Hikashop Business.

Use case: all our products do have a weight. With each product, I have a custom field. By default, it is set to 1. Maximum is 7. Each value chosen should add a certain weight times the chosen value, let's say 40 grams, to the product. So if the custom field contains the value 3, a total of 120 grams must be added to the weight of the order. If the product weight was already 100 grams, the total weight of the product in the cart has to be 100 + 120 = 220 grams. How can I achieve this?

For reasons I cannot use product variants or options. It has to be done through this custom field.

Any suggestion in the right direction is much appreciated!

Thanks, Jelger

Last edit: 1 year 2 weeks ago by praes.

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

  • Posts: 81540
  • Thank you received: 13069
  • MODERATOR
1 year 2 weeks ago #350899

Hi,

I think you'll have to create a small custom plugin. In it, you'll want to implement the onAfterOrderCreate and onAfterOrderUpdate event ( www.hikashop.com/support/documentation/6...mentation.html#order ).
In these, you'll want to:
- Run a MySQL query based on the order_id to load the products in the hikashop_order_product table and then their corresponding data in the hikashop_product table
- based on order_product_quantity in hikashop_order_product and your product custom field value in hikashop_product, you can update the order_product_weight in the hikashop_order_product table with a MySQL query
- you can also recalculate the total and set the order_weight in the hikashop_order table with a MySQL query.
Beware of NOT using the save function of class.order to save the new total weight in the order as you would create an infinite loop since the save function will then trigger the onAfterOrderUpdate event.

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

Time to create page: 0.059 seconds
Powered by Kunena Forum