Page 1 of 1
How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 4:54 am
by trujve
Hej all,
is it possible to change the success.php controller with an before trigger handler?
I have tried this, but there is no output on the success page.
Code: Select all
$myvar= str_replace(
[
'if (isset($this->session->data[\'order_id\'])) {',
],
[
'if (isset($this->session->data[\'order_id\'])) {
echo \'TEST\'',
],
$code
);
In:
Code: Select all
'trigger' => 'catalog/controller/checkout/success/before',
It looks as if the trigger is not infected.
Did I misses somethin?
Best,
Jack
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 10:18 am
by softmonke
trujve wrote: ↑Tue Dec 05, 2023 4:54 am
Hej all,
is it possible to change the success.php controller with an before trigger handler?
I have tried this, but there is no output on the success page.
Code: Select all
$myvar= str_replace(
[
'if (isset($this->session->data[\'order_id\'])) {',
],
[
'if (isset($this->session->data[\'order_id\'])) {
echo \'TEST\'',
],
$code
);
In:
Code: Select all
'trigger' => 'catalog/controller/checkout/success/before',
It looks as if the trigger is not infected.
Did I misses somethin?
Best,
Jack
From what I understand about events, I believe you can only modify output of view events. Based on what you're trying to do, perhaps you can set your own session at checkout/confirm and then verify if the session is set at checkout/success.
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 4:28 pm
by trujve
Thank you very much!
But does that mean that it would still be possible to collect and transfer everything I need in an array before the unsetting of the data in the success.php controller by an before handler?
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 5:34 pm
by DigitCart
Hi
This is what I use to replace the default success controller with my own controller:
Admin:
Code: Select all
$this->model_setting_event->addEvent('my_module', 'catalog/controller/checkout/success/before', 'extension/module/my_module/changeRoute');
Catalog
Code: Select all
public function changeRoute(&$route = '', &$data = array(), &$output = '') {
if ($something_is_true) {
$route = 'extension/module/my_module';
}
}
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 6:05 pm
by JNeuhoff
trujve wrote: ↑Tue Dec 05, 2023 4:28 pm
Thank you very much!
But does that mean that it would still be possible to collect and transfer everything I need in an array before the unsetting of the data in the success.php controller by an before handler?
What exactly are you trying to accomplish with your event handler?
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 6:59 pm
by trujve
DigitCart wrote: ↑Tue Dec 05, 2023 5:34 pm
Hi
This is what I use to replace the default success controller with my own controller:
Admin:
Code: Select all
$this->model_setting_event->addEvent('my_module', 'catalog/controller/checkout/success/before', 'extension/module/my_module/changeRoute');
Catalog
Code: Select all
public function changeRoute(&$route = '', &$data = array(), &$output = '') {
if ($something_is_true) {
$route = 'extension/module/my_module';
}
}
WOW! Very interesting! So replacing the entire controller is also possible???
Thanks a lot.
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 7:04 pm
by trujve
JNeuhoff wrote: ↑Tue Dec 05, 2023 6:05 pm
trujve wrote: ↑Tue Dec 05, 2023 4:28 pm
Thank you very much!
But does that mean that it would still be possible to collect and transfer everything I need in an array before the unsetting of the data in the success.php controller by an before handler?
What exactly are you trying to accomplish with your event handler?
Hej @JNeuhoff ,
Quite simply. I need some order data from the order on the SUCCESS page:
- All purchased products (title, SKU, EAN, MPN, brand)
- URL to the product Item image
- URL to the product detail page
- Total price of the order
- Order number
- E-mail address of the customer
- Currency
- Payment method
- Estimated delivery date
Best,
Jack
Re: How to change success.php controller with before trigger handler?
Posted: Tue Dec 05, 2023 10:21 pm
by JNeuhoff
You should use 2 event handlers for this:
1)
catalog/controller/checkout/success/before
from where you can get the order_id from the $this->session->data['order_id'], copy it to another session variable, because the $this->session->data['order_id'] will be cleared.
2)
catalog/view/checkout/success/before
to modify your data and template, you can get the data details from the order via the previously saved order_id. Finally clear your copied order_id in the session.
Re: How to change success.php controller with before trigger handler?
Posted: Wed Dec 06, 2023 5:36 pm
by trujve
JNeuhoff wrote: ↑Tue Dec 05, 2023 10:21 pm
You should use 2 event handlers for this:
1)
catalog/controller/checkout/success/before
from where you can get the order_id from the $this->session->data['order_id'], copy it to another session variable, because the $this->session->data['order_id'] will be cleared.
2)
catalog/view/checkout/success/before
to modify your data and template, you can get the data details from the order via the previously saved order_id. Finally clear your copied order_id in the session.

GREAT!
THNX again, i will try this out!
Best,
Jack
Re: How to change success.php controller with before trigger handler?
Posted: Wed Dec 06, 2023 8:50 pm
by JNeuhoff
Also take a look at
this forum thread for more details on how to modify a twig-template via an event handler.
Re: How to change success.php controller with before trigger handler?
Posted: Fri Dec 08, 2023 6:17 pm
by trujve
JNeuhoff wrote: ↑Wed Dec 06, 2023 8:50 pm
Also take a look at
this forum thread for more details on how to modify a twig-template via an event handler.
THNX!!
Re: How to change success.php controller with before trigger handler?
Posted: Sat Dec 09, 2023 3:31 pm
by trujve
I am now trying to pass the order_id from the "controller" into the data session and I still have the feeling that nothing is happening. I do not have this variable available.
Is this the right way?
catalog/controller/checkout/success/before
Code: Select all
if (!$this->session) {
$this->load->library('session');
}
$template_buffer = str_replace(
[
'if (isset($this->session->data[\'order_id\'])) {',
],
[
'if (isset($this->session->data[\'order_id\'])) {
$this->session->data[\'myorderid\'] = $this->session->data[\'order_id\'];
',
],
$code
);