What I am trying to do is add a few lines of code to the catalog/controller/checkout/register|save method. (Continue button on the checkout page)
I have no trouble registering the after of before event and my custom method is also triggered.
But when checking the $data in my before or after method it is always an empty array.
Is this maybe because the save method returns a JSON response?
I need to add 2 lines at the bottom of the register|save method to add a redirect to the json response.
What am I missing here?
All my extensions: Click here or Click here
What do you mean with the $data ?
Is it that array handed over from the call?
Or what?
Would help much if you could post your code here.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Yes that is exactly what I mean.
The second argument.
All my extensions: Click here or Click here
Use OCMOD.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
General a bad advice.
I know your agruments Paul, but doing such an easy task with a simple event cost a few minutes only.
And OCMod is here not required.
@Reptile saying it again: post your code here, everything else is "assuming" (and wasting my time).
And write is it a before or after event - that's very important!
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Sorry wasn't at my computer today.OSWorX wrote: ↑Thu Apr 10, 2025 9:51 pmGeneral a bad advice.
I know your agruments Paul, but doing such an easy task with a simple event cost a few minutes only.
And OCMod is here not required.
@Reptile saying it again: post your code here, everything else is "assuming" (and wasting my time).
And write is it a before or after event - that's very important!
But here is the code:
Code: Select all
public function install() {
$this->load->model('setting/event');
$separator = (substr(VERSION, 0, 7) < '4.0.2.0') ? '|' : '.';
$event = [$this->extension_name, 'catalog/controller/checkout/register|save/before', 'extension/' . $this->extension_name . '/module/' . $this->module_name . $separator . 'custom_extenstion', '', 1, true];
if (VERSION == '4.0.0.0') {
$this->model_setting_event->addEvent($event[0], $event[3], $event[1], $event[2], $event[5], $event[4]);
} else {
$this->model_setting_event->addEvent([
'code' => $event[0],
'trigger' => $event[1],
'action' => $event[2],
'description' => $event[3],
'sort_order' => $event[4],
'status' => $event[5]
]);
}
}
Code: Select all
<?php
namespace Opencart\Catalog\Controller\Extension\CustomExtension\Module;
class CustomExtension extends \Opencart\System\Engine\Controller {
public function custom_extension(&$route, &$data) {
$json['redirect'] = $this->url->link('checkout/checkout');
}
}
When I print_r or echo in the CustomExtension controller I can see this in my network tab when the api call is done.
But I can't seem to inject the $json['redirect'] line of code in the checkout/register controller in the save method.
Also tried the after event.
All my extensions: Click here or Click here
Code: Select all
class CustomExtension extends \Opencart\System\Engine\Controller {
public function custom_extension(&$route, &$data) {
$json['redirect'] = $this->url->link('checkout/checkout');
}
}
Such like that would work:
Code: Select all
class CustomExtension extends \Opencart\System\Engine\Controller {
public function custom_extension(&$route, &$data) {
$data['json']['redirect'] = $this->url->link('checkout/checkout');
}
}
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
I understand and I have tried this already.OSWorX wrote: ↑Fri Apr 11, 2025 1:02 amWell, such makes no sense:because you have "only" the $data array to "manipulate" ..Code: Select all
class CustomExtension extends \Opencart\System\Engine\Controller { public function custom_extension(&$route, &$data) { $json['redirect'] = $this->url->link('checkout/checkout'); } }
Such like that would work:Then you can work with the $data['json'] or $json array (depends if $data is used/assigned in/to a template or controller later).Code: Select all
class CustomExtension extends \Opencart\System\Engine\Controller { public function custom_extension(&$route, &$data) { $data['json']['redirect'] = $this->url->link('checkout/checkout'); } }
The $data array is always empty.
Even in the after event.
And when using this:
Code: Select all
$data['json']['redirect'] = $this->url->link('checkout/checkout');
<b>Error</b>
: Unknown named parameter $json in <b>/var/www/oc4000/system/engine/action.php</b>
on line <b>74</b>
And if you look in the checkout/register save method all it does is build up a $json response to output it to the jquery ajax call.
Could it be that there is no $data because the controller is called from the ajax call instead of PHP?
All my extensions: Click here or Click here
Code: Select all
public function customExtension(string &$route, array &$data, mixed &$output) {
// Load the controller as the $data array will always be empty if the controllers is called through an ajax call
$this->load->controller('checkout/register');
// Get the json array
$json = json_decode($this->response->getOutput(),true);
// Add a value to the json array
$json['redirect'] = $this->url->link('checkout/checkout');
// Update the output
$this->response->setOutput(json_encode($json));
}
All my extensions: Click here or Click here
Users browsing this forum: No registered users and 3 guests