Vote statistics & Report spam

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #69842

Hi,

In the product vote & comments section, is it already possible to achieve the following:

  • Vote Statistics: Display statistics of how many customers vote 1-star, 2-star, 3-star, and so on. (Refer to attached review-1.png)
  • Report Spam: A function for customers to report a comment as spam.(Refer to attached review-2.png)

If it's already achievable with the current version, I would like to know the steps to do it.

Thanks.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #69848

Hi,

You can edit the file "yourSite\components\com_hikashop\`views\product\view.html.php", and in the function "show()" add the code:

		$database = JFactory::getDBO();
		$query = 'SELECT vote_rating FROM '.hikashop_table('vote').' WHERE vote_ref_id = '.$product_id;
		$database->setQuery($query);
		$votes = $database->loadResultArray();
		$config = hikashop_config();
		$total_star = $config->get('vote_star_number');
		$rates = array();
		foreach($votes as $vote){
			for($i=1; $i <= $total_star; $i++){
				if($vote == $i){
					$rates[$i]++;
				}
			}
		}
		for($i=1; $i <= $total_star; $i++){
			if(!isset($rates[$i]) || $rates[$i] == null) $rates[$i] = 0;
		}
		krsort($rates);
		$this->assignRef('rates',$rates);
Just after:
		if(empty($product_id)){
			if (is_object( $menu )) {
				jimport('joomla.html.parameter');
				$category_params = new HikaParameter( $menu->params );
				$product_id = $category_params->get('product_id');
				JRequest::setVar('product_id',$product_id);
			}
		}
		if(empty($product_id)){
			return;
		}

And then in the view "product / show_default" (in HikaShop > Display > Views), you have the variable "$this->rates" which have all the informations for your "vote statistics" point.

For the spam reporting, the functionality is not available for the moment.

Last edit: 12 years 1 month ago by Xavier.

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #69867

Thanks Xavier.

I've added the earlier code for view.html.php.

For the next part to add the variable "$this->rates", I'm not too familiar with what code to add. But is the code supposed to be something like this?

foreach($this->rates as $rates){echo $rates->.......}

The "......." part I'm not too sure what to call from. Are you able to guide on this?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
12 years 1 month ago #70035

You can do like that for example :

foreach($this->rates as $k => $rates){echo $rates.' votes for '.$k.' stars<br/>';}

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
12 years 1 month ago #70179

Thanks for your guidance. The code works well!

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum