Skip to content

Commit bde57fa

Browse files
committed
MAGETWO-52011: Second error message is not displayed when adding product with two invalid file fields to the cart
1 parent d246b84 commit bde57fa

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10-
10+
use Magento\Framework\Exception\LocalizedException;
1111
/**
1212
* @api
1313
* Abstract model for product type implementation
@@ -561,6 +561,7 @@ public function getSpecifyOptionMessage()
561561
* @param \Magento\Catalog\Model\Product $product
562562
* @param string $processMode
563563
* @return array
564+
* @throws LocalizedException
564565
*/
565566
protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $product, $processMode)
566567
{
@@ -571,20 +572,29 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
571572
$options = $product->getOptions();
572573
}
573574
if ($options !== null) {
575+
$result = [];
574576
foreach ($options as $option) {
575577
/* @var $option \Magento\Catalog\Model\Product\Option */
576-
$group = $option->groupFactory($option->getType())
577-
->setOption($option)
578-
->setProduct($product)
579-
->setRequest($buyRequest)
580-
->setProcessMode($processMode)
581-
->validateUserValue($buyRequest->getOptions());
578+
try {
579+
$group = $option->groupFactory($option->getType())
580+
->setOption($option)
581+
->setProduct($product)
582+
->setRequest($buyRequest)
583+
->setProcessMode($processMode)
584+
->validateUserValue($buyRequest->getOptions());
585+
} catch (\Exception $e) {
586+
$result[] = $e->getMessage();
587+
continue;
588+
}
582589

583590
$preparedValue = $group->prepareForCart();
584591
if ($preparedValue !== null) {
585592
$transport->options[$option->getId()] = $preparedValue;
586593
}
587594
}
595+
if (count($result) > 0) {
596+
throw new LocalizedException(__(implode("\n", $result)));
597+
}
588598
}
589599

590600
$eventName = sprintf('catalog_product_type_prepare_%s_options', $processMode);

0 commit comments

Comments
 (0)