1

This is my scenario: I will set up a special price for current day only and I would like to mention in Frontend a text message when the offer is available.

By default when you select a date in Magento backend (Product editing page), you are not allow to set up the time too. If you look into the database both SpecialPriceFromDate and SpecialPriceToDate has the same time set up at 00:00. If they have the same value there is an issue, you cannot compare current visitor time with SpecialPriceToDate.

  • SpecialPriceFromDate = 2016-08-27 00:00:00
  • SpecialPriceToDate = 2016-08-27 00:00:00
  • Current Visitor Time = 2016-08-27 16:00:36

I can do some statements inside the template file, by creating a variable for end of the day and adding 86399 to SpecialPriceFromDate, then evaluating it with current visitor time. It works but it is not looking good.

I would like to ask you how if I can change the calendar in Product editing page in order to set up the time too. In this way the time is very precisely.

By the way, product special Price appears correctly in frontend if both dates are equal.

  • just as a side notice. I'm not sure, how this is handled in magento1. In Magento2, 86400 Seconds (1 Day) are always added to the special_to_date when it is compared. this way having the same day in the dates will set it as special for this day – David Verholen Aug 27 '16 at 16:32
  • As I mentioned in my post I can handle adding to SpecialPriceToDate 83699 just to get 1 second before midnight into my template or creating a module for doing this. But a more elagant way is allowing hours, minutes and seconds in Calendar. In this way anyone ca set up a more precisely time for specials. Let's say is not a whole day, only 4 hours. On the other hand same thing can do NewsFromDate and NewsToDate. Still looking for a solution to enhanced the options in that calendar and make it available for every Date attribute. – ADDISON74 Aug 27 '16 at 17:33
0

the way your special price dates are , special price coming for only SpecialPriceToDate = 2016-08-27 00:00:00 time you have to set to date to SpecialPriceToDate = 2016-08-27 23:59:59 for showing one day or SpecialPriceToDate = 2016-08-28 00:00:00 for one day showing this is the solution from my side , Please let me know if its not working.

  • Magento should not allow selecting the same ToDate value like FromDate. In this way you will be forced to select the next day as you mentioned which create a range of minimum one day. It is a logical bug. – ADDISON74 Aug 30 '16 at 8:44
  • you can not say its a logical bug but if you want to apply this kind of date then you have to think accordingly to magento. what they have think when they create this functionality , this is how all cms work – Murtuza Zabuawala Aug 30 '16 at 8:48
  • I am sorry to say but it is a logical bug. Magento is allowed to check the date in that from, it can warn if the time in ToDate is bellow FromDate. In this way it can warn you to set up next day if the values are both the same. If an admin is setting both values the same, because Magento allows it will come trouble if someone want to show information about special time range in frontend. Fortunately I was able to fix this and I will create a module to achieve an elegant way than bellow. – ADDISON74 Aug 30 '16 at 9:25
0
<?php
    if (!is_null($_product->getSpecialPrice()) && $_product->getSpecialPrice() <= $_product->getPrice()) {
       $specialCurrentTime = time();
       $specialStartTime   = strtotime($_product->getSpecialFromDate());
       if (!is_null($_product->getSpecialToDate())) $specialEndTime = strtotime($_product->getSpecialToDate());

       if (is_null($specialEndTime) && $specialStartTime <= $specialCurrentTime)
           echo "* Available starting with ".date('j F Y', $specialStartTime);

       if ($specialStartTime == $specialEndTime && $specialStartTime <= $specialCurrentTime && $specialCurrentTime <= $specialEndTime + 86399)
           echo "* Available only ".date('j F Y', $specialStartTime);

       if ($specialStartTime <> $specialEndTime && $specialStartTime <= $specialCurrentTime && $specialCurrentTime <= $specialEndTime + 86399)
           echo "* Available between ".date('j F Y', $specialStartTime)." and ".date('j F Y', $specialEndTime);                            
    }                               
?>

By default Magento is allowing setting up Special Price dates with the same value. This is a logical bug when you cannot set hours, minutes and second for SpecialToDate value. Both FromDate and ToDate are having the same values inside the database. If you plan to show any information in frontend in product page about the special price range of dates and your admins are setting up the same values for FromDate and ToDate because you did not instruct them to set up one day up (28 -> 29) then use the script from above. In this way you can prevent this logical issue in Magento.

Just pay attention to your system time which is processed by PHP. If there are any differences the text will be shown even there is not special price.

  • For those interested using the code from about it must be inserted into this file your_theme/template/catalog/product/view.phtml. – ADDISON74 Aug 30 '16 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.