Hi guys!
I have a database with three fields.
I would like this scenario: I go into the database, and when manually inserting a value in field1 and then field2 it automatically writes into field3 their sum.
Thank you in advance!
Hi guys!
I have a database with three fields.
I would like this scenario: I go into the database, and when manually inserting a value in field1 and then field2 it automatically writes into field3 their sum.
Thank you in advance!
You can do that by adding an afterUpdate Hook.
Assuming that the fields are: taxes , shipping and total .
export function orders_afterUpdate(order) {
// This is to make sure that you always have a number value
if (typeof order.taxes !== 'number') { order.taxes = 0 }
if (typeof order.shipping!== 'number') { order.shipping= 0 }
// Sum the taxes and shipping automatically.
order.total = Number(order.taxes) + Number(order.shipping);
// Don't forget to return the order to save the new changes.
return order;
}
Hope this helps~!
Ahmad
Thank you for the response! The only thing is that when I close the database and come back, the value is not there anymore. Any suggestions?
Thanks!
The value should remain even if you closed the database window.