Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How Can I Clear This Every 24Hrs? Rate Topic   - - - - -

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 03 January 2021 - 01:19 PM #1

How can i clear this product view counter field every 24hrs?

 

{"SELECT viewed FROM ?:product_popularity WHERE product_id = ?i"|db_get_field:$product.product_id}



 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 183 posts

Posted 03 January 2021 - 04:56 PM #2

Use a cron job


harmsmitsdev@gmail.com


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 03 January 2021 - 05:42 PM #3

Yeah can you point me on how? thanks



 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 183 posts

Posted 03 January 2021 - 07:03 PM #4

Depends on your database,  but you should invoke something along the lines of

$ mysql -u[database_user] -p"[database_password]" [database] -e "UPDATE [table_prefix]product_popularity SET viewed = '0' WHERE 1"

Where everything between `[]` should be replaced with your according variables.


harmsmitsdev@gmail.com


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 03 January 2021 - 09:33 PM #5

Why don't you want to track product views?

product views are done in the frontend/products.php controller.

Suggest you use the hook 'update_product_notifications_pre' to alter the data that is updated if you want to disable the 'viewed' tracking.

 

I can't find the template code you are referring to in the standard release.

 

If you need help utilizing the hook, feel free to contact me via the 'get a quote' link in my signature. 

 

If you truly want to do this hourly because you want to see views/hr, suggest you also utilize that hook and possibly extend the functionality  to capture views/hr rather than zapping the total views.  But note that you will then need code to visualize the data like a line graph or bar graph and a way to select the period you want to view.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 04 January 2021 - 02:00 PM #6

Yes, I want to show the views per hour on the product detailed page to everyone except the seller of that item, the seller show see the entire views



 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 183 posts

Posted 04 January 2021 - 02:35 PM #7

Yes, I want to show the views per hour on the product detailed page to everyone except the seller of that item, the seller show see the entire views

Then you will have to track every product view with a timestamp and clear those added with a certain timestamp every hour.


harmsmitsdev@gmail.com


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 04 January 2021 - 07:44 PM #8

Then you will have to track every product view with a timestamp and clear those added with a certain timestamp every hour.

How can i do this, sound like a good solution



 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 05 January 2021 - 06:36 PM #9

Can i clone this {"SELECT viewed FROM ?:product_popularity WHERE product_id = ?i"|db_get_field:$product.product_id} and clear the clone and leave this one

 
 
i tried changing viewed to prd_viewed but it didn't work;
 

{"SELECT viewed FROM ?:product_popularity WHERE product_id = ?i"|db_get_field:$product.product_id}

 


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 05 January 2021 - 07:33 PM #10

Why are you using template code?  Did you create the column named 'prd_viewed'?

Given the number of your questions across several topics, suggest you hire a developer to work with you to accomplish your needs.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 05 January 2021 - 09:02 PM #11

this is what i did, i didn't create the column i'm trying to clone the existing column can you help me with creating the column? 

I know i'm almost there, just a little push.. 

 

function fn_prd_viewed($product_id){
$prd_view_old = db_get_field("SELECT prd_views from ?:products WHERE product_id = ?i",$product_id);
$data = array(
'prd_views' => $prd_view_old+1,
);
 
//to set prd_views  zero (I'm not sure it's correct)
db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", "0", $product_id);
}


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22001 posts

Posted 06 January 2021 - 06:35 AM #12

 

this is what i did, i didn't create the column i'm trying to clone the existing column can you help me with creating the column? 

I know i'm almost there, just a little push.. 

 

 

You can create new columns in few click in phpmyadmin. But it is still not clear for me what are you trying to do, sorry


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 06 January 2021 - 03:05 PM #13

You can create new columns in few click in phpmyadmin. But it is still not clear for me what are you trying to do, sorry

 

This snippet db_get_field("SELECT viewed from ?:products WHERE product_id = ?i",$product_id); will get the product views from the column viewed in database, i want to clone this snippet to have a second product views i can clear without clearing the main product views on viewed column. 

 

 

I need to know how to:

 

Create column for prd_views to act like column viewed

 

Update the count of prd_views to zero using php

 

here is what i have tried

db_get_field("UPDATE prd_views from ?:products WHERE product_id = ?i",$product_id, "0"); <-not sure if this will set count to zero->



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 06 January 2021 - 08:23 PM #14

This snippet db_get_field("SELECT viewed from ?:products WHERE product_id = ?i",$product_id); will get the product views from the column viewed in database, i want to clone this snippet to have a second product views i can clear without clearing the main product views on viewed column. 

 

 

I need to know how to:

 

Create column for prd_views to act like column viewed

 

Update the count of prd_views to zero using php

 

here is what i have tried

db_get_field("UPDATE prd_views from ?:products WHERE product_id = ?i",$product_id, "0"); <-not sure if this will set count to zero->

 

You do not appear to have any SQL or PHP experience.  I would again  suggest that you hire a developer to help you.  When you hire a developer, you are paying for time spent as well as some guarantee that your needs will be met and that things will be done in a manner that will survive future updates (normally).


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12075 posts

Posted 06 January 2021 - 08:24 PM #15

You can create new columns in few click in phpmyadmin. But it is still not clear for me what are you trying to do, sorry

 

I believe he thinks that if he captures data over the period of one hour that he will get views/hr.  But as you know, you will get views from last time it was zeroed.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • harmsmitsdev
  • Senior Member
  • Members
  • Join Date: 22-Feb 20
  • 183 posts

Posted 06 January 2021 - 11:21 PM #16

I believe he thinks that if he captures data over the period of one hour that he will get views/hr.  But as you know, you will get views from last time it was zeroed.

He should create a temporary / memory table and then store store something by `product_id | datetime`, and then just select the count where date time is larger than now() - 1 hour, and have a cron job periodically clear the table.

 

 

You do not appear to have any SQL or PHP experience.  I would again  suggest that you hire a developer to help you.  When you hire a developer, you are paying for time spent as well as some guarantee that your needs will be met and that things will be done in a manner that will survive future updates (normally).

 

I agree. He should just hire a developer. Its easier, and more convenient. Besides that, you will not end up accidentally causing any vulnerabilities or breaking your store with faulty SQL.


harmsmitsdev@gmail.com


 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 06 January 2021 - 11:23 PM #17

You can create new columns in few click in phpmyadmin. But it is still not clear for me what are you trying to do, sorry

 

eComs can you please give me the php snippet that can get the product views?



 
  • Dexterflamez
  • Senior Member
  • Trial users
  • Join Date: 08-Jan 18
  • 319 posts

Posted 06 January 2021 - 11:25 PM #18

He should create a temporary / memory table and then store store something by `product_id | datetime`, and then just select the count where date time is larger than now() - 1 hour, and have a cron job periodically clear the table.

 

 

 

I agree. He should just hire a developer. Its easier, and more convenient. Besides that, you will not end up accidentally causing any vulnerabilities or breaking your store with faulty SQL.

 

You have great ideas but all in theory, if you can show few snippets i can work from there, I don't have money to hire a developer yet



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 22001 posts

Posted 10 January 2021 - 06:59 AM #19

eComs can you please give me the php snippet that can get the product views?

 

Use code form post #1. But I agree with other answers here. Hire a developer to avoid problems with upgrades and other possible errors


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)