77namespace Magento \CatalogRule \Controller \Adminhtml \Promo \Catalog ;
88
99use Magento \CatalogRule \Controller \Adminhtml \Promo \Catalog as CatalogAction ;
10+ use Magento \CatalogRule \Model \Rule ;
1011use Magento \Framework \App \Action \HttpGetActionInterface ;
1112use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
1213use Magento \Rule \Model \Condition \AbstractCondition ;
@@ -21,34 +22,36 @@ class NewConditionHtml extends CatalogAction implements HttpPostActionInterface,
2122 */
2223 public function execute ()
2324 {
24- $ id = $ this ->getRequest ()->getParam ('id ' );
25- $ formName = $ this ->getRequest ()->getParam ('form_namespace ' );
26- $ typeArr = explode ('| ' , str_replace ('- ' , '/ ' , $ this ->getRequest ()->getParam ('type ' , '' )));
27- $ type = $ typeArr [0 ];
25+ $ objectId = $ this ->getRequest ()->getParam ('id ' );
26+ $ formNamespace = $ this ->getRequest ()->getParam ('form_namespace ' );
27+ $ types = explode (
28+ '| ' ,
29+ str_replace ('- ' , '/ ' , $ this ->getRequest ()->getParam ('type ' , '' ))
30+ );
31+ $ objectType = $ types [0 ];
32+ $ reponseBody = '' ;
2833
29- if (class_exists ($ type ) && !in_array (ConditionInterface::class, class_implements ($ type ))) {
30- $ html = '' ;
31- $ this ->getResponse ()->setBody ($ html );
34+ if (class_exists ($ objectType ) && !in_array (ConditionInterface::class, class_implements ($ objectType ))) {
35+ $ this ->getResponse ()->setBody ($ reponseBody );
3236 return ;
3337 }
3438
35- $ model = $ this ->_objectManager ->create ($ type )
36- ->setId ($ id )
37- ->setType ($ type )
38- ->setRule ($ this ->_objectManager ->create (\ Magento \ CatalogRule \ Model \ Rule::class))
39+ $ conditionModel = $ this ->_objectManager ->create ($ objectType )
40+ ->setId ($ objectId )
41+ ->setType ($ objectType )
42+ ->setRule ($ this ->_objectManager ->create (Rule::class))
3943 ->setPrefix ('conditions ' );
4044
41- if (!empty ($ typeArr [1 ])) {
42- $ model ->setAttribute ($ typeArr [1 ]);
45+ if (!empty ($ types [1 ])) {
46+ $ conditionModel ->setAttribute ($ types [1 ]);
4347 }
4448
45- if ($ model instanceof AbstractCondition) {
46- $ model ->setJsFormObject ($ this ->getRequest ()->getParam ('form ' ));
47- $ model ->setFormName ($ formName );
48- $ html = $ model ->asHtmlRecursive ();
49- } else {
50- $ html = '' ;
49+ if ($ conditionModel instanceof AbstractCondition) {
50+ $ conditionModel ->setJsFormObject ($ this ->getRequest ()->getParam ('form ' ));
51+ $ conditionModel ->setFormName ($ formNamespace );
52+ $ reponseBody = $ conditionModel ->asHtmlRecursive ();
5153 }
52- $ this ->getResponse ()->setBody ($ html );
54+
55+ $ this ->getResponse ()->setBody ($ reponseBody );
5356 }
5457}
0 commit comments