And I finnaly worked out how to change the HTML of a view.
The only thing I can't figure out is how to change the data in another controller with an event.
What I did so far is made an after event which changes the view of the invoice.
Now I need to add more code to the controller sale/order and in the function invoice.
This because I need the data for the view.
I tried to do this with a before event but I don't know how to add code to the invoice function.
Can anyone point me in the right direction?
All my extensions: Click here or Click here
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Yes this I understand but this will mean that I have to copy the complete contents of the invoice function from the sale/order controller.
This does work.
But doesn't seems logical to do.
It would be nice if I could somehow access this data and use it in the handler for my trigger.
All my extensions: Click here or Click here
There's no need to copy the entire invoice method. Which is why Event Triggers are used so that it can be expanded from the same method rather than duplicating it while coding on another extension module file, for instance.Reptile wrote: ↑Mon Apr 24, 2023 12:45 amYes this I understand but this will mean that I have to copy the complete contents of the invoice function from the sale/order controller.
This does work.
But doesn't seems logical to do.
It would be nice if I could somehow access this data and use it in the handler for my trigger.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
So how would you read the data then?straightlight wrote: ↑Mon Apr 24, 2023 1:35 amThere's no need to copy the entire invoice method. Which is why Event Triggers are used so that it can be expanded from the same method rather than duplicating it while coding on another extension module file, for instance.Reptile wrote: ↑Mon Apr 24, 2023 12:45 amYes this I understand but this will mean that I have to copy the complete contents of the invoice function from the sale/order controller.
This does work.
But doesn't seems logical to do.
It would be nice if I could somehow access this data and use it in the handler for my trigger.
I tried before and after but the data array is always empty in the trigger handler.
All my extensions: Click here or Click here
You must understand one truth when dealing with events. Events are only for changing input/output data. They do not work inside processed entities.
My FREE extensions in marketplace. [ security | flexibility | speedup ]
You'd need to post your Event Trigger code in order for the support users to take a look.Reptile wrote: ↑Mon Apr 24, 2023 4:29 amSo how would you read the data then?straightlight wrote: ↑Mon Apr 24, 2023 1:35 amThere's no need to copy the entire invoice method. Which is why Event Triggers are used so that it can be expanded from the same method rather than duplicating it while coding on another extension module file, for instance.Reptile wrote: ↑Mon Apr 24, 2023 12:45 am
Yes this I understand but this will mean that I have to copy the complete contents of the invoice function from the sale/order controller.
This does work.
But doesn't seems logical to do.
It would be nice if I could somehow access this data and use it in the handler for my trigger.
I tried before and after but the data array is always empty in the trigger handler.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Code: Select all
public function install() {
$this->load->model('setting/event');
$this->model_setting_event->addEvent([
'code' => $this->extension_name,
'trigger' => 'admin/view/sale/order_invoice/after',
'action' => 'extension/custominvoice/module/custom_invoice.invoice',
'description' => '',
'sort_order' => 1,
'status' => true
]);
}
Code: Select all
public function invoice(string &$route, array &$data, mixed &$output): void {
$data['cio'] = $this->model_setting_setting->getSetting('module_' . $this->module_name, $this->store_id);
if (isset($data['cio']['module_custom_invoice_status']) && $data['cio']['module_custom_invoice_status']) {
$data['ip'] = $order_info['ip']; // Need the IP but don't have access to $order_info as this is inside the sale/order controller invoice method
$module = $this->load->view('extension/custominvoice/cio/order_invoice', $data);
$output = preg_replace("/<html\s(.+?)>(.+?)<\/html>/is", $module, $output);
}
}
But I want to do this now only through the event system.
All my extensions: Click here or Click here
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
At the top you can only see the saved data for the invoice.straightlight wrote: ↑Mon Apr 24, 2023 9:06 pmIf you print_r the $data array directly from your method, does it output the array that includes your custom invoice?
And below that a whole lot of what looks like the view translation files.
Here is a small part of the print_r:
Code: Select all
Array ( [title] => Invoice [base] => https://www.fakedomain.com/admin/ [direction] => ltr [lang] => en [bootstrap_css] => view/stylesheet/bootstrap.css [icons] => view/stylesheet/fonts/fontawesome/css/all.min.css [stylesheet] => view/stylesheet/stylesheet.css [jquery] => view/javascript/jquery/jquery-3.6.1.min.js [bootstrap_js] => view/javascript/bootstrap/js/bootstrap.bundle.min.js [orders] => Array ( [0] => Array ( [order_id] => 1 [invoice_no] => INV-2023-001 [date_added] => 21/04/2023 [store_name] => Your Store [store_url] => https://www.fakedomain.com [store_address] => Address 1 [store_email] => noreply@email.com [store_telephone] => 123456789 [email] => ddd@ddd.com [telephone] => [shipping_address] => ddd ddd
ddd
ddd, Aberdeen ddd
United Kingdom [shipping_method] => Flat Shipping Rate [payment_address] => [payment_method] => Cash On Delivery [product] => Array ( [0] => Array ( [name] => iPhone [model] => product 11 [option] => Array ( ) [subscription] => [quantity] => 1 [price] => $123.20 [total] => $123.20 ) [1] => Array ( [name] => MacBook [model] => Product 16 [option] => Array ( ) [subscription] => [quantity] => 1 [price] => $602.00 [total] => $602.00 ) [2] => Array ( [name] => Canon EOS 5D [model] => Product 3 [option] => Array ( [0] => Array ( [name] => Select [value] => Blue ) ) [subscription] => [quantity] => 1 [price] => $98.00 [total] => $98.00 ) ) [voucher] => Array ( ) [total] => Array ( [0] => Array ( [title] => Sub-Total [text] => $681.00 ) [1] => Array ( [title] => Flat Shipping Rate [text] => $5.00 ) [2] => Array ( [title] => Eco Tax (-2.00) [text] => $8.00 ) [3] => Array ( [title] => VAT (20%) [text] => $137.20 ) [4] => Array ( [title] => Total [text] => $831.20 ) ) [comment] => ) ) [code] => en [date_format_short] => d/m/Y [date_format_long] => l jS F Y [time_format] => h:i:s A [datetime_format] => d/m/Y H:i:s [decimal_point] => . [thousand_point] => , [text_yes] => Yes [text_no] => No [text_on] => On [text_off] => Off [text_enabled] => Enabled [text_disabled] => Disabled [text_none] => --- None --- [text_select] => --- Please Select --- [text_select_all] => Select All [text_all] => All [text_unselect_all] => Unselect All [text_all_zones] => All Zones [text_default] => Default [text_close] => Close [text_pagination] => Showing %d to %d of %d (%d Pages) [text_loading] => Loading... [text_no_results] => No results! [text_confirm] => Are you sure? [text_home] => Home [text_second_ago] => just now [text_seconds_ago] => %s seconds ago [text_minute_ago] => %s minute ago [text_minutes_ago] => %s minutes ago [text_hour_ago] => %s hour ago [text_hours_ago] => %s hours ago [text_day_ago] => %s day ago [text_days_ago] => %s days ago [text_week_ago] => %s week ago [text_weeks_ago] => %s weeks ago [text_month_ago] => %s month ago [text_months_ago] => %s months ago [text_year_ago] => %s year ago [text_years_ago] => %s years ago [button_add] => Add New [button_delete] => Delete [button_save] => Save [button_cancel] => Cancel [button_subscription_cancel] => Cancel Subscription [button_continue] => Continue [button_confirm] => Confirm [button_clear] => Clear [button_close] => Close [button_enable] => Enable [button_disable] => Disable [button_filter] => Filter [button_send] => Send [button_edit] => Edit [button_copy] => Copy [button_back] => Back [button_remove] => Remove [button_refresh] => Refresh [button_export] => Export [button_import] => Import [button_download] => Download [button_rebuild] => Rebuild [button_upload] => Upload [button_submit] => Submit [button_invoice_print] => Print Invoice [button_shipping_print] => Print Shipping List [button_address_add] => Add Address [button_attribute_add] => Add Attribute [button_banner_add] => Add Banner [button_custom_field_value_add] => Add Custom Field [button_product_a
All my extensions: Click here or Click here
You won't see other variables than $data or $json in the event controllers. For that, you need to re-query it.Reptile wrote: ↑Mon Apr 24, 2023 9:54 pmAt the top you can only see the saved data for the invoice.straightlight wrote: ↑Mon Apr 24, 2023 9:06 pmIf you print_r the $data array directly from your method, does it output the array that includes your custom invoice?
And below that a whole lot of what looks like the view translation files.
Here is a small part of the print_r:I don't see variables like $order_info for example.Code: Select all
Array ( [title] => Invoice [base] => https://www.fakedomain.com/admin/ [direction] => ltr [lang] => en [bootstrap_css] => view/stylesheet/bootstrap.css [icons] => view/stylesheet/fonts/fontawesome/css/all.min.css [stylesheet] => view/stylesheet/stylesheet.css [jquery] => view/javascript/jquery/jquery-3.6.1.min.js [bootstrap_js] => view/javascript/bootstrap/js/bootstrap.bundle.min.js [orders] => Array ( [0] => Array ( [order_id] => 1 [invoice_no] => INV-2023-001 [date_added] => 21/04/2023 [store_name] => Your Store [store_url] => https://www.fakedomain.com [store_address] => Address 1 [store_email] => noreply@email.com [store_telephone] => 123456789 [email] => ddd@ddd.com [telephone] => [shipping_address] => ddd ddd ddd ddd, Aberdeen ddd United Kingdom [shipping_method] => Flat Shipping Rate [payment_address] => [payment_method] => Cash On Delivery [product] => Array ( [0] => Array ( [name] => iPhone [model] => product 11 [option] => Array ( ) [subscription] => [quantity] => 1 [price] => $123.20 [total] => $123.20 ) [1] => Array ( [name] => MacBook [model] => Product 16 [option] => Array ( ) [subscription] => [quantity] => 1 [price] => $602.00 [total] => $602.00 ) [2] => Array ( [name] => Canon EOS 5D [model] => Product 3 [option] => Array ( [0] => Array ( [name] => Select [value] => Blue ) ) [subscription] => [quantity] => 1 [price] => $98.00 [total] => $98.00 ) ) [voucher] => Array ( ) [total] => Array ( [0] => Array ( [title] => Sub-Total [text] => $681.00 ) [1] => Array ( [title] => Flat Shipping Rate [text] => $5.00 ) [2] => Array ( [title] => Eco Tax (-2.00) [text] => $8.00 ) [3] => Array ( [title] => VAT (20%) [text] => $137.20 ) [4] => Array ( [title] => Total [text] => $831.20 ) ) [comment] => ) ) [code] => en [date_format_short] => d/m/Y [date_format_long] => l jS F Y [time_format] => h:i:s A [datetime_format] => d/m/Y H:i:s [decimal_point] => . [thousand_point] => , [text_yes] => Yes [text_no] => No [text_on] => On [text_off] => Off [text_enabled] => Enabled [text_disabled] => Disabled [text_none] => --- None --- [text_select] => --- Please Select --- [text_select_all] => Select All [text_all] => All [text_unselect_all] => Unselect All [text_all_zones] => All Zones [text_default] => Default [text_close] => Close [text_pagination] => Showing %d to %d of %d (%d Pages) [text_loading] => Loading... [text_no_results] => No results! [text_confirm] => Are you sure? [text_home] => Home [text_second_ago] => just now [text_seconds_ago] => %s seconds ago [text_minute_ago] => %s minute ago [text_minutes_ago] => %s minutes ago [text_hour_ago] => %s hour ago [text_hours_ago] => %s hours ago [text_day_ago] => %s day ago [text_days_ago] => %s days ago [text_week_ago] => %s week ago [text_weeks_ago] => %s weeks ago [text_month_ago] => %s month ago [text_months_ago] => %s months ago [text_year_ago] => %s year ago [text_years_ago] => %s years ago [button_add] => Add New [button_delete] => Delete [button_save] => Save [button_cancel] => Cancel [button_subscription_cancel] => Cancel Subscription [button_continue] => Continue [button_confirm] => Confirm [button_clear] => Clear [button_close] => Close [button_enable] => Enable [button_disable] => Disable [button_filter] => Filter [button_send] => Send [button_edit] => Edit [button_copy] => Copy [button_back] => Back [button_remove] => Remove [button_refresh] => Refresh [button_export] => Export [button_import] => Import [button_download] => Download [button_rebuild] => Rebuild [button_upload] => Upload [button_submit] => Submit [button_invoice_print] => Print Invoice [button_shipping_print] => Print Shipping List [button_address_add] => Add Address [button_attribute_add] => Add Attribute [button_banner_add] => Add Banner [button_custom_field_value_add] => Add Custom Field [button_product_a
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Isn't it possible to use a second event trigger to modify the sale/order controller invoice method to insert the extra variables?You won't see other variables than $data or $json in the event controllers. For that, you need to re-query it.
Just like I would do with VQMod?
I already tried it but I might be doing this wrong.
How would one do this?
You can't use str_replace as these are variables and not considered as strings right?
All my extensions: Click here or Click here
To add new array keys, you could use: array_merge or array_merge_recursive with your $order_info . As for str_replace, with an array, you could also use: array_replace . See php.net for more information by using Google about those functions. Alternatively, you could also use: array_push .Reptile wrote: ↑Mon Apr 24, 2023 10:25 pmIsn't it possible to use a second event trigger to modify the sale/order controller invoice method to insert the extra variables?You won't see other variables than $data or $json in the event controllers. For that, you need to re-query it.
Just like I would do with VQMod?
I already tried it but I might be doing this wrong.
How would one do this?
You can't use str_replace as these are variables and not considered as strings right?
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
straightlight wrote: ↑Mon Apr 24, 2023 10:35 pmTo add new array keys, you could use: array_merge or array_merge_recursive with your $order_info . As for str_replace, with an array, you could also use: array_replace . See php.net for more information by using Google about those functions. Alternatively, you could also use: array_push .Reptile wrote: ↑Mon Apr 24, 2023 10:25 pmIsn't it possible to use a second event trigger to modify the sale/order controller invoice method to insert the extra variables?You won't see other variables than $data or $json in the event controllers. For that, you need to re-query it.
Just like I would do with VQMod?
I already tried it but I might be doing this wrong.
How would one do this?
You can't use str_replace as these are variables and not considered as strings right?
Thanks for the tips.
I will play around with that.
All my extensions: Click here or Click here
Now that the issue has been resolved, please add: [SOLVED] at the beginning of the subject line on your first post.Reptile wrote: ↑Mon Apr 24, 2023 10:55 pmstraightlight wrote: ↑Mon Apr 24, 2023 10:35 pmTo add new array keys, you could use: array_merge or array_merge_recursive with your $order_info . As for str_replace, with an array, you could also use: array_replace . See php.net for more information by using Google about those functions. Alternatively, you could also use: array_push .Reptile wrote: ↑Mon Apr 24, 2023 10:25 pm
Isn't it possible to use a second event trigger to modify the sale/order controller invoice method to insert the extra variables?
Just like I would do with VQMod?
I already tried it but I might be doing this wrong.
How would one do this?
You can't use str_replace as these are variables and not considered as strings right?
Thanks for the tips.
I will play around with that.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 2 guests