【问题标题】:How to duplicate product template in opencart如何在opencart中复制产品模板
【发布时间】:2012-05-30 14:06:37
【问题描述】:

我对 opencart 很陌生,但我认为这是最简单且最好的解决方案。虽然玩模板不是一件乐事……

我正在努力创建一些额外的模板页面。例如,我有两种类型的产品和类别页面。我想为不同的产品使用不同的模板。在 opencart 中,您只有一种产品布局。

我想做的是复制产品布局。我在网上得到了一些帮助,但我仍然不确定还需要什么。这就是我到目前为止所做的......

1 - 复制catalog/controller/product/product.php 的控制器文件并更改为catalog/controller/product/product-2.php。然后我在控制器中改变了这个:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product-2.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/product/product-2.tpl';
    } else {
        $this->template = 'default/template/product/product-2.tpl';
        }

2 - 然后我复制了产品语言文件并保存为 product-2

3 - 之后我复制了实际的 tpl 文件并保存为 product-2

看起来不错,但如果我尝试对 product-2.tpl 进行一些更改,则没有任何变化。是否需要复制更多文件才能完成?

【问题讨论】:

标签: opencart


【解决方案1】:

在搜索并进行大量研究和令人难以置信之后,我找到了一种非常有用的方法来做我想做的事。通过这种方式,我可以完全控制 opencart 主题系统。我可以根据需要制作尽可能多的不同布局。我不必使用 VQmod 也不必制作任何控制器,但您必须使用现有的控制器,如产品、类别等。如果您正在制作自己的控制器,即使它可以工作。

以下是为不同类别、产品和常用页面实现不同模板的步骤。

我在这里做产品的例子。 1-在主题的产品文件夹中创建产品的自定义模板。例如 customproduct.tpl 2-现在根据需要自定义它。创建一个产品并获取它的 id。 id在这里很重要。 3-进入控制器目录/controller/product/product.php 4-找到这个代码

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
  $this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
            } else {
    $this->template = 'default/template/product/product.tpl';
            }

5- 现在你必须使用简单的 if else 条件。例如

//42 is the id of the product 
 if($this->request->get['product_id'] == 42){
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/customproduct.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/customproduct.tpl';
            } else {
                $this->template = 'default/template/product/customproduct.tpl';
            }
        }
        else{
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
            } else {
                $this->template = 'default/template/product/customproduct.tpl';
            }
        }

就这样完成了;) 你可以对其他控制器做同样的事情。

【讨论】:

    【解决方案2】:

    如您所见;

    http://pranshuarya.com/jaal/Development/opencart-creating-a-new-viewtemplate.html

    这是“全新布局”请求的真正解决方案的第二个选项。 两者都可以使用。如果您不需要新的控制器例程,您的解决方案可以节省时间。但这种方式更灵活。

    这里是步骤;

    • 将新的控制器文件添加到 /catalog/controller。如果已经有类似的控制器,请调用类似 new_layout.php... 的内容。请务必按照我在下面的评论中所述更改控制器名称。

    • 在您的主题文件夹中添加一个新的视图文件......如果您希望可以复制类似的视图文件内容并根据需要进行修改,可以像控制器一样。

    • 从管理面板 System/Design/Layouts 或直接从 MYSQL 表添加新布局,如上面链接中所述。

    • 现在好了。只需在此布局视图中添加一些模块即可享受。

    【讨论】:

    • 我现在处理了解决方法......要添加一点点......您还必须将控制器名称更改为 - 例如,如果您的新布局名称是 Campaigns,则从 ControllerProductProduct 更改为 ControllerProductCampaigns-跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多