Question

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?

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top