Hi All
i need to insert in a separat table data after the order is inserted in the db (to be specific, i want on special payment methods where i have the payment imediately to insert the amount i received in a specific table)
i saw the hook listen_insertOrder but i think thats specific for the orders table....
thanks in advance!
Hook to insert after Order is inserted in DB
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Hook to insert after Order is inserted in DB
https://github.com/CE-PhoenixCart/Phoen ... .sql#L1166
That's the hook that invokes the order insertion.
I wouldn't describe listen_insertOrder as being limited to the order table, but it does run before the insertion. If you want to add a new table and use the order ID, I would suggest adding a hook that runs after _14_insert_order -- you can get the order ID by $GLOBALS['order']->get_id() E.g.
Code: Select all
INSERT INTO hooks (hooks_site, hooks_group, hooks_action, hooks_code, hooks_class, hooks_method) VALUES ('shop', 'checkout_process', 'startCheckout', '_14_insert_order', 'checkout_surface', 'insert_order');I wouldn't describe listen_insertOrder as being limited to the order table, but it does run before the insertion. If you want to add a new table and use the order ID, I would suggest adding a hook that runs after _14_insert_order -- you can get the order ID by $GLOBALS['order']->get_id() E.g.
Code: Select all
class hook_shop_checkout_process__14a_after_insert {
public function listen_startCheckout() {
$order_id = $GLOBALS['order']->get_id();
// do stuff here
}
}-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: Hook to insert after Order is inserted in DB
thank you eCartz, i think your hook is what i need but i'm not sure about the naming of the file.
if i put it in
templates\override\includes\hooks\shop\siteWide\ what is the name of the file?
with the content of this
if i put it in
templates\override\includes\hooks\shop\siteWide\ what is the name of the file?
with the content of this
Code: Select all
class hook_shop_checkout_process__14a_after_insert {
public function listen_startCheckout() {
$order_id = $GLOBALS['order']->get_id();
// do stuff here
}
}-
loop
- Contributor
- Posts: 253
- Joined: Thu Mar 25, 2021 12:26 pm
- Phoenix Version:
- Has thanked: 7 times
- Been thanked: 3 times
Re: Hook to insert after Order is inserted in DB
perfect, it worked!
is there maybe a simpler solution to get payment_method / amount without query the database? maybe in the orders object?
is there maybe a simpler solution to get payment_method / amount without query the database? maybe in the orders object?
Code: Select all
public function listen_startCheckout() {
$order_id = $GLOBALS['order']->get_id();
$payment_method = tep_db_get_one_field('payment_method','orders','orders_id="'.(int)$order_id.'"');
$amount = tep_db_get_one_field('value','orders_total','orders_id="'.(int)$order_id.'" AND class = "ot_total"');
//Betrag bereits einbuchen
if(($payment_method=="Vorauszahlung") || ($payment_method=="Kredit Karte") || ($payment_method=="Twint") || ($payment_method=="PayPal") || ($payment_method=="PostFinance Debit Direct (Postcard)")){
tep_db_query("INSERT INTO orders_paid (orders_id, paid, amount, `time`, who) values ('".$order_id."','1','".$amount."','".time()."','Order Import')");
}
}-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Hook to insert after Order is inserted in DB
Considering that you just inserted them into the database, go back and look at insert_order.php and see what it did to fetch those values (so as to insert them). Then do that.