0

I am trying to redirect home page catalog/controller/common/home.php in opencart. In the php file, after this line public function index() { and before this line $this->config->get('config_meta_title')); When I add $this->response->redirect($this->url->link('product/product', 'product_id=50')); it redirects and works when a user visits opencart home page. I need to create OCMOD file to achieve the same thing without modifying the core code in this php file. Also I don't want to use htaccess redirect. I tried the below code but not working. I am not that much knowledgable in XML or PHP. hence please help. The OCMOD code I tried is below:

<name>Product page as home page</name>
<id>Product page as home page</id>
<version>1.0.0</version>
<code>Product page as home page</code>
<author>test</author>
<link>#</link>  

<file path="catalog/controller/common/home.php">
    
             <operation>
        <search><![CDATA[if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) {]]></search>
        <add position="before"><![CDATA[
    $this->response->redirect($this->url->link('product/product', 'product_id=50'));
        ]]></add>
    </operation>
</file>

Please help. Thanks and regards VSR

VSR
  • 23
  • 5

1 Answers1

0

There it is not ocmod. this is vqmod. OCMOD here:

<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>Product page as home page</name>
<version>1.0.0</version>
<code>Product page as home page</code>
<author>test</author>
<link>#</link>  

<file path="catalog/controller/common/home.php">
    
    <operation>
        <search><![CDATA[if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) {]]></search>
        <add position="before"><![CDATA[
    $this->response->redirect($this->url->link('product/product', 'product_id=50'));
        ]]></add>
    </operation>
</file>
</modification>

And carefully check your string which is in the ocmod search tag... if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) { it is correct? Seems the string is incorrect.

EDITED regarding your comment:

 <?xml version="1.0" encoding="UTF-8"?>
    <modification>
    <name>Product page as home page</name>
    <version>1.0.0</version>
    <code>Product page as home page</code>
    <author>test</author>
    <link>#</link>  
    
    <file path="catalog/controller/common/home.php">
    
        <operation>
            <search><![CDATA[public function index() {]]></search>
            <add position="after"><![CDATA[
        $this->response->redirect($this->url->link('product/product', 'product_id=50'));
            ]]></add>
        </operation>
    </file>
    </modification>
K. B.
  • 1,388
  • 2
  • 13
  • 25
  • Thank you K.B for this. I tried you modified code, still not working. I tried to removeing '{" in the above code, but not working. Please see the below home.php code: public function index() { $this->document->setTitle($this->config->get('config_meta_title')); this code: $this->response->redirect($this->url->link('product/product', 'product_id=50')); must be placed dynamically after public function index() { and before $this->document->setTitle($this->config->get('config_meta_title')); – VSR Feb 16 '21 at 06:08
  • I have edited on your comment. Please check it now. – K. B. Feb 16 '21 at 08:43
  • Hi K.B. I tried your edited Code. But the home page is not redirecting. The very same code I also tried earlier. It was not working. How to dynamically insert $this->response->redirect($this->url->link('product/product', 'product_id=50')); in home.php at that particular place Using OCMOD? When that code is manually added in home.php, it redirects correctly. But could not do this with OCMOD. If you could help further, it would nice. Thanks – VSR Feb 16 '21 at 11:12
  • Seems I have made an mistake also. Try now "EDITED". I have edited my code again. – K. B. Feb 16 '21 at 13:11
  • Hi K.B Works Perfectly now. Excellent. Thanks. – VSR Feb 16 '21 at 13:34
  • I have marked K.B.s answer as useful, for the code that appears below " EDITED regarding your comment:" which is based on my 2nd comment. There is one code above this EDITED line, which is based on my 1st comment did not work. The 2nd code works perfectly. – VSR Feb 18 '21 at 04:57