Author Topic: HACK: add product counter by product  (Read 10166 times)

Creb

  • Beginner
  • *
  • Posts: 18
HACK: add product counter by product
« on: July 05, 2010, 11:42:46 am »
Helo, I add counter to view product.
Instruction:
Create new field in jos_vm_product table
Code: [Select]
ALTER TABLE `jos_vm_product` ADD `product_counter` INT( 11 ) NOT NULL
change jos_ prefix to You database prefix.

In administrator/components/com_virtuemart/html/shop.product_details.php
add after
Code: [Select]
$recent_products = $ps_product->recentProducts($product_id,$tpl->get_cfg('showRecent', 5)); about line 382
Code: [Select]

// product_counter by Creb

// set cookie to 1 hour
$ip=$_SERVER['REMOTE_ADDR'];
//$ip_local = $_SERVER['HTTP_X_FORWARDED_FOR'];
setcookie("ip_addr", $ip, time()+3600);

// check cookie
if($_COOKIE['ip_addr']){;
// if cookie exists print counter

$product_counter = (int)$db_product->f("product_counter");
//$product_counter .= $ip . " " . $ip_local;
}else{

// if cookie not exists add to database
$product_counter = (int)$db_product->f("product_counter");
$product_counter_new = $product_counter + 1;

$q = "UPDATE #__{vm}_product SET product_counter = '$product_counter_new' WHERE product_id = '$product_id' LIMIT 1 ";
$db->query( $q );

}
// end product_counter by Creb
I add cookie, becouse I nedd for catalog only, and prepare module most viewed.

If You need to see counter on flypage - add template declaration.
Before line:
Code: [Select]
/* Finish and Print out the Page */
echo $tpl->fetch( '/product_details/'.$flypage . '.php' );

add:
Code: [Select]
// Counter by Creb http://forum.virtuemart.net/index.php?topic=72913.0
$tpl->set("product_counter", $product_counter);
// end counter by Creb
On flypage:
Code: [Select]
<?php echo $product_counter ?>sorry for my english :)
Creb


erick_alcala

  • Jr. Member
  • **
  • Posts: 155
  • Everything is Possible!
    • Ofix-Comp
Re: HACK: add product counter by product
« Reply #1 on: July 07, 2010, 00:36:02 am »
what do you mean by product counter??.. is this like the product ID? it counts for example  I have 1058 products, if I add another one the next number will be product #1059 ?? or what?
wanting to learn to create good templates

Creb

  • Beginner
  • *
  • Posts: 18
Re: HACK: add product counter by product
« Reply #2 on: July 07, 2010, 00:42:19 am »
This is Hits Counter.
how many viewed this product.

Creb

Lylene

  • Jr. Member
  • **
  • Posts: 118
Re: HACK: add product counter by product
« Reply #3 on: July 12, 2010, 22:27:35 pm »
Hy
Great idea !

just a question : does it exclude bots like google etc ?

Creb

  • Beginner
  • *
  • Posts: 18
Re: HACK: add product counter by product
« Reply #4 on: July 13, 2010, 00:27:59 am »
No, my client need module most viewed product. I create catalog for bathroom equipment. This modyfication add hit counter by products, and exlude multiple click for one product. This only external IP control by cookie.

If You need boot control maybe use this?

http://www.webmasterworld.com/php/4079073.htm

Creb

coolissimo

  • Beginner
  • *
  • Posts: 26
Re: HACK: add product counter by product
« Reply #5 on: October 02, 2010, 01:19:39 am »
Hi,

Seems doesnt work for me. It is just showing  "0" on product flypage.
It should be showing "1" cause i'm on the page, isnt it ??

IntraX

  • Jr. Member
  • **
  • Posts: 87
Re: HACK: add product counter by product
« Reply #6 on: October 04, 2010, 02:33:44 am »
Hi,

Seems doesnt work for me. It is just showing  "0" on product flypage.
It should be showing "1" cause i'm on the page, isnt it ??

Maybe when you reload the page again it shows 1 and then when reloading again it shows 2 and so on? As Hits are not current views, mostly people want to know how many before did excl. the own visit:)

godel

  • Beginner
  • *
  • Posts: 4
Re: HACK: add product counter by product
« Reply #7 on: July 16, 2011, 07:34:03 am »
i really like your hack

but i want to change the code:
if the client clicks on a button or link then the database will increase or decrease, such as buttons like on facebook.
I intend to make a button like and dislike in flypage.tpl.php, which if clicked on the button like it will be entered into the database, so the browser can display how many client are like and how many who do not like a product.

Thanks for the help.

coolissimo

  • Beginner
  • *
  • Posts: 26
Re: HACK: add product counter by product
« Reply #8 on: August 26, 2011, 22:28:17 pm »
Thanks Creb , was my mistake all is working great now !

Just one thing is missing now : could we have a "Most Viewed Products" Module ? It would be great !

Thanks again for sharing your knowledge

design8x

  • Beginner
  • *
  • Posts: 3
Re: HACK: add product counter by product
« Reply #9 on: December 14, 2012, 09:18:38 am »
How can display in virtuemart 2.0
Please help me

design8x

  • Beginner
  • *
  • Posts: 3
Re: HACK: add product counter by product
« Reply #10 on: December 15, 2012, 18:18:16 pm »
please help me!

Pacther

  • Beginner
  • *
  • Posts: 15
Re: HACK: add product counter by product
« Reply #11 on: February 10, 2013, 11:01:09 am »
hello, I am very interested in this modified version of VM 2.0. In addition I wanted to ask if you could add a query that would make me see the clicks that relate a particular manufacturer.
Thank you all.