Public Member Functions | |
validateUserValue ($values) | |
prepareForCart () | |
getFormattedOptionValue ($optionValue) | |
getPrintableOptionValue ($optionValue) | |
getEditableOptionValue ($optionValue) | |
parseOptionValue ($optionValue, $productOptionValues) | |
prepareOptionValueForRequest ($optionValue) | |
useCalendar () | |
is24hTimeFormat () | |
getYearStart () | |
getYearEnd () | |
Protected Member Functions | |
_setInternalInRequest ($internalValue) | |
_dateExists () | |
_timeExists () |
Definition at line 34 of file Date.php.
_dateExists | ( | ) | [protected] |
Does option have date?
Definition at line 307 of file Date.php.
00308 { 00309 return in_array($this->getOption()->getType(), array( 00310 Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE, 00311 Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME 00312 )); 00313 }
_setInternalInRequest | ( | $ | internalValue | ) | [protected] |
Save internal value of option in infoBuy_request
string | $internalValue Datetime value in internal format |
Definition at line 292 of file Date.php.
00293 { 00294 $requestOptions = $this->getRequest()->getOptions(); 00295 if (!isset($requestOptions[$this->getOption()->getId()])) { 00296 $requestOptions[$this->getOption()->getId()] = array(); 00297 } 00298 $requestOptions[$this->getOption()->getId()]['date_internal'] = $internalValue; 00299 $this->getRequest()->setOptions($requestOptions); 00300 }
_timeExists | ( | ) | [protected] |
Does option have time?
Definition at line 320 of file Date.php.
00321 { 00322 return in_array($this->getOption()->getType(), array( 00323 Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME, 00324 Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME 00325 )); 00326 }
getEditableOptionValue | ( | $ | optionValue | ) |
Return formatted option value ready to edit, ready to parse
string | $optionValue Prepared for cart option value |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 190 of file Date.php.
00191 { 00192 return $this->getFormattedOptionValue($optionValue); 00193 }
getFormattedOptionValue | ( | $ | optionValue | ) |
Return formatted option value for quote option
string | $optionValue Prepared for cart option value |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 151 of file Date.php.
00152 { 00153 if ($this->_formattedOptionValue === null) { 00154 00155 $option = $this->getOption(); 00156 if ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE) { 00157 $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM); 00158 $result = Mage::app()->getLocale()->date($optionValue, Zend_Date::ISO_8601, null, false)->toString($format); 00159 } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DATE_TIME) { 00160 $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); 00161 $result = Mage::app()->getLocale()->date($optionValue, Varien_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format); 00162 } elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME) { 00163 $date = new Zend_Date($optionValue); 00164 $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp()); 00165 } else { 00166 $result = $optionValue; 00167 } 00168 $this->_formattedOptionValue = $result; 00169 } 00170 return $this->_formattedOptionValue; 00171 }
getPrintableOptionValue | ( | $ | optionValue | ) |
Return printable option value
string | $optionValue Prepared for cart option value |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 179 of file Date.php.
00180 { 00181 return $this->getFormattedOptionValue($optionValue); 00182 }
getYearEnd | ( | ) |
Year range end
Definition at line 276 of file Date.php.
00277 { 00278 $_range = explode(',', $this->getConfigData('year_range')); 00279 if (isset($_range[1]) && !empty($_range[1])) { 00280 return $_range[1]; 00281 } else { 00282 return date('Y'); 00283 } 00284 }
getYearStart | ( | ) |
Year range start
Definition at line 261 of file Date.php.
00262 { 00263 $_range = explode(',', $this->getConfigData('year_range')); 00264 if (isset($_range[0]) && !empty($_range[0])) { 00265 return $_range[0]; 00266 } else { 00267 return date('Y'); 00268 } 00269 }
is24hTimeFormat | ( | ) |
Time Format
Definition at line 251 of file Date.php.
00252 { 00253 return (bool)($this->getConfigData('time_format') == '24h'); 00254 }
parseOptionValue | ( | $ | optionValue, | |
$ | productOptionValues | |||
) |
Parse user input value and return cart prepared value
string | $optionValue | |
array | $productOptionValues Values for product option |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 202 of file Date.php.
00203 { 00204 $timestamp = strtotime($optionValue); 00205 if ($timestamp === false || $timestamp == -1) { 00206 return null; 00207 } 00208 00209 $date = new Zend_Date($timestamp); 00210 return $date->toString(Varien_date::DATETIME_INTERNAL_FORMAT); 00211 }
prepareForCart | ( | ) |
Prepare option value for cart
Mage_Core_Exception |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 104 of file Date.php.
00105 { 00106 if ($this->getIsValid() && $this->getUserValue() !== null) { 00107 $option = $this->getOption(); 00108 $value = $this->getUserValue(); 00109 00110 if (isset($value['date_internal']) && $value['date_internal'] != '') { 00111 $this->_setInternalInRequest($value['date_internal']); 00112 return $value['date_internal']; 00113 } 00114 00115 $timestamp = 0; 00116 00117 if ($this->_dateExists()) { 00118 if ($this->useCalendar()) { 00119 $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); 00120 $timestamp += Mage::app()->getLocale()->date($value['date'], $format, null, false)->getTimestamp(); 00121 } else { 00122 $timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']); 00123 } 00124 } else { 00125 $timestamp += mktime(0, 0, 0, date('m'), date('d'), date('Y')); 00126 } 00127 00128 if ($this->_timeExists()) { 00129 $hour = $this->is24hTimeFormat() ? $value['hour'] : $value['hour'] + 12; 00130 $timestamp += 60 * 60 * $hour + 60 * $value['minute']; 00131 } 00132 00133 $date = new Zend_Date($timestamp); 00134 $result = $date->toString(Varien_date::DATETIME_INTERNAL_FORMAT); 00135 00136 // Save date in internal format to avoid locale date bugs 00137 $this->_setInternalInRequest($result); 00138 00139 return $result; 00140 } else { 00141 return null; 00142 } 00143 }
prepareOptionValueForRequest | ( | $ | optionValue | ) |
Prepare option value for info buy request
string | $optionValue |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 219 of file Date.php.
00220 { 00221 // return array('date_internal' => $optionValue); 00222 $quoteItem = $this->getQuoteItem(); 00223 $infoBuyRequest = $quoteItem->getOptionByCode('info_buyRequest'); 00224 try { 00225 $value = unserialize($infoBuyRequest->getValue()); 00226 if (is_array($value) && isset($value['options']) && isset($value['options'][$this->getOption()->getId()])) { 00227 return $value['options'][$this->getOption()->getId()]; 00228 } else { 00229 return array('date_internal' => $optionValue); 00230 } 00231 } catch (Exception $e) { 00232 return array('date_internal' => $optionValue); 00233 } 00234 }
useCalendar | ( | ) |
Use Calendar on frontend or not
Definition at line 241 of file Date.php.
00242 { 00243 return (bool)$this->getConfigData('use_calendar'); 00244 }
validateUserValue | ( | $ | values | ) |
Validate user input for option
Mage_Core_Exception |
array | $values All product option values, i.e. array (option_id => mixed, option_id => mixed...) |
Reimplemented from Mage_Catalog_Model_Product_Option_Type_Default.
Definition at line 43 of file Date.php.
00044 { 00045 parent::validateUserValue($values); 00046 00047 $option = $this->getOption(); 00048 $value = $this->getUserValue(); 00049 00050 $dateValid = true; 00051 if ($this->_dateExists()) { 00052 if ($this->useCalendar()) { 00053 $dateValid = isset($value['date']) && preg_match('/^[0-9]{1,4}.+[0-9]{1,4}.+[0-9]{1,4}$/', $value['date']); 00054 } else { 00055 $dateValid = isset($value['day']) && isset($value['month']) && isset($value['year']) 00056 && $value['day'] > 0 && $value['month'] > 0 && $value['year'] > 0; 00057 } 00058 } 00059 00060 $timeValid = true; 00061 if ($this->_timeExists()) { 00062 $timeValid = isset($value['hour']) && isset($value['minute']) 00063 && is_numeric($value['hour']) && is_numeric($value['minute']); 00064 } 00065 00066 $isValid = $dateValid && $timeValid; 00067 00068 if ($isValid) { 00069 $this->setUserValue( 00070 array( 00071 'date' => isset($value['date']) ? $value['date'] : '', 00072 'year' => isset($value['year']) ? intval($value['year']) : 0, 00073 'month' => isset($value['month']) ? intval($value['month']) : 0, 00074 'day' => isset($value['day']) ? intval($value['day']) : 0, 00075 'hour' => isset($value['hour']) ? intval($value['hour']) : 0, 00076 'minute' => isset($value['minute']) ? intval($value['minute']) : 0, 00077 'day_part' => isset($value['day_part']) ? $value['day_part'] : '', 00078 'date_internal' => isset($value['date_internal']) ? $value['date_internal'] : '', 00079 ) 00080 ); 00081 } elseif (!$isValid && $option->getIsRequire() && !$this->getProduct()->getSkipCheckRequiredOption()) { 00082 $this->setIsValid(false); 00083 if (!$dateValid) { 00084 Mage::throwException(Mage::helper('catalog')->__('Please specify date required option(s)')); 00085 } elseif (!$timeValid) { 00086 Mage::throwException(Mage::helper('catalog')->__('Please specify time required option(s)')); 00087 } else { 00088 Mage::throwException(Mage::helper('catalog')->__('Please specify the product required option(s)')); 00089 } 00090 } else { 00091 $this->setUserValue(null); 00092 return $this; 00093 } 00094 00095 return $this; 00096 }