使用 OCMOD xml 将主页重定向到产品页面 Opencart 3.0.3.6 或 3.0.3.7

问题描述

我正在尝试在 opencart 中重定向主页目录/控制器/common/home.PHP。 在 PHP 文件中,此行 public function index() { 之后和此行之前 $this->config->get('config_Meta_title'));当我添加 $this->response->redirect($this->url->link('product/product','product_id=50'));当用户访问 opencart 主页时,它会重定向并工作。我需要创建 OCMOD 文件来实现相同的功能,而无需修改PHP 文件中的核心代码。另外我不想使用 htaccess 重定向。我尝试了下面的代码但没有工作。我对 XML 或 PHP 不太了解。因此请帮忙。我试过的 OCMOD 代码如下:

<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>

请帮忙。谢谢并恭祝安康 VSR

解决方法

那里不是ocmod。这是 vqmod。 OCMOD 在这里:

<?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>

并仔细检查 ocmod 搜索标签中的字符串... if (isset($this->document->setTitle($this->config->get('config_meta_title'));'])) { 是否正确?好像字符串不对。

编辑您的评论:

 <?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>