Jump to content

[Solved] Countdown Timer For Special Prices (Current V0.8.1)


Rod_
 Share

Recommended 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.

 

Added by mdekker - DO NOT REMOVE

This module has multiple issues:

- This module can not be uploaded though the Back Office. You must connect through FTP and upload to the right directory.

- Not compatible with PrestaShop 1.6

These warnings can be removed as soon as the issues have been resolved.

 

Hot Price v0.8.1.zip

  • Like 1

Share this post


Link to post
Share on other sites

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}


...

Share this post


Link to post
Share on other sites

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?.

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites

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

2095_bvIJj6LnLECAufQhkWFZ_t

2105_EW4DisZtXL47RleE1yMk_t

Hot Price v0.8.1.zip

Share this post


Link to post
Share on other sites

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 ??

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

  • 2 weeks later...
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:

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

  • 1 month later...

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

Share this post


Link to post
Share on other sites

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


Hello Henry,
This module is tacking the style of an exclusive block content. So in will take your default colours from your exclusive block content styles.
For the countdown box DIV the ID is "hotprice" so adding #hotprice on your CSS sheet you will able to edit that table style.

Hope it helps you ;)

Share this post


Link to post
Share on other sites

in my prestashop appear 0.6 no 0.7 ... why?? and i how to can setup this? pls


Hi checkmate!.
First, sorry about the version number. It was just a detail I forgot to change :red: .
Anyway I uploaded the fixed one.

No about your second question.
This module's countdown timer starts when you create a new discount on any product. It will compare the current time with the target date you put on the discount fields.
By the way I can tell you that on my system I'm using this module with the condition that only 45% or more will activate the countdown. Otherwise the countdown will not start. You can edit this on the line #48 of the hotprice.php file.
(OR reduction_percent > '0').

I hope this helps you ;)

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Islander, if you can ask me in English I'll be able to give you an answer.

Jaro61.
This module takes, by default, any active discount. So if you put a discount on any product this will appear on the Hot Price module. Remember that if you don't set a final date for discount the module will show "Undefined" otherwise it will compare that end date with the current time and date and so the remaining time.

I hope this solve your problem ;)

PS: It is a good idea to change the condition (hotprice.php lines 47-48). In my case I use a 45% discount percent or more so this module will show only this special discounts and all the rest under 45% will be taking as just normal discounts (specials module) =)

Share this post


Link to post
Share on other sites

hi rod, i m sorry for my post in french.Iunderstood, i have to put a end selling date to make it works right ?
i ll try and let you know,
regards

toa
www.tahitibluray.com


If you put the same dates it will show the Undefined message for undefined time discounts.

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

Hi, I cannot get your Module to work on mysite, have I missed something ? it always showes "undefined", I have tried setting the % in hotprice.php, any ideas ? I am running presta shop v1.0.0.8

All the best, Steve
(it will be a shame if I cannot get it to work as it seems to be a nice Module) :-)

Share this post


Link to post
Share on other sites

Hi, I cannot get your Module to work on mysite, have I missed something ? it always showes "undefined", I have tried setting the % in hotprice.php, any ideas ? I am running presta shop v1.0.0.8

All the best, Steve
(it will be a shame if I cannot get it to work as it seems to be a nice Module) :-)


Let me check it for you!.
Give me a couple of minutes and will I post the solution. ;)

Share this post


Link to post
Share on other sites

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

Thank you, Rod

Share this post


Link to post
Share on other sites

Hi Rod,
I seemed to have got it working (somehow), at the moment I have set the % in hotprice back to "0" .
Thanks for your help.

All the best,
Steve

P.S just seen your message, if its working ok now should I still upgrade it ?


Hi Steve,

Actually should be better if you install again the new version. Otherwise just copy the two files hotprice (hotprice.php & hotprice.tpl) and replace the olds.

Good luck! ;)

Share this post


Link to post
Share on other sites

Hi Rod,
I'm having problems again, I have set the expiry date on one item in sale (all other items in sale do not have dates set) but the Module shows the countdown time on all Sale items (Its the same countdown time for all sale items)

can you advise :question:

All the best, Steve

