簡體   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