예제 #1
0
 public function getTimeLeftToBuy($deal = false, $time = false, $now = false, $gmtTo = false)
 {
     if ($now === false && $gmtTo === false && $deal !== false && $time !== false) {
         $gmtTo = AW_Collpur_Helper_Data::getGmtTimestamp($deal->getData($time));
         $now = AW_Collpur_Helper_Data::getGmtTimestamp(true, true);
     }
     $amount = $gmtTo - $now;
     $days = floor($amount / 86400);
     $amount = $amount % 86400;
     $hours = floor($amount / 3600);
     $amount = $amount % 3600;
     $minutes = floor($amount / 60);
     $amount = $amount % 60;
     $seconds = floor($amount);
     if ($minutes < 10) {
         $minutes = "0{$minutes}";
     }
     if ($seconds < 10) {
         $seconds = "0{$seconds}";
     }
     $daysPHP = $days > 1 || $days == 0 ? Mage::helper('collpur')->__('days') : Mage::helper('collpur')->__('day');
     $hoursPHP = $hours > 1 || $hours == 0 ? Mage::helper('collpur')->__('hours') : Mage::helper('collpur')->__('hours');
     $minutesPHP = $minutes > 1 || $minutes == 0 ? Mage::helper('collpur')->__('minutes') : Mage::helper('collpur')->__('minute');
     $secondsPHP = $seconds > 1 || $seconds == 0 ? Mage::helper('collpur')->__('seconds') : Mage::helper('collpur')->__('second');
     return "{$days} {$daysPHP} {$hours}:{$minutes}";
     //{seconds};
 }
 public function getExpiredAfterDaysFilter($daysToAdd)
 {
     $currentZendDate = AW_Collpur_Helper_Data::getGmtTimestamp(true, true, $daysToAdd, false);
     $dateAfterDays = $currentZendDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
     $this->getSelect()->where('available_to <= ?', $dateAfterDays)->where('available_to IS NOT NULL')->where('sent_before_flag = 0')->order('id ASC');
     return $this;
 }
 /**
  * Core function returning timeDiff
  * Use gmmktime and gmdate to generate mock timestamps
  *
  * @dataProvider provider__testGetGmtTimestamp
  * @loadFixture
  * @loadExpectation
  */
 public function testGetGmtTimestamp($data)
 {
     if ($data['timezone'] != false) {
         @ini_set('date.timezone', $data['timezone']);
     }
     if ($data['now'] == true) {
         $currentDate = AW_Collpur_Helper_Data::getGmtTimestamp(true, true, false, false);
         if (true !== (gmdate('Y-m-d h:i:s') == $currentDate->toString('YYYY-MM-dd HH:mm:ss'))) {
             $this->fail('Incorrect current date time stamp calculation!');
         }
         $this->assertEquals(gmdate('Y-m-d h:i:s'), AW_Collpur_Helper_Data::getGmtTimestamp(true, true, false, 'toString'));
         return;
     }
     if (isset($data['dbDate']) && $data['add'] == false) {
         $stamp = AW_Collpur_Helper_Data::getGmtTimestamp($data['dbDate']);
         $this->assertEquals($stamp, $data['expectedStamp']);
         return;
     }
     if ($data['add'] == true) {
         $dateAddedStamp = AW_Collpur_Helper_Data::getGmtTimestamp($data['dbDate'], false, $data['add']);
         $this->assertEquals($dateAddedStamp, $data['expectedStamp']);
         return;
     }
 }
 public function isAvailable()
 {
     $coreDate = Mage::getModel('core/date');
     $currentTimestamp = $coreDate->gmtTimestamp();
     $availableFrom = $this->getData('available_from') ? $this->getData('available_from') : null;
     $fromAvailability = $availableFrom == null || $currentTimestamp >= AW_Collpur_Helper_Data::getGmtTimestamp($availableFrom);
     $availableTo = $this->getData('available_to') ? $this->getData('available_to') : null;
     $toAvailability = $availableTo == null || $currentTimestamp <= AW_Collpur_Helper_Data::getGmtTimestamp($availableTo);
     return $this->getData('is_active') && $this->isOpen() && $fromAvailability && $toAvailability;
 }
 public function updateStatus($collection, $value)
 {
     foreach ($collection as $coupon) {
         $coupon->setStatus($value)->setCouponDateUpdated(AW_Collpur_Helper_Data::getGmtTimestamp(true, true, false, 'toString'))->save();
     }
 }
 public function getTimeLeftToBuy($deal, $time = 'available_to')
 {
     $gmtTo = AW_Collpur_Helper_Data::getGmtTimestamp($deal->getData($time));
     $now = AW_Collpur_Helper_Data::getGmtTimestamp(true, true);
     $this->_cacheJsonString($deal, $now, $gmtTo);
     return Mage::helper('collpur/deals')->getTimeLeftToBuy(false, false, $now, $gmtTo);
 }