http://www.presta.speedmotorcycleclothing.net


Let me check that Steve I didn't try the module with more than one discount before.
By the way sorry by my late answer but I will take a look at this as soon as possible.

Regards.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

This is a great little module, is there away of being able to put this into the middle of my site and to be able to show more then just 1 item at a time? I think it would look even better if it could display and work the same way as a featured products....

Can it be done if so how?

Share this post


Link to post
Share on other sites

You can show it at your middle column but not sure if you can initialise the countdown more than one time. The entire code works only for one result so for that you need to remake it I think or find another way.
Sorry about that but maybe somebody could give you another solution.

Share this post


Link to post
Share on other sites

Thanks for the quick reply, how do I put it in the middle of the page then?


For this you have to modify the installer to enable the Home hook and then work a bit with the structure and CSS.
Let me take a look.

Share this post


Link to post
Share on other sites

Add these lines to your "hotprice.php" file (before the ?> of course):

    function hookHome($params)
   {
       return $this->hookRightColumn($params);
   }



Then just transplant your module to the Homepage Content hook and then all you have to do is work a bit with the HTML (.tpl file) and CSS.

PS: Don't forget to delete the module from the right column hook or wherever else you have it.

Good luck ;)

Share this post


Link to post
Share on other sites

Thanks for the quick reply, I should be able to do the first part but not sure on the rest as I'm not good with html or css code. Any help you could offer would be appreciated.


Yes buddy I can. Find me in Skype as hernan thiers if you want (or can). Otherwise I will send you by PM the result.
Not today of course but I will take my time soon.

Regards

Share this post


Link to post
Share on other sites

Hi great module.

How do I translate it into danish? i undertsand that its in the hotprice.tpl. but witch lines?
Thanks for the guide.

/
Mobimob


Time Remaining:

        {if $centinel == 1}

Undefined

        {else}<!-- centinel -->

            {if $wolverine == 1}

{$remainingDay} days {$remainingHour}:{$remainingMinutes}:{$remainingSeconds}



Just change the text values on these lines. Remember, you don't have to change the {$values}, only "Time Rem...", "Undefined", "days", and that words.

Good luck!.

Share this post


Link to post
Share on other sites

Hello there,

it's a greate module, this is something very nice for our online shop :)

need some help, I'm using Prestashop version 1.0 and seem that this module won't work on my shop, I have some like 4 special products that are not displayed in the hot price module, any reason why?

I modified the date and still not listed.... all I see is: "No hot specials at this time"

Share this post


Link to post
Share on other sites

Hello there,

it's a greate module, this is something very nice for our online shop :)

need some help, I'm using Prestashop version 1.0 and seem that this module won't work on my shop, I have some like 4 special products that are not displayed in the hot price module, any reason why?

I modified the date and still not listed.... all I see is: "No hot specials at this time"


Just make sure that you put the correct date format.
Anyway I will be able to give you a better support in a few days.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Hi Paul? what did you do to fix it? I have like 15 discounted products and no idea on how to make one of them show up there, on PS 1.1.0.5, start and end date are correct, at least for 5 products I have manually modified.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Just a quick question, how do we get the timer to display time left on each product with a special whilst they are in list view and also in the product view. I am asking this because as far as I am aware the customer only know how much time is left by looking at the hot specials box, which only shows one product at a time.

By continuously letting the customer know how much time is left, they may be enticed to purchase quickly before the special is over.

Share this post


Link to post
Share on other sites

  • 2 weeks later...

Ok, I've been playing around with this module for a few days now trying to figure out what works and what doesn't. This is a great module with a lot of potential but there are a few problems with it. This is what I have found:

When you have more than one product on special (say for example 10) and some of them are set with the same start and end dates (which PS sees as an "ongoing" special) then this module displays only those products with different start/end dates as a hot Special and the products with the same start/end dates are displayed as "No hot specials at this time", all in a rotation. So, if you had 4 products with different start/end dates and 6 products with the same dates then if you refresh your page 10 times, 4 times would show the hot specials and 6 times would show the "no specials" message.

