7
7
namespace Magento \SalesRule \Controller \Adminhtml \Promo \Quote ;
8
8
9
9
use Magento \Framework \App \Action \HttpPostActionInterface ;
10
+ use Magento \Framework \App \Request \DataPersistorInterface ;
10
11
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
11
12
12
13
/**
@@ -20,25 +21,35 @@ class Save extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implement
20
21
* @var TimezoneInterface
21
22
*/
22
23
private $ timezone ;
24
+
25
+ /**
26
+ * @var DataPersistorInterface
27
+ */
28
+ private $ dataPersistor ;
23
29
24
30
/**
25
31
* @param \Magento\Backend\App\Action\Context $context
26
32
* @param \Magento\Framework\Registry $coreRegistry
27
33
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
28
34
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
29
35
* @param TimezoneInterface $timezone
36
+ * @param DataPersistorInterface $dataPersistor
30
37
*/
31
38
public function __construct (
32
39
\Magento \Backend \App \Action \Context $ context ,
33
40
\Magento \Framework \Registry $ coreRegistry ,
34
41
\Magento \Framework \App \Response \Http \FileFactory $ fileFactory ,
35
42
\Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter ,
36
- TimezoneInterface $ timezone = null
43
+ TimezoneInterface $ timezone = null ,
44
+ DataPersistorInterface $ dataPersistor = null
37
45
) {
38
46
parent ::__construct ($ context , $ coreRegistry , $ fileFactory , $ dateFilter );
39
47
$ this ->timezone = $ timezone ?? \Magento \Framework \App \ObjectManager::getInstance ()->get (
40
48
TimezoneInterface::class
41
49
);
50
+ $ this ->dataPersistor = $ dataPersistor ?? \Magento \Framework \App \ObjectManager::getInstance ()->get (
51
+ DataPersistorInterface::class
52
+ );
42
53
}
43
54
44
55
/**
@@ -73,12 +84,8 @@ public function execute()
73
84
$ data
74
85
);
75
86
$ data = $ inputFilter ->getUnescaped ();
76
- $ id = $ this ->getRequest ()->getParam ('rule_id ' );
77
- if ($ id ) {
78
- $ model ->load ($ id );
79
- if ($ id != $ model ->getId ()) {
80
- throw new \Magento \Framework \Exception \LocalizedException (__ ('The wrong rule is specified. ' ));
81
- }
87
+ if (!$ this ->checkRuleExists ($ model )) {
88
+ throw new \Magento \Framework \Exception \LocalizedException (__ ('The wrong rule is specified. ' ));
82
89
}
83
90
84
91
$ session = $ this ->_objectManager ->get (\Magento \Backend \Model \Session::class);
@@ -89,6 +96,7 @@ public function execute()
89
96
$ this ->messageManager ->addErrorMessage ($ errorMessage );
90
97
}
91
98
$ session ->setPageData ($ data );
99
+ $ this ->dataPersistor ->set ('sale_rule ' , $ data );
92
100
$ this ->_redirect ('sales_rule/*/edit ' , ['id ' => $ model ->getId ()]);
93
101
return ;
94
102
}
@@ -147,4 +155,22 @@ public function execute()
147
155
}
148
156
$ this ->_redirect ('sales_rule/*/ ' );
149
157
}
158
+
159
+ /**
160
+ * Check if Cart Price Rule with provided id exists.
161
+ *
162
+ * @param \Magento\SalesRule\Model\Rule $model
163
+ * @return bool
164
+ */
165
+ private function checkRuleExists (\Magento \SalesRule \Model \Rule $ model ): bool
166
+ {
167
+ $ id = $ this ->getRequest ()->getParam ('rule_id ' );
168
+ if ($ id ) {
169
+ $ model ->load ($ id );
170
+ if ($ model ->getId () != $ id ) {
171
+ return false ;
172
+ }
173
+ }
174
+ return true ;
175
+ }
150
176
}
0 commit comments