6
6
*/
7
7
namespace Magento \Catalog \Controller \Adminhtml \Product \Set ;
8
8
9
+ use Magento \Framework \App \ObjectManager ;
10
+
11
+ /**
12
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
+ */
9
14
class Save extends \Magento \Catalog \Controller \Adminhtml \Product \Set
10
15
{
11
16
/**
@@ -17,22 +22,49 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Set
17
22
* @var \Magento\Framework\Controller\Result\JsonFactory
18
23
*/
19
24
protected $ resultJsonFactory ;
20
-
25
+
26
+ /*
27
+ * @var \Magento\Eav\Model\Entity\Attribute\SetFactory
28
+ */
29
+ private $ attributeSetFactory ;
30
+
31
+ /*
32
+ * @var \Magento\Framework\Filter\FilterManager
33
+ */
34
+ private $ filterManager ;
35
+
36
+ /*
37
+ * @var \Magento\Framework\Json\Helper\Data
38
+ */
39
+ private $ jsonHelper ;
40
+
21
41
/**
22
42
* @param \Magento\Backend\App\Action\Context $context
23
43
* @param \Magento\Framework\Registry $coreRegistry
24
44
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
25
45
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
46
+ * @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
47
+ * @param \Magento\Framework\Filter\FilterManager $filterManager
48
+ * @param \Magento\Framework\Json\Helper\Data $jsonHelper
26
49
*/
27
50
public function __construct (
28
51
\Magento \Backend \App \Action \Context $ context ,
29
52
\Magento \Framework \Registry $ coreRegistry ,
30
53
\Magento \Framework \View \LayoutFactory $ layoutFactory ,
31
- \Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory
54
+ \Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory ,
55
+ \Magento \Eav \Model \Entity \Attribute \SetFactory $ attributeSetFactory = null ,
56
+ \Magento \Framework \Filter \FilterManager $ filterManager = null ,
57
+ \Magento \Framework \Json \Helper \Data $ jsonHelper = null
32
58
) {
33
59
parent ::__construct ($ context , $ coreRegistry );
34
60
$ this ->layoutFactory = $ layoutFactory ;
35
61
$ this ->resultJsonFactory = $ resultJsonFactory ;
62
+ $ this ->attributeSetFactory = $ attributeSetFactory ?: ObjectManager::getInstance ()
63
+ ->get (\Magento \Eav \Model \Entity \Attribute \SetFactory::class);
64
+ $ this ->filterManager = $ filterManager ?: ObjectManager::getInstance ()
65
+ ->get (\Magento \Framework \Filter \FilterManager::class);
66
+ $ this ->jsonHelper = $ jsonHelper ?: ObjectManager::getInstance ()
67
+ ->get (\Magento \Framework \Json \Helper \Data::class);
36
68
}
37
69
38
70
/**
@@ -65,16 +97,12 @@ public function execute()
65
97
$ isNewSet = $ this ->getRequest ()->getParam ('gotoEdit ' , false ) == '1 ' ;
66
98
67
99
/* @var $model \Magento\Eav\Model\Entity\Attribute\Set */
68
- $ model = $ this ->_objectManager ->create (\Magento \Eav \Model \Entity \Attribute \Set::class)
69
- ->setEntityTypeId ($ entityTypeId );
70
-
71
- /** @var $filterManager \Magento\Framework\Filter\FilterManager */
72
- $ filterManager = $ this ->_objectManager ->get (\Magento \Framework \Filter \FilterManager::class);
100
+ $ model = $ this ->attributeSetFactory ->create ()->setEntityTypeId ($ entityTypeId );
73
101
74
102
try {
75
103
if ($ isNewSet ) {
76
104
//filter html tags
77
- $ name = $ filterManager ->stripTags ($ this ->getRequest ()->getParam ('attribute_set_name ' ));
105
+ $ name = $ this -> filterManager ->stripTags ($ this ->getRequest ()->getParam ('attribute_set_name ' ));
78
106
$ model ->setAttributeSetName (trim ($ name ));
79
107
} else {
80
108
if ($ attributeSetId ) {
@@ -85,11 +113,10 @@ public function execute()
85
113
__ ('This attribute set no longer exists. ' )
86
114
);
87
115
}
88
- $ data = $ this ->_objectManager ->get (\Magento \Framework \Json \Helper \Data::class)
89
- ->jsonDecode ($ this ->getRequest ()->getPost ('data ' ));
116
+ $ data = $ this ->jsonHelper ->jsonDecode ($ this ->getRequest ()->getPost ('data ' ));
90
117
91
118
//filter html tags
92
- $ data ['attribute_set_name ' ] = $ filterManager ->stripTags ($ data ['attribute_set_name ' ]);
119
+ $ data ['attribute_set_name ' ] = $ this -> filterManager ->stripTags ($ data ['attribute_set_name ' ]);
93
120
94
121
$ model ->organizeData ($ data );
95
122
}
0 commit comments