Problem: Some of us would like to display only those 4 products with different start/end dates as limited time Hot Specials in the module and not have the "long term" specials (i.e. those with the same dates) picked up by this module at all. The only reason we have those "long term specials" is so that we can show, on the product page, a RRP (recommended retail price) price with a strike through it and then our normal (lower) price below it.

Another problem is that when the countdown gets to the last 24 hours, the PS software seems to automatically change the start date of the special to "todays" date and, since the end date also happens to be today (because there are only 24 hours to go), the start date and end date are now the same - thus the module now displays "No hot specials at this time". If I wait on the page for the module to pass 1 Days, 0 : 0 : 01, it does carry on counting down (23 : 59 : 59 etc) as per usual but as soon as I refresh the page I get the "No hot specials..." message.

I would also like to be able to have "24 Hour Hot Specials", which this module cannot do due to the reasons mentioned above, as well as have the countdown timer show in the list view and on the product page itself.

Would it not be possible to have a separate tab in the BO (or even an added panel on the BO catalog products page) where we can control the products to be shown in this module and dates for those products separately?

Share this post


Link to post
Share on other sites

Is Rod_ still around?

Has anybody else managed to come right with this module? I still can't figure out how to show a 24hr Hot special :sick:

As soon as the start and the end date of the special are the same in the BO, the module displays "No hot specials at this time". I have looked at the both the hotprice.php and the hotprice.tpl code but since I know less than nothing about smarty I'm a bit stuck. Anybody know what I can change to get it to display just a 24hr countdown?

Share this post


Link to post
Share on other sites

  • 1 month later...
I fixed the display during the last 24 hours issue. I am attaching the updated module.
Thanks whitelighter but it doesn't work for me :down:

Your updated module always starts the countdown from 23:59:59 - i.e. Every time I refresh the page it goes back to 23:59:59

I also cannot get it to show for specials that are longer than one day?

Share this post


Link to post
Share on other sites

Hi !
sorry, but for me, the countdwon does simply NOT appear.
do not know why (and I have different date on a few products)
any idea why it did not work here (countdown is not showing)
tks !

Share this post


Link to post
Share on other sites

