Forum PrestaShop

Il Forum di PrestaShop è lo spazio in cui puoi condividere con la comunità di PrestaShop consigli pratici sull'e-commerce e trovare la risposta a tutte le domande tecniche e funzionali.

Forum PrestaShop

Jump to content

[Solved] Countdown timer for special prices (Current v0.8.1)

112 replies to this topic
#1
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
Hi there.
I'm trying to create this module based on the specials one. The idea is to put a countdown timer over the special product that starts until the end of the discount.
At first I put the script on the php file and then a javascript function on the tpl. Here's the code:

[removed]
var days = '{$remainingDay}';
var hours = '{$remainingHour}';
var minutes = '{$remainingMinutes}';
var seconds = '{$remainingSeconds}';

{literal}
function setCountDown()
{
seconds--;
if (seconds < 0){
minutes--;
seconds = 59
}
if (minutes < 0){
hours--;
minutes = 59
}
if (hours < 0){
days--;
hours = 23
}
document.getElementById("remain") = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
setTimeout ("setCountDown()", 1000 );
}
{/literal}
[removed]

The tpl file shows me correctly the time but it's not active, I mean it is not counting. This is because I need to load this js function and I don't know how to call it when the page is loaded. In a html file you can put the "onload" event in the <body> tag, but no way here.
How can I do this?. Is there any other way to create a function that loads on the page beginning?.
Thanks by your help.

Attached Files


Southern PS Fan =)

#2
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
Finally I did it!. I'm not sure if it's a bad thing but it works lol. I create new <body> tags around the module and added the onload event. That's it!.
But now I'm trying to get this dynamic.
The target date (discount ends) muss to be the one in the DB. So I have to get the reduction_from and reduction_to fields from the products table. For this I'm trying to create the query on the php, getting the results on the tpl but the only result is the word "array". No matter what the result of the query is, it only shows the word "Array".
I tried with [0] but no result.
-- PHP FILE:
$sql = "SELECT reduction_from, reduction_to FROM ps_product
WHERE reduction_price > '0'
OR reduction_percent > '0'";
$response = Db::getInstance()->ExecuteS($sql);
$smarty->assign('response',$response);

-- TPL FILE:
...
RESPONCE:{$response}

...
Southern PS Fan =)

#3
Fabrice

    PrestaShop Fanatic

  • Moderators
  • 3147 posts
hummm.. very interested !
Fabrice
http://www.my-deco-shop.com
Projet en cours de lancement - New fantastic module: Checkout-Pro
le meilleur outil de gestion pour Prestashop que j'utilise - best tool I use: Store Commander

#4
SmartiesKiller

    PrestaShop Addict

  • Members
  • PipPipPip
  • 542 posts
where are you with this piece of code ???
did you realise it ?

#5
Paul C

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1005 posts
RESPONCE:{$response->reduction_from}, {$response->reduction_to} 

Free Prestashop modules and developer resources

Latest Prestashop Developer articles:
* 1.4 Plugins Revisited – Part 1
* 1.4 Plugins Revisited – Part 2

Latest News:
Prestashop Module and Theme Developers can now Advertise on eCartService.net

#6
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts

From 1222784688:

where are you with this piece of code ???
did you realise it ?


(the $sql is actually $responce)

lol man It is just for tests trying to get any value from the DB and then show it on the tpl file. Forget what is it for xD
Do you know how can I do this?. What's the way for sql queries?.
Southern PS Fan =)

#7
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
Finally...
The problem wasn't in the sql query, it was just the key value of the array.
So to get the value on the tpl file, the code must to be like this: {$variable.key} . In my case: {$response.reduction_from} (f.e.).

Good to now this ;)

Thanks for those who tried to help me! and I hope could be ready to show any advance of this module soon ;)
Southern PS Fan =)

#8
Paul C

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1005 posts
err, look up ;-)

Paul
Free Prestashop modules and developer resources

Latest Prestashop Developer articles:
* 1.4 Plugins Revisited – Part 1
* 1.4 Plugins Revisited – Part 2

Latest News:
Prestashop Module and Theme Developers can now Advertise on eCartService.net

#9
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts

From 1222798863:

err, look up ;-)

Paul


Sorry it's with the point " . " instead of the " -> " ... {$var.key} . But your comment makes me find the way to call for a key in the array =)
Southern PS Fan =)

