Simple modification to OpenCart theme

人走茶凉 提交于 2019-12-12 01:16:11

问题


I'm using the Shoppica theme with OpenCart. I'd like to make a modification to the category page. It gives a description (which I entered in the backend) and than a list of products follow.

In category.tpl it says:

<?php if ($description) echo $description; ?>

But I'd like to have an extra description, let's call it description2. This should come AFTER the list of products. In PhpMyAdmin I added another row in *oc_category_description* and called it description2 Manually (so in PhpMyAdmin) I filled this with text.

Now I placed the following in the category.tpl file:

<?php if ($description2) echo $description2; ?>

But now I receive an error:

undefined variable: description2 in /home/.../public_html/catalog/view/theme/shoppica2/template/product/category.tpl on line 187

Any idea, what I did wrong. Do I need to declare it somewhere else (in another file? where?)


回答1:


There is need of understanding of the MVC pattern which is OpenCart built in.

Briefly - You have a Model class that interacts with the database, a Controller class that operates above and calls Model methods (data retrieval, data update, data insertion) and pass the output to the brwoser while it is processed by the View (should be another class but OpenCart has only like MC - Model-Controller part with template files).

So to Your problem: You have to modify catalog/model/catalog/category.php and look for method called getCategory that retrieves the concrete category data. Here in select query should be select * from ... - if it is so, everything is OK, but if it is like select category_id, category_description, ... from ... then You have to add Your new field here as well (sorry, I do not remember the SQL queries from OpenCart).

Additionaly edit the catalog/controller/product/category.php and look for the part where the category data is controlled (the category model is called) or look for line that starts with $this->data['description'] = ...; and add Your new field here, like $this->data['description2'] = ...;.

Hope this will help.



来源:https://stackoverflow.com/questions/13401924/simple-modification-to-opencart-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!