문제

I want to show the flag country when customers leaves reviews

I did this:

  • added a row in db table review called country_id
  • in catalog/model/catalog/review.php in public function addReview( I added :
    • , country_id = '" . (int)$this->config->get('config_country_id') . "' so it stores the user's country_id if he is logged in

Now how can I call it and bring the image flag from Image/flag and place in review.tpl?

There is a topic in http://forum.opencart.com/viewtopic.php?t=58425 where nobody could give a solution

Any help?

도움이 되었습니까?

해결책

Now that You have stored the country_id, You can simply load the concrete country based on that id when loading the reviews (for each review, respectively).

When the reviews are loaded from DB, in catalog/controller/product/product.php in method review() the array of results is looped through:

    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']))
        );
    }

Now You only need to load the country to get it's code for flag, so You could end up with something like this:

    $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'
        );
    }

Now the flag index should contain value like de.png, gb.png, fr.png etc. Just make sure You type the right value to the flag images in the template and that You have the flag images with such a names...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top