Post by trujve » 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

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by softmonke » Tue Dec 05, 2023 10:18 am

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.

Reach out to us at hello@softmonke.com for your OpenCart web development needs.


User avatar
Active Member

Posts

Joined
Tue May 23, 2023 4:42 am


Post by trujve » 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?

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by DigitCart » 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';
			}
	}

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by JNeuhoff » 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?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by trujve » Tue Dec 05, 2023 6:59 pm

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.

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by trujve » Tue Dec 05, 2023 7:04 pm

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

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by JNeuhoff » 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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by trujve » Wed Dec 06, 2023 5:36 pm

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.
O0 GREAT!
THNX again, i will try this out!

Best,
Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by JNeuhoff » 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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by trujve » Fri Dec 08, 2023 6:17 pm

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!!

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by trujve » Sat Dec 09, 2023 3:31 pm

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
);

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm
Who is online

Users browsing this forum: No registered users and 3 guests