Opencart 在评论中显示船旗国


Opencart Show the flag country in reviews

我想在客户留下评论时显示船旗国

我这样做了:

  • 在数据库表审查中添加了一个名为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.pnggb.pngfr.png等值。只需确保您为模板中的标志图像键入正确的值,并且您拥有具有此类名称的标志图像......