Post by Screwball » Tue Apr 10, 2012 11:59 am

Can anyone tell me how I would go about adding a 'country' field for when customers are adding their product review? Ideally I would like the field to be positioned under the 'Name' field.

New member

Posts

Joined
Tue Apr 10, 2012 11:26 am

Post by Avvici » Tue Apr 10, 2012 1:34 pm

You will need to hire someone to custom code that for you. Even though it's not a lot of work at all....there is no extension for that. The code is already there for you on certain parts of the website you just need to translate it to the reviews form, add the appropriate field(s) to the review table, and adjust the INSERT query to insert the value.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by gal_op » Thu Aug 02, 2012 4:47 pm

Hi There,

I am also looking for a way doing that. I have a good understanding in PHP and familiar with OpenCart framework.
Any kind of help will be appreciated.

Thanks,

Gal Opatovsky - Web Designer
http://www.vibesdesign.com.au
http://www.themineralmiracle.com.au


Newbie

Posts

Joined
Sat May 26, 2012 10:11 am

Post by Avvici » Sat Aug 04, 2012 11:40 am

Open: /catalog/view/theme/your_theme/template/product/product.tpl and find this line:

Code: Select all

<input type="text" name="name" value="" />
Directly below that add this:

Code: Select all

 <br />

    <br />
<b>Country:</b> <br /><select name="country_id">   
              <option value="">Select</option>
             <?php foreach ($countries as $country) { ?>
              
              <option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
             
              <?php } ?>
            </select>
And now find this:

Code: Select all

data: 'name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()),
Replace it with this:

Code: Select all

data: 'country_id=' + encodeURIComponent($('select[name=\'country_id\']').val()) + '&name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()),

Now open catalog/model/catalog/reveiw.php and find this code:

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['name']) . "', customer_id = '" . (int)$this->customer->getId() . "', product_id = '" . (int)$product_id . "', text = '" . $this->db->escape($data['text']) . "', rating = '" . (int)$data['rating'] . "', date_added = NOW()");
Replace that with this:

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['name']) . "', customer_id = '" . (int)$this->customer->getId() . "', product_id = '" . (int)$product_id . "', text = '" . $this->db->escape($data['text']) . "', country_id = '" . (int)$data['country_id'] . "', rating = '" . (int)$data['rating'] . "', date_added = NOW()");
Now open: catalog/controller/product/product.php and find this line:

Code: Select all

public function index() { 
Directly below that add this:

Code: Select all

$this->load->model('localisation/country');
		
    	$this->data['countries'] = $this->model_localisation_country->getCountries();
BACK UP YOUR DATABASE. Open up your database in phpmyadmin and click on the SQL tab. Paste this code and run the command by pressing GO.

Code: Select all

ALTER TABLE `review` ADD `country_id` INT( 8 ) NOT NULL  
So there you have it. You now need to take the country codes from that field and run the function that will display the country name as a part of the reviews in the admin. You will set it up like I did here: with the control, model, and view.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by gal_op » Sat Aug 04, 2012 1:28 pm

Thanks avvici,

This is great, I am sure other users will also use that as a guide for adding different fields to the standard review form.

Gal Opatovsky - Web Designer
http://www.vibesdesign.com.au
http://www.themineralmiracle.com.au


Newbie

Posts

Joined
Sat May 26, 2012 10:11 am

Post by Avvici » Sun Aug 05, 2012 3:14 am

If you need help setting up the administration portion just let me know I can post that as well.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by allenshea » Sun Aug 05, 2012 6:57 am

Hi, Avvici, How can we change text country to Icon flag? Thanks!

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm

Post by Avvici » Sun Aug 05, 2012 8:01 am

You mean the icon for the store country?

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by allenshea » Sun Aug 05, 2012 1:24 pm

avvici wrote:You mean the icon for the store country?
Yes, the one in 'image\flags\'.

Can not find the way to make it. It would be great appreciated if you can help. Thanks!

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm

Post by Avvici » Sun Aug 05, 2012 8:20 pm

Uh, there are many flags. Do you want your home country flag in place of the text "Country: ?"

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by allenshea » Sun Aug 05, 2012 8:54 pm

avvici wrote:Uh, there are many flags. Do you want your home country flag in place of the text "Country: ?"

No, the country flag for customer.

Your code can show the country name in text, but if you can change it to country flag instead of country text would be great. Hope you can understand it.

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm

Post by frankleng » Sat Sep 01, 2012 8:18 am

searching for same thing. thanks.

Active Member

Posts

Joined
Sun Apr 22, 2012 5:49 pm

Post by frankleng » Sat Sep 01, 2012 8:22 am

allenshea wrote:
avvici wrote:Uh, there are many flags. Do you want your home country flag in place of the text "Country: ?"

No, the country flag for customer.

Your code can show the country name in text, but if you can change it to country flag instead of country text would be great. Hope you can understand it.
Right.

Active Member

Posts

Joined
Sun Apr 22, 2012 5:49 pm

Post by frankleng » Fri Sep 14, 2012 1:14 pm

this is a half bridge, without the admin part, the country name still can not be shown on reviews page. : (

Active Member

Posts

Joined
Sun Apr 22, 2012 5:49 pm
Who is online

Users browsing this forum: No registered users and 40 guests