Post by trujve » Sat Feb 03, 2024 12:48 am

Hej folks,

i'm trying to customize the opencart success.php in the checkout controller in my own extension, unfortunately it doesn't have the slightest effect and I would like to ask you if you find a bug that I just don't see anymore?

This is what it looks like in my admin controller module

Code: Select all

$this->model_setting_event->deleteEventByCode($this->module.'_mycheckoutcontroller');
		$this->model_setting_event->addEvent([
			'code'			=> $this->module.'_mycheckoutcontroller',
			'description'	=> $this->description.' - my descriptionr',
			'trigger'		=> 'catalog/controller/checkout/success/before',
			'action'		=> 'extension/mymodule/module/mymodule.mycheckoutcontroller',
			'status'		=> true,
			'sort_order'	=> 0
		]);

This is what it looks like in my catalog controller module

Code: Select all

public function mycheckoutcontroller(&$route, &$data, &$code = null) {

    if (!$this->config->get("module_mymodule_status")) {
        return;
    }

$template_code = $this->getTemplateCodeMycheckoutController($route, $code);

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->load->model("checkout/order");
$myOwnData= $this->model_checkout_order->getOrder($this->session->data["order_id"]);
if ($myOwnData) {
$data["order_id"] = (int)$myOwnData["order_id"];
$data["total"] = number_format((float)$myOwnData["total"], 2, ".", "");
}',

$code
);

    $code = $template_buffer;
    return null;
}

protected function getTemplateCodeMycheckoutController($route, &$code) {
    if (!empty($code)) {
        return $code;
    }

    $file = DIR_OPENCART . 'catalog/controller/' . $route . '.php';
    if (is_file($file)) {
        $code = file_get_contents($file);
    } else {
        trigger_error("Cannot find template file for route '$route'");
        exit;
    }
    return $code;
}

In this way I can customize everything so far, but only here in the catalog controller it simply does not work in the success.php.
Am I missing something?

Best,
Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by straightlight » Sat Feb 03, 2024 1:22 am

trujve wrote:
Sat Feb 03, 2024 12:48 am
Hej folks,

i'm trying to customize the opencart success.php in the checkout controller in my own extension, unfortunately it doesn't have the slightest effect and I would like to ask you if you find a bug that I just don't see anymore?

This is what it looks like in my admin controller module

Code: Select all

$this->model_setting_event->deleteEventByCode($this->module.'_mycheckoutcontroller');
		$this->model_setting_event->addEvent([
			'code'			=> $this->module.'_mycheckoutcontroller',
			'description'	=> $this->description.' - my descriptionr',
			'trigger'		=> 'catalog/controller/checkout/success/before',
			'action'		=> 'extension/mymodule/module/mymodule.mycheckoutcontroller',
			'status'		=> true,
			'sort_order'	=> 0
		]);

This is what it looks like in my catalog controller module

Code: Select all

public function mycheckoutcontroller(&$route, &$data, &$code = null) {

    if (!$this->config->get("module_mymodule_status")) {
        return;
    }

$template_code = $this->getTemplateCodeMycheckoutController($route, $code);

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->load->model("checkout/order");
$myOwnData= $this->model_checkout_order->getOrder($this->session->data["order_id"]);
if ($myOwnData) {
$data["order_id"] = (int)$myOwnData["order_id"];
$data["total"] = number_format((float)$myOwnData["total"], 2, ".", "");
}',

$code
);

    $code = $template_buffer;
    return null;
}

protected function getTemplateCodeMycheckoutController($route, &$code) {
    if (!empty($code)) {
        return $code;
    }

    $file = DIR_OPENCART . 'catalog/controller/' . $route . '.php';
    if (is_file($file)) {
        $code = file_get_contents($file);
    } else {
        trigger_error("Cannot find template file for route '$route'");
        exit;
    }
    return $code;
}

In this way I can customize everything so far, but only here in the catalog controller it simply does not work in the success.php.
Am I missing something?

Best,
Jack
You're using an /after event controller in the catalog-end while declaring a /before in your admin module.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by trujve » Sat Feb 03, 2024 3:07 am

Many thanks @straightlight !
Sorry I'm not following, but where or how do I use the /after event controller? I don't see it in my code?

Best,
Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by straightlight » Sat Feb 03, 2024 3:12 am

trujve wrote:
Sat Feb 03, 2024 3:07 am
Many thanks @straightlight !
Sorry I'm not following, but where or how do I use the /after event controller? I don't see it in my code?

