PrestaShop Forums: [Solved] Countdown timer for special prices (Current v0.8.1) - PrestaShop Forums

Jump to content


Welcome to the PrestaShop Forum! We hope you'll share your comments and suggestions with us. We ask that you please post in English to the main sections of the PrestaShop Forum. If you want to write in another language, please post in the corresponding PrestaShop Community section below.

Please note that PrestaShop Community sections are largely self-moderated. PrestaShop team members may or may not participate in non-English sections. To improve the chances of receiving feedback to your question or comment, please post it in English to the main sections of our Forum.

NYC

Vous parlez français ? par ici !


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


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

#1 Rod_

    PrestaShop Apprentice

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 28 September 2008 - 02:23 AM

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 File(s)


Southern PS Fan =)

#2 Rod_

    PrestaShop Apprentice

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 28 September 2008 - 03:50 AM

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

  • 28 Jul 2008
  • Moderators
  • 3124 posts
  • Location:Strasbourg - east France

Posted 28 September 2008 - 08:04 AM

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

  • 20 May 2008
  • Members
  • PipPipPip
  • 542 posts
  • Location:Calais

Posted 30 September 2008 - 03:24 PM

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

#5 Paul C

    PrestaShop Fanatic

  • 02 Aug 2008
  • Members
  • PipPipPipPip
  • 1003 posts
  • Location:Dundee, Scotland, United Kingdom

Posted 30 September 2008 - 03:56 PM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 30 September 2008 - 04:02 PM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 30 September 2008 - 07:04 PM

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

  • 02 Aug 2008
  • Members
  • PipPipPipPip
  • 1003 posts
  • Location:Dundee, Scotland, United Kingdom

Posted 30 September 2008 - 07:21 PM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 01 October 2008 - 03:20 AM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 01 October 2008 - 07:48 AM

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 File(s)


Southern PS Fan =)

#11 Paul C

    PrestaShop Fanatic

  • 02 Aug 2008
  • Members
  • PipPipPipPip
  • 1003 posts
  • Location:Dundee, Scotland, United Kingdom

Posted 01 October 2008 - 10:48 AM

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

  • 20 May 2008
  • Members
  • PipPipPip
  • 542 posts
  • Location:Calais

Posted 01 October 2008 - 12:29 PM

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

  • 20 May 2008
  • Members
  • PipPipPip
  • 542 posts
  • Location:Calais

Posted 01 October 2008 - 12:35 PM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 01 October 2008 - 06:06 PM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 02 October 2008 - 06:32 AM

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

  • 28 Jul 2008
  • Moderators
  • 3124 posts
  • Location:Strasbourg - east France

Posted 13 October 2008 - 02:40 AM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 13 October 2008 - 03:00 AM

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

  • 28 Jul 2008
  • Moderators
  • 3124 posts
  • Location:Strasbourg - east France

Posted 13 October 2008 - 03:05 AM

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

  • 26 Jul 2008
  • Members
  • PipPip
  • 92 posts
  • Location:Australia

Posted 13 October 2008 - 03:12 AM

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

  • 19 Sep 2008
  • Members
  • Pip
  • 11 posts

Posted 14 November 2008 - 01:24 AM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users