that's cool. working now.
I have a small "bug" : the word "Days" is staying "Days" and is not translated. could you tell me what I should change ? (it's translated in the BO of course...)
tks !!

Share this post


Link to post
Share on other sites

  • 3 weeks later...

Hi Fabrice,

Easy Solution.

Just edit file : hotprice.tpl

then : modify lines 9 & 10 like that :

var ldays = '{l s='Days' mod='hotprice'}';
var lday = '{l s='Day' mod='hotprice'}';



In fact, mod='hotprice' was forgetten ...

Cheers,

JP

Share this post


Link to post
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
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.


Hi !
I am trying to insert the php code in the prices_drop.php

could you please help me and tell me which part of this code I may put in the prices_drop.php page ?

tks for your help !

this is the full code : what may I keep ?
<?php
/**
* Hot Price Module v0.9.2
* Developed by Rod_ - 2009
*
* New version by vinoalvino
* New version by whitelighter
**/

class HotPrice extends Module
{
   private $_html = '';
   private $_postErrors = array();

   function __construct()
   {
       $this->name = 'hotprice';
       $this->tab = 'Blocks';
       $this->version = 0.93;

       parent::__construct();

       /* The parent construct is required for translations */
       $this->page = basename(__FILE__, '.php');
       $this->displayName = $this->l('Special Countdown');
       $this->description = $this->l('Adds a hot price product countdown timer');
   }

   function install()
   {
       parent::install();
       $this->registerHook('rightColumn');
   }

   function hookRightColumn($params)
   {
       global $smarty;
       global $product_idx;

       $special_on=1;
       if ($special = Product::getRandomSpecial(intval($params['cookie']->id_lang))) {
           $product_idx = $special['id_product'];
           $smarty->assign(array(
           'special' => $special,
           'oldPrice' => number_format($special['price'] + $special['reduction'], 2, '.', '')
       ));}

       if ($special === false ) $special_on=0;



       //******************************** START *********************************************
       //
       // MICRO COUNTDOWN  -  Version: 1.0
       //
       //*****************************************************************************

       // SQL QUERY

       /**
        ** VV001 **
        * CHANGE THE REDUCTION PRICE OR PERCENT FOR PERSONALISED SPECIALS
        * (Example: reduction_percent = 20). This will activate the module only for discounts over 20% off.
        **/

       $min_reduction_price=0;
       $min_reduction_percent=0;

       /*************************/

       $result = db::getInstance()->ExecuteS(
           "SELECT * FROM `"._DB_PREFIX_."product`
            WHERE `id_product` = '".$product_idx."'
         AND `reduction_to` >= DATE(NOW())
         AND `reduction_to` > `reduction_from`
         AND `active` = 1
         AND (`reduction_price` > ".$min_reduction_price." OR `reduction_percent` > ".$min_reduction_percent.")
           LIMIT 0,1");

       $superman=0;
       if (empty($result) === false AND $result != false AND sizeof($result))
       {
           $date_f = $result[0]['reduction_to'];
           $superman = 1;

           // String extraction
           $year_f = substr($date_f,0,4);
           $month_f = substr($date_f,5,2);
           $day_f = substr($date_f,8,2);

           // Define your target date here
           $targetYear  = $year_f;
           $targetMonth = $month_f;
           $targetDay   = $day_f;
           $targetHour  = 23;
           $targetMinute= 59;
           $targetSecond= 59;

           // Define date format
           $dateFormat = "Y-m-d H:i:s";

           $targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
           $actualDate = time();

           $secondsDiff = $targetDate - $actualDate;
           $remainingDay = floor($secondsDiff/60/60/24);

           $remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
           $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
           $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));

           #$targetDateDisplay = date($dateFormat,$targetDate);
           #$actualDateDisplay = date($dateFormat,$actualDate);

           // Smarty Assigns:
           $smarty->assign('remainingDay', $remainingDay);
           $smarty->assign('remainingHour', $remainingHour);
           $smarty->assign('remainingMinutes', $remainingMinutes);
           $smarty->assign('remainingSeconds', $remainingSeconds);

           /** Days translation **/
           $smarty->assign('dds', $this->l('days'));
           $smarty->assign('dd', $this->l('day'));

       }

       $smarty->assign('superman', $superman);
       $smarty->assign('special_on', $special_on);
       return $this->display(__FILE__, 'hotprice.tpl');
   }

   function hookLeftColumn($params)
   {
       return $this->hookRightColumn($params);
   }
}

?>

Share this post


Link to post
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 1 month later...

I know the last post in this thread is about a year old.... but I've struggled with an issue that may benefit someone else. Others in this Thread reported problems when the offer date is less than 1 day away. I also had this issue even with the latest release. Here was my problem... The SQL query was this:

$result = db::getInstance()->ExecuteS(
           "SELECT * FROM `"._DB_PREFIX_."product`
            WHERE `id_product` = '".$product_idx."'
         AND `reduction_to` >= DATE(NOW())
         AND `reduction_to` > `reduction_from`
         AND `active` = 1
         AND (`reduction_price` > ".$min_reduction_price." OR `reduction_percent` > ".$min_reduction_percent.")
           LIMIT 0,1");



So the problem happened when the reduction_to date is the same as the reduction_from date. (offer good only for the day)

Changing

 AND `reduction_to` > `reduction_from`


To

 AND `reduction_to` >= `reduction_from`


... allowed for the times when the deal say started on 2009-01-01 and ended 2009-01-01 (at 23:59:59)

Share this post


Link to post
Share on other sites

  • 11 months later...
  • 2 weeks later...
  • 5 weeks later...

Hi - Great idea this module - but no matter what we do we can not get it to work for us (on two active PS sites)

I would recomend the Solved be removed from the thread until such time as it is solved.

We are very interested in this module and will follow the posts.

Regards


Ian

Share this post


Link to post
Share on other sites

  • 1 month later...
up. I would like to include this countdown directly in the price-drop.php page.
should be displayed below each product.
how may I achieve that ? any idea ?
tks for any help.


Im interest too in this function, the countdown should are in principal page in all products sale

Share this post


Link to post
Share on other sites

  • 2 weeks later...