Page 1 of 1
How to add custom code into the checkout_process
Posted: Fri Jun 25, 2021 10:30 am
by stevang
How can i add custom code to a specific point in the checkout process?
in earlier version i added my own hook call into the checkout_process.php and added a hook into the hook folder. but checkout_process seems to be all over the place now.
I also don't understand if there is any order in how something loads during checkout_process
btw; there is not realy any documentation regarding the code and processes of Phoenix out there?
Regards,
Stephan
Re: How to add custom code into the checkout_process
Posted: Fri Jun 25, 2021 10:56 am
by ecartz
Checkout process loads everything via
hooks. In
https://github.com/CE-PhoenixCart/Phoen ... ss.php#L15
https://github.com/CE-PhoenixCart/Phoen ... p#L13..L14
https://github.com/CE-PhoenixCart/Phoen ... 144..L1180
Hooks are loaded in order by hook name. So to add something new, add the appropriate hook file or database entry with a name that sorts at the appropriate place.
Re: How to add custom code into the checkout_process
Posted: Fri Jun 25, 2021 5:32 pm
by zipurman
Re: How to add custom code into the checkout_process
Posted: Tue Jun 29, 2021 10:45 am
by stevang
Thanks! Your videos are great always and very helpfull! Keep 'em coming
But the checkout process seems a bit different to what your video shows about hooks. I am talking about the files in /includes/system/segments/checkout/ . As i understand it, those files are each one part of the complete checkout process, called up one by one in alphabetical order. if i want to add something to the checkout process, i have to add it where i want it by choosing a filename that will be where i need the file to run (alphabeticaly).
Like if i needed some additional code within the checkout process right when a new order number is set, i would give it a filename that sorts in right after insert_order.php . for example insert_order_do_that.php or insert_order_01.php etc
Do i have that right?
Regards,
Stephan
Re: How to add custom code into the checkout_process
Posted: Tue Jun 29, 2021 6:12 pm
by ecartz
stevang wrote: ↑Tue Jun 29, 2021 10:45 am
But the checkout process seems a bit different to what your video shows about hooks. I am talking about the files in /includes/system/segments/checkout/ . As i understand it, those files are each one part of the complete checkout process, called up one by one in alphabetical order. if i want to add something to the checkout process, i have to add it where i want it by choosing a filename that will be where i need the file to run (alphabeticaly).
Like if i needed some additional code within the checkout process right when a new order number is set, i would give it a filename that sorts in right after insert_order.php . for example insert_order_do_that.php or insert_order_01.php etc
Do i have that right?
No. The segment files are not hook files. They're just loaded via hook. For example, here is the entry for insert_order:
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');
The name of the hook is _14_insert_order, so _14a_whatever would run immediately after it.
It would be possible to make a database hook for your thing that points to your file, but that seems the long way around. You could just create a hook file in includes/hooks/shop/checkout_process/_14a_whatever.php and listen for startCheckout. This should be as simple as renaming your old hook. You'd have to change
1. The hook class name.
2. The hook listener function name (to listen_startCheckout).
3. The file path, including the file name.