#10
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
Well, finally here I have my module working. By now it only takes one special product and shows the time remaining until the discount ends.

By the way, maybe you will need to change the DB Prefix. It's using "ps_". (I tried _DB_PREFIX_ but who knows why it didn't work =/ )



If anyone want to try and/or improve it here's my Hot Price Countdown
Current version: 0.8.1

Attached Files


Southern PS Fan =)

#11
Paul C

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1005 posts
Oops Rod_ you're quite right, it should have been a "." :red:

Great module idea you've come up with! Look forward to seeing many more from you :cheese:

Paul
Free Prestashop modules and developer resources

Latest Prestashop Developer articles:
* 1.4 Plugins Revisited – Part 1
* 1.4 Plugins Revisited – Part 2

Latest News:
Prestashop Module and Theme Developers can now Advertise on eCartService.net

#12
SmartiesKiller

    PrestaShop Addict

  • Members
  • PipPipPip
  • 542 posts

From 1222843704:

Well, finally here I have my module working. By now it only takes one special product and shows the time remaining until the discount ends.

By the way, maybe you will need to change the DB Prefix. It's using "ps_". (I tried _DB_PREFIX_ but who knows why it didn't work =/ )



If anyone want to try and/or improve it here's my Hot Price Countdown v0.5 module ;-)


yeah i'd like to test it but how did it work ??

#13
SmartiesKiller

    PrestaShop Addict

  • Members
  • PipPipPip
  • 542 posts
i see how it work
it was only a mistake from me cause the block is allowed to right colum and my need to be on left colum :D now it work like a charm.
Thnx again for this great module.

#14
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
v0.6 change:
To avoid wrong timers by negative differences between the beginning and the end of the discount that can appear when the time is 00:00, I added some conditions and the timer will now show "Finished". (Look at the second screenshot).

If you want to avoid this message and just stop the special price, change the "target time" on the php file. In this case you can change it by 23:59:59. Just before 00:00 o'clock.
Southern PS Fan =)

#15
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts
v0.7 change:

More than 1 day condition added.
If the discount is for more than 1 day, the block will show the remaining days next the countdown timer.
Southern PS Fan =)

#16
Fabrice

    PrestaShop Fanatic

  • Moderators
  • 3147 posts
Hi !

in the same idea (countdown) is it possible to have it in a full text ?
the idea is to write for instance in the editorial : blablabla finished in "the countdown"

is that possible ?
thanks !
Fabrice
http://www.my-deco-shop.com
Projet en cours de lancement - New fantastic module: Checkout-Pro
le meilleur outil de gestion pour Prestashop que j'utilise - best tool I use: Store Commander

#17
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts

From 1223862022:

Hi !

in the same idea (countdown) is it possible to have it in a full text ?
the idea is to write for instance in the editorial : blablabla finished in "the countdown"

is that possible ?
thanks !


You mean to have the countdown on the editorial section or what?. :roll:
Southern PS Fan =)

#18
Fabrice

    PrestaShop Fanatic

  • Moderators
  • 3147 posts
yes, I want to type text in editorial, via the editor (which is using smarty), then place the code just after the text to show countdown.

the result should be, for instance : the next promotion starts in xxxx seconds
where xxx is the dynamic countdown.

is that possible ?
tks.
Fabrice
http://www.my-deco-shop.com
Projet en cours de lancement - New fantastic module: Checkout-Pro
le meilleur outil de gestion pour Prestashop que j'utilise - best tool I use: Store Commander

#19
Rod_

    PrestaShop Apprentice

  • Members
  • PipPip
  • 92 posts

From 1223863502:

yes, I want to type text in editorial, via the editor (which is using smarty), then place the code just after the text to show countdown.

the result should be, for instance : the next promotion starts in xxxx seconds
where xxx is the dynamic countdown.

is that possible ?
tks.


Yes you can man. It's practically the same code but working with the starting date of the discount. This obviously in the editorial.php of the module.
Southern PS Fan =)

#20
Henry

    PrestaShop Newbie

  • Members
  • Pip
  • 11 posts
Hello Rod,


Thanks for this module.

I just want to ask a question which is "how can we modify the background color of this module". In the example, the color is pink but I wish can have different background color for this module. If we need to modify the global.css, can you show us an example to modify color?

Thanks,

Henry