Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

Recommended Posts

Здравствуйте дорогие гуру!
не смогли бы помочь адаптировать данные коды под опенкарт?

в product.php 

 

	public function videolike() {

	include 'configrating.php';
	
	extract($_POST);
	$user_ip = $_SERVER['REMOTE_ADDR'];

	// check if the user has already clicked on the unlike (merating = 2) or the like (merating = 1)
		$dislike_sql = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE ip = "'.$user_ip.'" and product_id = "'.$product_id.'" and merating = 2 ');
		$dislike_count = mysql_result($dislike_sql, 0); 

		$like_sql = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE ip = "'.$user_ip.'" and product_id = "'.$product_id.'" and merating = 1 ');
		$like_count = mysql_result($like_sql, 0); 

	if($act == 'like'): //if the user click on "like"
		if(($like_count == 0) && ($dislike_count == 0)){
			mysql_query('INSERT INTO rat_ing (product_id, ip, merating )VALUES("'.$product_id.'", "'.$user_ip.'", "1")');
		}
		if($dislike_count == 1){
			mysql_query('UPDATE rat_ing SET merating = 1 WHERE product_id = '.$product_id.' and ip ="'.$user_ip.'"');
		}

	endif;
	if($act == 'dislike'): //if the user click on "like"
		if(($like_count == 0) && ($dislike_count == 0)){
			mysql_query('INSERT INTO rat_ing (product_id, ip, merating )VALUES("'.$product_id.'", "'.$user_ip.'", "2")');
		}
		if($like_count == 1){
			mysql_query('UPDATE rat_ing SET merating = 2 WHERE product_id = '.$product_id.' and ip ="'.$user_ip.'"');
		}

	endif;

	}

 

в product.tpl
 

   <?php
    include 'configrating.php';

    $user_ip = $_SERVER['REMOTE_ADDR'];

    //function to calculate the percent
    function percent($num_amount, $num_total) {
        $count1 = $num_amount / $num_total;
        $count2 = $count1 * 100;
        $count = number_format($count2, 0);
        return $count;
    }

    // check if the user has already clicked on the unlike (merating = 2) or the like (merating = 1)
        $dislike_sql = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE ip = "'.$user_ip.'" and product_id = "'.$product_id.'" and merating = 2 ');
        $dislike_count = mysql_result($dislike_sql, 0); 

        $like_sql = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE ip = "'.$user_ip.'" and product_id = "'.$product_id.'" and merating = 1 ');
        $like_count = mysql_result($like_sql, 0);  

        // count all the merating 
        $merating_all_count = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE product_id = "'.$product_id.'"');
        $merating_all_count = mysql_result($merating_all_count, 0);  

        $merating_like_count = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE product_id = "'.$product_id.'" and merating = 1');
        $merating_like_count = mysql_result($merating_like_count, 0);  
        $merating_like_percent = percent($merating_like_count, $merating_all_count);

        $merating_dislike_count = mysql_query('SELECT COUNT(*) FROM  rat_ing WHERE product_id = "'.$product_id.'" and merating = 2');
        $merating_dislike_count = mysql_result($merating_dislike_count, 0);  
        $merating_dislike_percent = percent($merating_dislike_count, $merating_all_count);
?>
<div class="rat_ing">

<script>
    $(function(){ 
        var product_id = <?php echo $product_id;  ?>; 

        $('.like-btn').click(function(){
            $('.dislike-btn').removeClass('dislike-h');    
            $(this).addClass('like-h');
            $.ajax({
                type:"POST",
                url:"index.php?route=video/video/videolike&product_id=<?php echo $product_id; ?>",
                data:'act=like&product_id='+product_id,
                success: function(){
                }
            });
        });
        $('.dislike-btn').click(function(){
            $('.like-btn').removeClass('like-h');
            $(this).addClass('dislike-h');
            $.ajax({
                type:"POST",
                url:"index.php?route=video/video/videolike&product_id=<?php echo $product_id; ?>",
                data:'act=dislike&product_id='+product_id,
                success: function(){
                }
            });
        });
    });
</script>

			<div class="ld">
                <div class="like-btn <?php if($like_count == 1){ echo 'like-h';} ?>"><?php echo $merating_like_count; ?></div>
                <div class="dislike-btn <?php if($dislike_count == 1){ echo 'dislike-h';} ?>"><?php echo $merating_dislike_count; ?></div>
			</div>

			
			

    </div>

так же былоб хорошо если бы помогли сделать обновление лайков  ибо  количество лайков и дизлайков обновляются только после обновления страницы!

заранее всем спасибо

4d54387cb2.png

Link to post
Share on other sites

так в чем проблема? 2 функции в product.php + аяксом это дергать

Link to post
Share on other sites
1 минуту назад, spectre сказал:

так в чем проблема? 2 функции в product.php + аяксом это дергать

 

если бы в этом разбирался я бы сам его и сделал и не стал писать на форуме!

Link to post
Share on other sites

3 минуты назад, Blackangel861 сказал:

 

если бы в этом разбирался я бы сам его и сделал и не стал писать на форуме!

 

думаю безвозмездно мало кто вам напишет работающий код

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.