File tree Expand file tree Collapse file tree 2 files changed +45
-20
lines changed
app/code/Magento/Quote/Model/QuoteRepository
lib/internal/Magento/Framework/Exception Expand file tree Collapse file tree 2 files changed +45
-20
lines changed Original file line number Diff line number Diff line change 7
7
8
8
use Magento \Quote \Api \Data \CartInterface ;
9
9
use Magento \Framework \Exception \InputException ;
10
- use Magento \Framework \Exception \CouldNotSaveException ;
10
+ use Magento \Framework \Exception \CouldNotSaveMultiMessageException ;
11
11
12
12
class SaveHandler
13
13
{
@@ -73,10 +73,7 @@ public function save(CartInterface $quote)
73
73
}
74
74
$ errors = $ quote ->getErrors ();
75
75
if (!empty ($ errors )) {
76
- $ renderedErrors = $ this ->renderErrors ($ errors );
77
- throw new CouldNotSaveException (
78
- __ ('Following errors occurred on save: %1 ' , implode ('; ' , $ renderedErrors ))
79
- );
76
+ throw new CouldNotSaveMultiMessageException ('Following errors occurred on save: %1 ' , $ errors );
80
77
}
81
78
82
79
// Billing Address processing
@@ -91,21 +88,6 @@ public function save(CartInterface $quote)
91
88
return $ quote ;
92
89
}
93
90
94
- /**
95
- * @param array $errors
96
- * @return array
97
- */
98
- private function renderErrors ($ errors )
99
- {
100
- $ renderedErrors = [];
101
- /** @var \Magento\Framework\Message\Error $error */
102
- foreach ($ errors as $ error ) {
103
- $ renderedErrors [] = $ error ->getText ();
104
- }
105
- return $ renderedErrors ;
106
- }
107
-
108
-
109
91
/**
110
92
* @param \Magento\Quote\Model\Quote $quote
111
93
* @return void
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Framework \Exception ;
8
+
9
+ use Magento \Framework \Phrase ;
10
+
11
+ class CouldNotSaveMultiMessageException extends CouldNotSaveException
12
+ {
13
+ /**
14
+ * @param string $mainMessage
15
+ * @param \Magento\Framework\Message\Error[] $errors
16
+ * @param string $separator
17
+ */
18
+ public function __construct ($ mainMessage , $ errors , $ separator = '; ' )
19
+ {
20
+ $ renderedErrors = $ this ->renderErrors ($ errors , $ separator );
21
+ // $mainMessage should contain %1 to be substituted by concatenated errors
22
+ $ phrase = new \Magento \Framework \Phrase ($ mainMessage , [$ renderedErrors ]);
23
+ parent ::__construct ($ phrase );
24
+ }
25
+
26
+ /**
27
+ * @param \Magento\Framework\Message\Error[] $errors
28
+ * @param string $separator
29
+ * @return string
30
+ */
31
+ private function renderErrors ($ errors , $ separator )
32
+ {
33
+ $ renderedErrors = '' ;
34
+ $ eol = '' ;
35
+ /** @var \Magento\Framework\Message\Error $error */
36
+ foreach ($ errors as $ error ) {
37
+ $ renderedErrors .= $ eol . __ ($ error ->getText ())->render ();
38
+ $ eol = $ separator ;
39
+ }
40
+ return $ renderedErrors ;
41
+ }
42
+
43
+ }
You can’t perform that action at this time.
0 commit comments