Joomla has great plugin system that allows you to manipulate the variables to able to re-route the result of page.
Seems not works on Joomla 4 and VM 4.
Create a plugin and place code at onAfterInitialise() event
$this->app->input->set('option','com_virtuemart');
$this->app->input->set('view','productdetails');
$this->app->input->set('virtuemart_product_id',1);
All pages to load specific specific view
Core variables option, view , task not manipulated!
Seems like stores in OBJECT the vars in the framework load
Setting Value
PHP Built On Linux server.linux91.papaki.gr 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
Database Type mysql
Database Version 10.3.37-MariaDB
Database Collation utf8_general_ci
Database Connection Collation utf8mb4_general_ci
Database Connection Encryption None
Database Server Supports Connection Encryption No
PHP Version 7.4.33
Web Server Apache
WebServer to PHP Interface cgi-fcgi
Joomla! Version Joomla! 4.2.5 Stable [ Uaminifu ] 8-November-2022 15:00 GMT
User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Title |
|
onAfterInitialise() is called before onAfterRoute().
The onAfterRoute has already loaded the non-desired view/component
I don't know how onAfterRoute has already loaded the non-desired view/component. On my quick test, I used the code like this:
public function onAfterRoute()
{
if ($this->app->isClient('site'))
{
$this->app->input->set('option', 'com_contact');
$this->app->input->set('view', 'category');
$this->app->input->set('id', 4);
$this->app->input->set('layout', 'default');
}
}
And that loads category view of category with ID = 4 in com_contact. So onAfterRoute()
works well for me. I can use that event to route to the component/view I want.
On Joomla 1.5 up to 3.x the onAfterInitialise() worked for me.
I don't know if has any issue the specific component I am trying (virtuemart)
I will do my tests and I will come back with the results
I will have to check it again but I remember I read somewhere that in Joomla 3, Joomla Input object use $_REQUEST as reference, so any modification to Joomla input object will affect data from $_REQUEST.
On Joomla 4, $_REQUEST is not passed by reference to input object anymore, so modify Joomla input object won't make change to $_REQUEST.
With that said, if VM for some reasons, uses data from $_REQUEST instead of using data from Joomla input object, the change won't have any affect.
(Haven't looed at VM from long time ago, so I can just guess)
As for modify routing variables like in this example, I believe onAfterRoute
is the right event to use.
Hope you will figure out and come up with a solution.
Closing because this is a none core issue. Feel free to re-open if you have something want to discuss further.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-11-29 07:25:19 |
Closed_By | ⇒ | joomdonation |
Shouldn't you use
onAfterRoute
instead ?