11
11
/**
12
12
* Catalog product option date type
13
13
*
14
- * @author Magento Core Team <core@magentocommerce.com>
15
14
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
16
15
*/
17
16
class Date extends \Magento \Catalog \Model \Product \Option \Type \DefaultType
@@ -218,32 +217,36 @@ public function prepareForCart()
218
217
public function getFormattedOptionValue ($ optionValue )
219
218
{
220
219
if ($ this ->_formattedOptionValue === null ) {
221
- if ($ this ->getOption ()->getType () == ProductCustomOptionInterface::OPTION_TYPE_DATE ) {
222
- $ result = $ this ->_localeDate ->formatDateTime (
223
- new \DateTime ($ optionValue ),
224
- \IntlDateFormatter::MEDIUM ,
225
- \IntlDateFormatter::NONE ,
226
- null ,
227
- 'UTC '
228
- );
229
- } elseif ($ this ->getOption ()->getType () == ProductCustomOptionInterface::OPTION_TYPE_DATE_TIME ) {
230
- $ result = $ this ->_localeDate ->formatDateTime (
231
- new \DateTime ($ optionValue ),
232
- \IntlDateFormatter::SHORT ,
233
- \IntlDateFormatter::SHORT ,
234
- null ,
235
- 'UTC '
236
- );
237
- } elseif ($ this ->getOption ()->getType () == ProductCustomOptionInterface::OPTION_TYPE_TIME ) {
238
- $ result = $ this ->_localeDate ->formatDateTime (
239
- new \DateTime ($ optionValue ),
240
- \IntlDateFormatter::NONE ,
241
- \IntlDateFormatter::SHORT ,
242
- null ,
243
- 'UTC '
244
- );
245
- } else {
246
- $ result = $ optionValue ;
220
+ switch ($ this ->getOption ()->getType ()) {
221
+ case ProductCustomOptionInterface::OPTION_TYPE_DATE :
222
+ $ result = $ this ->_localeDate ->formatDateTime (
223
+ new \DateTime ($ optionValue ),
224
+ \IntlDateFormatter::MEDIUM ,
225
+ \IntlDateFormatter::NONE ,
226
+ null ,
227
+ 'UTC '
228
+ );
229
+ break ;
230
+ case ProductCustomOptionInterface::OPTION_TYPE_DATE_TIME :
231
+ $ result = $ this ->_localeDate ->formatDateTime (
232
+ new \DateTime ($ optionValue ),
233
+ \IntlDateFormatter::SHORT ,
234
+ \IntlDateFormatter::SHORT ,
235
+ null ,
236
+ 'UTC '
237
+ );
238
+ break ;
239
+ case ProductCustomOptionInterface::OPTION_TYPE_TIME :
240
+ $ result = $ this ->_localeDate ->formatDateTime (
241
+ new \DateTime ($ optionValue ),
242
+ \IntlDateFormatter::NONE ,
243
+ \IntlDateFormatter::SHORT ,
244
+ null ,
245
+ 'UTC '
246
+ );
247
+ break ;
248
+ default :
249
+ $ result = $ optionValue ;
247
250
}
248
251
$ this ->_formattedOptionValue = $ result ;
249
252
}
@@ -302,7 +305,9 @@ public function prepareOptionValueForRequest($optionValue)
302
305
$ infoBuyRequest = $ confItem ->getOptionByCode ('info_buyRequest ' );
303
306
try {
304
307
$ value = $ this ->serializer ->unserialize ($ infoBuyRequest ->getValue ());
305
- if (is_array ($ value ) && isset ($ value ['options ' ]) && isset ($ value ['options ' ][$ this ->getOption ()->getId ()])
308
+
309
+ if (
310
+ is_array ($ value ) && isset ($ value ['options ' ]) && isset ($ value ['options ' ][$ this ->getOption ()->getId ()])
306
311
) {
307
312
return $ value ['options ' ][$ this ->getOption ()->getId ()];
308
313
} else {
@@ -341,12 +346,9 @@ public function is24hTimeFormat()
341
346
public function getYearStart ()
342
347
{
343
348
$ _range = $ this ->getConfigData ('year_range ' ) !== null
344
- ? explode (', ' , $ this ->getConfigData ('year_range ' )) : [];
345
- if (isset ($ _range [0 ]) && !empty ($ _range [0 ])) {
346
- return $ _range [0 ];
347
- } else {
348
- return date ('Y ' );
349
- }
349
+ ? explode (', ' , $ this ->getConfigData ('year_range ' ))
350
+ : [];
351
+ return (isset ($ _range [0 ]) && !empty ($ _range [0 ])) ? $ _range [0 ] : date ('Y ' );
350
352
}
351
353
352
354
/**
@@ -357,12 +359,9 @@ public function getYearStart()
357
359
public function getYearEnd ()
358
360
{
359
361
$ _range = $ this ->getConfigData ('year_range ' ) !== null
360
- ? explode (', ' , $ this ->getConfigData ('year_range ' )) : [];
361
- if (isset ($ _range [1 ]) && !empty ($ _range [1 ])) {
362
- return $ _range [1 ];
363
- } else {
364
- return date ('Y ' );
365
- }
362
+ ? explode (', ' , $ this ->getConfigData ('year_range ' ))
363
+ : [];
364
+ return (isset ($ _range [1 ]) && !empty ($ _range [1 ])) ? $ _range [1 ] : date ('Y ' );
366
365
}
367
366
368
367
/**
0 commit comments