Best,
Jack
Exactly. You are using /before instead of /after which is why you don't see /after in your code right now. You need to rename /before to /after.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by trujve » Sat Feb 03, 2024 5:01 am

Ah, now I've got it. With /before it makes no sense, as it is then processed. So it has to be /after. The code itself does not change, but is then no longer processed. I think that's it.

I tried it in a hurry and so far no output. I'd rather do it during the day. Thanks for the tip, I'll look into it.

Best,
Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by trujve » Sat Feb 03, 2024 5:19 am

I now changed it to /after and changed the code to:

Code: Select all

public function mycheckoutcontroller(string &$route, array &$data, mixed &$output): void {
    if (!$this->config->get("module_mymodule_status")) {
        return;
    }

        $output = isset($output) ? (string)$output : '';
        
        $output = str_replace(

          '$this->cart->clear();',

          '$this->cart->clear();

  			$this->load->model("checkout/order");
  			$myOwnData = $this->model_checkout_order->getOrder($this->session->data["order_id"]);
  			if ($myOwnData) {
  			$data["order_id"] = (int)$myOwnData["order_id"];
  			$data["total"] = number_format((float)$myOwnData["total"], 2, ".", "");
  		}', 
  		
  		$output);
}
And have still no output.
Think i`m to tired :-)

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by straightlight » Sat Feb 03, 2024 5:52 am

trujve wrote:
Sat Feb 03, 2024 5:19 am
I now changed it to /after and changed the code to:

Code: Select all

public function mycheckoutcontroller(string &$route, array &$data, mixed &$output): void {
    if (!$this->config->get("module_mymodule_status")) {
        return;
    }

        $output = isset($output) ? (string)$output : '';
        
        $output = str_replace(

          '$this->cart->clear();',

          '$this->cart->clear();

  			$this->load->model("checkout/order");
  			$myOwnData = $this->model_checkout_order->getOrder($this->session->data["order_id"]);
  			if ($myOwnData) {
  			$data["order_id"] = (int)$myOwnData["order_id"];
  			$data["total"] = number_format((float)$myOwnData["total"], 2, ".", "");
  		}', 
  		
  		$output);
}
And have still no output.
Think i`m to tired :-)
It also has to be changed in your oc_event table if you haven't reinstalled your extension.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by trujve » Sun Feb 04, 2024 7:37 pm

Still no output. No matter whether I use /before or /after. And yes, I have reinstalled it resp. changed it in the database. I have also tried to execute a LOG output, but this does not arrive either. So it seems that this one of my methods is not executed at all.

Unfortunately I don't understand why it has to be a /after handler. A /before makes sense, doesn't it?

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by straightlight » Mon Feb 05, 2024 12:55 am

trujve wrote:
Sun Feb 04, 2024 7:37 pm
Still no output. No matter whether I use /before or /after. And yes, I have reinstalled it resp. changed it in the database. I have also tried to execute a LOG output, but this does not arrive either. So it seems that this one of my methods is not executed at all.

Unfortunately I don't understand why it has to be a /after handler. A /before makes sense, doesn't it?
That is up to your decision which direction you'd like to take whether it's /before or /after. However, your original code indicated /before with a controller that is using a /after method. For more assistance, you can always look at the Event documentation on Github, on the forum, create a new service request in the Commercial Support section of the forum or contact me directly to investigate this issue as a custom job.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by trujve » Mon Feb 05, 2024 3:00 am

I have now checked and cleaned everything a bit and it now looks like this, which unfortunately has no positive effect either. I do not get my data output on the success page. Obviously the success.php is subject to some guidelines, so I can't make any changes there with /before or /after handler?


admin / controller / module

Code: Select all

		$this->model_setting_event->deleteEventByCode($this->module.'_mycheckoutcontroller');
		$this->model_setting_event->addEvent([
			'code'			=> $this->module.'_mycheckoutcontroller',
			'description'	=> $this->description.' - Checkout Controller',
			'trigger'		=> 'catalog/controller/checkout/success/before',
			'action'		=> 'extension/mymodule/module/mymodule.mycheckoutcontroller',
			'status'		=> true,
			'sort_order'	=> 0
		]);

catalog / controller / module

Code: Select all

