How to add custom code into the checkout_process

Open to all! Ask other shopowners for help.
Post Reply
User avatar
stevang
Member
Posts: 21
Joined: Thu Nov 07, 2019 11:47 pm
Phoenix Version:
Has thanked: 15 times
Been thanked: 1 time

How to add custom code into the checkout_process

Post 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to add custom code into the checkout_process

Post 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.
User avatar
zipurman
Builder
Posts: 540
Joined: Tue Oct 13, 2020 5:20 pm
Phoenix Version: v
Has thanked: 93 times
Been thanked: 162 times

Re: How to add custom code into the checkout_process

Post by zipurman »

Not sure if this helps:

https://youtu.be/bLd9m_uABYI
zipurman
-----------
User avatar
stevang
Member
Posts: 21
Joined: Thu Nov 07, 2019 11:47 pm
Phoenix Version:
Has thanked: 15 times
Been thanked: 1 time

Re: How to add custom code into the checkout_process

Post by stevang »

zipurman wrote: Fri Jun 25, 2021 5:32 pm Not sure if this helps:

https://youtu.be/bLd9m_uABYI
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
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to add custom code into the checkout_process

Post 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.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply