Skip to content

Commit 2575929

Browse files
committed
MAGETWO-64465: Investigate and fix post-refactoring issues
1 parent b15782d commit 2575929

File tree

2 files changed

+40
-41
lines changed
  • app/code/Magento/Catalog

2 files changed

+40
-41
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -316,22 +316,24 @@ public function prepareForCart()
316316
public function getFormattedOptionValue($optionValue)
317317
{
318318
if ($this->_formattedOptionValue === null) {
319-
try {
320-
$value = $this->unserializeJsonValue($optionValue);
321-
322-
$customOptionUrlParams = $this->getCustomOptionUrlParams() ? $this->getCustomOptionUrlParams() : [
323-
'id' => $this->getConfigurationItemOption()->getId(),
324-
'key' => $value['secret_key']
325-
];
326-
327-
$value['url'] = ['route' => $this->_customOptionDownloadUrl, 'params' => $customOptionUrlParams];
328-
329-
$this->_formattedOptionValue = $this->_getOptionHtml($value);
330-
$this->getConfigurationItemOption()->setValue($this->serializer->serialize($value));
331-
return $this->_formattedOptionValue;
332-
} catch (\Exception $e) {
333-
return $optionValue;
319+
if ($optionValue !== 'null') {
320+
$value = $this->serializer->unserialize($optionValue);
321+
if ($value !== null) {
322+
$customOptionUrlParams = $this->getCustomOptionUrlParams()
323+
? $this->getCustomOptionUrlParams()
324+
: [
325+
'id' => $this->getConfigurationItemOption()->getId(),
326+
'key' => $value['secret_key']
327+
];
328+
329+
$value['url'] = ['route' => $this->_customOptionDownloadUrl, 'params' => $customOptionUrlParams];
330+
331+
$this->_formattedOptionValue = $this->_getOptionHtml($value);
332+
$this->getConfigurationItemOption()->setValue($this->serializer->serialize($value));
333+
return $this->_formattedOptionValue;
334+
}
334335
}
336+
return $optionValue;
335337
}
336338
return $this->_formattedOptionValue;
337339
}
@@ -402,16 +404,17 @@ public function getPrintableOptionValue($optionValue)
402404
*/
403405
public function getEditableOptionValue($optionValue)
404406
{
405-
try {
406-
$value = $this->unserializeJsonValue($optionValue);
407-
return sprintf(
408-
'%s [%d]',
409-
$this->_escaper->escapeHtml($value['title']),
410-
$this->getConfigurationItemOption()->getId()
411-
);
412-
} catch (\Exception $e) {
413-
return $optionValue;
407+
if ($optionValue !== 'null') {
408+
$unserializedValue = $this->serializer->unserialize($optionValue);
409+
if ($unserializedValue !== null) {
410+
return sprintf(
411+
'%s [%d]',
412+
$this->_escaper->escapeHtml($unserializedValue['title']),
413+
$this->getConfigurationItemOption()->getId()
414+
);
415+
}
414416
}
417+
return $optionValue;
415418
}
416419

417420
/**
@@ -431,15 +434,14 @@ public function parseOptionValue($optionValue, $productOptionValues)
431434
if (preg_match('/\[([0-9]+)\]/', $optionValue, $matches)) {
432435
$confItemOptionId = $matches[1];
433436
$option = $this->_itemOptionFactory->create()->load($confItemOptionId);
434-
try {
435-
$this->unserializeJsonValue($option->getValue());
436-
return $option->getValue();
437-
} catch (\Exception $e) {
438-
return null;
437+
if ($option->getValue() !== 'null') {
438+
$unserializedValue = $this->serializer->unserialize($option->getValue());
439+
if ($unserializedValue !== null) {
440+
return $option->getValue();
441+
}
439442
}
440-
} else {
441-
return null;
442443
}
444+
return null;
443445
}
444446

445447
/**
@@ -467,11 +469,13 @@ private function unserializeJsonValue($jsonValue)
467469
*/
468470
public function prepareOptionValueForRequest($optionValue)
469471
{
470-
try {
471-
return $this->unserializeJsonValue($optionValue);
472-
} catch (\Exception $e) {
473-
return null;
472+
if ($optionValue !== 'null') {
473+
$unserializedValue = $this->serializer->unserialize($optionValue);
474+
if ($unserializedValue !== null) {
475+
return $unserializedValue;
476+
}
474477
}
478+
return null;
475479
}
476480

477481
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,7 @@ public function testGetEditableOptionValue()
288288
public function testGetEditableOptionValueInvalid()
289289
{
290290
$fileObject = $this->getFileObject();
291-
$optionTitle = 'Option Title';
292-
$optionValue = json_encode(['title' => $optionTitle]);
293-
$this->serializer->expects($this->once())
294-
->method('unserialize')
295-
->with($optionValue)
296-
->willThrowException(new SerializationException(__('Invalid JSON value.')));
291+
$optionValue = '#invalid jSoN*(&@#^$(*&';
297292
$this->escaper->expects($this->never())
298293
->method('escapeHtml');
299294

0 commit comments

Comments
 (0)