public function mycheckoutcontroller(&$route, &$data, &$code = null) {

    if (!$this->config->get("module_mymodule_status")) {
        return;
    }

    $template_code = $this->getTemplateCodeMycheckoutController($route, $code);

    $template_buffer = str_replace(
        [
            '$this->cart->clear();',
        ],
        [
            '$this->load->model("checkout/order");
      $myOwnData = $this->model_checkout_order->getOrder($this->session->data["order_id"]);
      if ($myOwnData) {
          $data["order_id"] = (int)$myOwnData["order_id"];
          $data["email"] = html_entity_decode($myOwnData["email"], ENT_QUOTES, "UTF-8");
      	}
            $this->cart->clear();',
        ],
        $code
    );

    $code = $template_buffer;
    return null;
}

protected function getTemplateCodeMycheckoutController($route, &$code) {
    if (!empty($code)) {
        return $code;

    }

    $file = DIR_OPENCART . 'catalog/controller/' . $route . '.php';
    if (is_file($file)) {
        $code = file_get_contents($file);
        $this->log->write("CODE: ".$code);
    } else {
        trigger_error("Cannot find template file for route '$route'");
        exit;
    }

    return $code;
}

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by JNeuhoff » Mon Feb 05, 2024 5:53 am

I think it's meant to be like this:

Code: Select all

		$this->model_setting_event->deleteEventByCode('module_mycheckoutcontroller');
		$this->model_setting_event->addEvent([
			'code'		=> 'module_mycheckoutcontroller',
			'description'	=> $this->description,
			'trigger'	=> 'catalog/view/checkout/success/before',
			'action'	=> 'extension/mymodule/module/mymodule.mycheckoutcontroller',
			'status'	=> true,
			'sort_order'	=> 0
		]);
And then you have to write up a proper event handler for your 'catalog/view/checkout/success/before' trigger.

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


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by trujve » Mon Feb 05, 2024 4:50 pm

Hej @JNeuhoff,

not sure if you are right?

This seems not to be the right trigger:

Code: Select all

'trigger'	=> 'catalog/view/checkout/success/before',
Image

I realy meant this:

Code: Select all

'trigger'		=> 'catalog/controller/checkout/success/before',
Image

Am I wrong?

And that is why I want to do this in the success.php to grab my variables that i need in the checkout. It worked when i put it manually in there, but "str_replace" seems not to work in the /before handler:

Code: Select all

$template_buffer = str_replace(
        [
            '$this->cart->clear();',
        ],
        [
            '$this->load->model("checkout/order");
      $myOwnData = $this->model_checkout_order->getOrder($this->session->data["order_id"]);
      if ($myOwnData) {
          $data["order_id"] = (int)$myOwnData["order_id"];
          $data["email"] = html_entity_decode($myOwnData["email"], ENT_QUOTES, "UTF-8");
      	}
            $this->cart->clear();',
        ],
        $code
    );

Important!
Of course I have looked at the output as with all my /before and /after hanlder and the code is replaced everywhere as I would like it to be. You helped me in this case a few months agao. But for some reason this way just doesn't work in this success.php. I don't get my desired variables in the checkout.

Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by JNeuhoff » Fri Feb 09, 2024 10:37 pm

Sorry, yes, you are right, the trigger should be for 'catalog/view/common/success/before'.

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


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by trujve » Mon Feb 12, 2024 1:30 am

JNeuhoff wrote:
Fri Feb 09, 2024 10:37 pm
Sorry, yes, you are right, the trigger should be for 'catalog/view/common/success/before'.
OK, thanks so much for checking. And that's exactly my issue. I can not get my needed variables in the checkout althought everything seems to be right :-( it seems that the controller is changed, but it hat no impact on the output.

Is there a chance to track this in any way?
I have tried it with log entry but this also did not work. Maybe i have overseen something major?

Best,
Jack

New member

Posts

Joined
Tue Jul 09, 2019 7:25 pm

Post by straightlight » Mon Feb 12, 2024 3:47 am

trujve wrote:
Mon Feb 12, 2024 1:30 am
JNeuhoff wrote:
Fri Feb 09, 2024 10:37 pm
Sorry, yes, you are right, the trigger should be for 'catalog/view/common/success/before'.
OK, thanks so much for checking. And that's exactly my issue. I can not get my needed variables in the checkout althought everything seems to be right :-( it seems that the controller is changed, but it hat no impact on the output.

Is there a chance to track this in any way?
I have tried it with log entry but this also did not work. Maybe i have overseen something major?

Best,
Jack
Use the debug event to test your triggers.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 3 guests