繁体   English   中英

在评论中显示船旗国

[英]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

现在如何调用它并将Image标志从Image / flag中带出并放置在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 。只需确保您在模板中为标志图像键入正确的值,并且您具有带有此类名称的标志图像...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM