예제 #1
0
 /**
  * @param null $startDate
  *
  * calculate the next date create order of recurring profile
  * Timezone of startDate is store's timezone
  * Timezone of startDatetime load into recurring profile is store's timezone
  */
 public function nextDate($startDate = null)
 {
     // when recurring profile loaded, startDate updated by currentDate
     // timezone used as store's timezone
     if ($startDate == null) {
         $startDate = $this->_recurringProfile->getStartDatetime();
         $date = new DateTime($startDate, new DateTimeZone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE));
         $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
         $date->setTimezone(new DateTimeZone($timezone));
         $startDate = $date->format('Y-m-d');
     }
     $frequency = (int) $this->_recurringProfile->getPeriodFrequency();
     $unit = $this->_recurringProfile->getPeriodUnit();
     if ($unit === 'week') {
         $unit = 'day';
         $frequency = $frequency * 7;
     }
     if ($unit === 'two weeks') {
         $unit = 'day';
         $frequency = $frequency * 14;
     }
     $newDate = date('Y-m-d', strtotime('+' . $frequency . $unit, strtotime($startDate)));
     if (!$this->_checkDate($unit, $frequency, $startDate, $newDate)) {
         $newDate = date('Y-m-d', strtotime('-1day', strtotime(date('Y-m-1', strtotime('+1month', strtotime($newDate))))));
     }
     $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
     $additionalInfo['nextDate'] = $newDate;
     $this->_recurringProfile->setAdditionalInfo($additionalInfo);
     $this->_recurringProfile->save();
 }