我想在客户留下评论时显示船旗国
我这样做了:
- 在数据库表审查中添加了一个名为
country_id
的行 - 在
catalog/model/catalog/review.php
public function addReview(
中,我补充说:-
, country_id = '" . (int)$this->config->get('config_country_id') . "'
,以便在用户登录时存储用户的country_id
-
现在我该如何调用它并从图像/标志中引入图像标志并放置在review.tpl
中?
http://forum.opencart.com/viewtopic.php?t=58425 有一个话题,没有人能给出解决方案
有什么帮助吗?
现在您已经存储了country_id
,您可以在加载评论时简单地根据该 id 加载具体国家/地区(分别针对每个评论)。
从数据库加载评论时,在方法review()
中catalog/controller/product/product.php
结果数组循环遍历:
foreach ($results as $result) {
$this->data['reviews'][] = array(
'author' => $result['author'],
'text' => $result['text'],
'rating' => (int)$result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
现在你只需要加载国家/地区来获取它的标志代码,所以你最终可能会得到这样的东西:
$this->load->model('localisation/country');
foreach ($results as $result) {
$country = $this->model_localisation_country->getCountry($result['country_id']);
$this->data['reviews'][] = array(
'author' => $result['author'],
'text' => $result['text'],
'rating' => (int)$result['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'flag' => strtolower($country['iso_code_2']) . '.png'
);
}
现在flag
索引应该包含de.png
、gb.png
、fr.png
等值。只需确保您为模板中的标志图像键入正确的值,并且您拥有具有此类名称的标志图像......