6
6
7
7
namespace Magento \Catalog \Controller \Adminhtml \Product ;
8
8
9
+ use Magento \Backend \App \Action \Context ;
9
10
use Magento \Catalog \Api \AttributeSetRepositoryInterface ;
10
11
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
12
+ use Magento \Catalog \Controller \Adminhtml \Product ;
11
13
use Magento \Eav \Api \AttributeGroupRepositoryInterface ;
12
14
use Magento \Eav \Api \AttributeManagementInterface ;
13
15
use Magento \Eav \Api \AttributeRepositoryInterface ;
16
18
use Magento \Eav \Api \Data \AttributeInterface ;
17
19
use Magento \Eav \Api \Data \AttributeSetInterface ;
18
20
use Magento \Framework \Api \SearchCriteriaBuilder ;
21
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
22
+ use Magento \Framework \Controller \Result \Json ;
23
+ use Magento \Framework \Controller \Result \JsonFactory ;
24
+ use Magento \Framework \DataObject ;
19
25
use Magento \Framework \Exception \LocalizedException ;
26
+ use Magento \Framework \App \ObjectManager ;
20
27
use Psr \Log \LoggerInterface ;
28
+ use Magento \Framework \Exception \NoSuchEntityException ;
21
29
use Magento \Framework \Api \ExtensionAttributesFactory ;
22
30
23
31
/**
24
32
* Class AddAttributeToTemplate
25
33
*
26
34
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
35
*/
28
- class AddAttributeToTemplate extends \ Magento \ Catalog \ Controller \ Adminhtml \ Product
36
+ class AddAttributeToTemplate extends Product implements HttpPostActionInterface
29
37
{
30
38
/**
31
- * @var \Magento\Framework\Controller\Result\ JsonFactory
39
+ * @var JsonFactory
32
40
*/
33
41
protected $ resultJsonFactory ;
34
42
@@ -75,33 +83,34 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
75
83
/**
76
84
* Constructor
77
85
*
78
- * @param \Magento\Backend\App\Action\ Context $context
86
+ * @param Context $context
79
87
* @param Builder $productBuilder
80
- * @param \Magento\Framework\Controller\Result\ JsonFactory $resultJsonFactory
81
- * @param \Magento\Eav\Api\Data\ AttributeGroupInterfaceFactory|null $attributeGroupFactory
88
+ * @param JsonFactory $resultJsonFactory
89
+ * @param AttributeGroupInterfaceFactory|null $attributeGroupFactory
82
90
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
91
+ * @SuppressWarnings(PHPMD.LongVariable)
83
92
*/
84
93
public function __construct (
85
- \ Magento \ Backend \ App \ Action \ Context $ context ,
86
- \ Magento \ Catalog \ Controller \ Adminhtml \ Product \ Builder $ productBuilder ,
87
- \ Magento \ Framework \ Controller \ Result \ JsonFactory $ resultJsonFactory ,
88
- \ Magento \ Eav \ Api \ Data \ AttributeGroupInterfaceFactory $ attributeGroupFactory = null
94
+ Context $ context ,
95
+ Builder $ productBuilder ,
96
+ JsonFactory $ resultJsonFactory ,
97
+ AttributeGroupInterfaceFactory $ attributeGroupFactory = null
89
98
) {
90
99
parent ::__construct ($ context , $ productBuilder );
91
100
$ this ->resultJsonFactory = $ resultJsonFactory ;
92
- $ this ->attributeGroupFactory = $ attributeGroupFactory ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
93
- ->get (\ Magento \ Eav \ Api \ Data \ AttributeGroupInterfaceFactory::class);
101
+ $ this ->attributeGroupFactory = $ attributeGroupFactory ?: ObjectManager::getInstance ()
102
+ ->get (AttributeGroupInterfaceFactory::class);
94
103
}
95
104
96
105
/**
97
106
* Add attribute to attribute set
98
107
*
99
- * @return \Magento\Framework\Controller\Result\ Json
108
+ * @return Json
100
109
*/
101
110
public function execute ()
102
111
{
103
112
$ request = $ this ->getRequest ();
104
- $ response = new \ Magento \ Framework \ DataObject ();
113
+ $ response = new DataObject ();
105
114
$ response ->setError (false );
106
115
107
116
try {
@@ -124,12 +133,12 @@ public function execute()
124
133
->getItems ();
125
134
126
135
if (!$ attributeGroupItems ) {
127
- throw new \ Magento \ Framework \ Exception \ NoSuchEntityException ;
136
+ throw new NoSuchEntityException ;
128
137
}
129
138
130
139
/** @var AttributeGroupInterface $attributeGroup */
131
140
$ attributeGroup = reset ($ attributeGroupItems );
132
- } catch (\ Magento \ Framework \ Exception \ NoSuchEntityException $ e ) {
141
+ } catch (NoSuchEntityException $ e ) {
133
142
/** @var AttributeGroupInterface $attributeGroup */
134
143
$ attributeGroup = $ this ->attributeGroupFactory ->create ();
135
144
}
@@ -176,101 +185,114 @@ public function execute()
176
185
* Adding basic filters
177
186
*
178
187
* @return SearchCriteriaBuilder
179
- * @throws \Magento\Framework\Exception\ LocalizedException
188
+ * @throws LocalizedException
180
189
*/
181
190
private function getBasicAttributeSearchCriteriaBuilder ()
182
191
{
183
- $ attributeIds = (array )$ this ->getRequest ()->getParam ('attributeIds ' , []);
192
+ $ attributeIds = (array ) $ this ->getRequest ()->getParam ('attributeIds ' , []);
184
193
185
194
if (empty ($ attributeIds ['selected ' ])) {
186
195
throw new LocalizedException (__ ('Attributes were missing and must be specified. ' ));
187
196
}
188
197
189
198
return $ this ->getSearchCriteriaBuilder ()
190
- ->addFilter ('attribute_set_id ' , new \Zend_Db_Expr ('null ' ), 'is ' )
191
199
->addFilter ('attribute_id ' , [$ attributeIds ['selected ' ]], 'in ' );
192
200
}
193
201
194
202
/**
203
+ * Get AttributeRepositoryInterface
204
+ *
195
205
* @return AttributeRepositoryInterface
196
206
*/
197
207
private function getAttributeRepository ()
198
208
{
199
209
if (null === $ this ->attributeRepository ) {
200
- $ this ->attributeRepository = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
201
- ->get (\ Magento \ Eav \ Api \ AttributeRepositoryInterface::class);
210
+ $ this ->attributeRepository = ObjectManager::getInstance ()
211
+ ->get (AttributeRepositoryInterface::class);
202
212
}
203
213
return $ this ->attributeRepository ;
204
214
}
205
215
206
216
/**
217
+ * Get AttributeSetRepositoryInterface
218
+ *
207
219
* @return AttributeSetRepositoryInterface
208
220
*/
209
221
private function getAttributeSetRepository ()
210
222
{
211
223
if (null === $ this ->attributeSetRepository ) {
212
- $ this ->attributeSetRepository = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
213
- ->get (\ Magento \ Catalog \ Api \ AttributeSetRepositoryInterface::class);
224
+ $ this ->attributeSetRepository = ObjectManager::getInstance ()
225
+ ->get (AttributeSetRepositoryInterface::class);
214
226
}
215
227
return $ this ->attributeSetRepository ;
216
228
}
217
229
218
230
/**
231
+ * Get AttributeGroupInterface
232
+ *
219
233
* @return AttributeGroupRepositoryInterface
220
234
*/
221
235
private function getAttributeGroupRepository ()
222
236
{
223
237
if (null === $ this ->attributeGroupRepository ) {
224
- $ this ->attributeGroupRepository = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
225
- ->get (\ Magento \ Eav \ Api \ AttributeGroupRepositoryInterface::class);
238
+ $ this ->attributeGroupRepository = ObjectManager::getInstance ()
239
+ ->get (AttributeGroupRepositoryInterface::class);
226
240
}
227
241
return $ this ->attributeGroupRepository ;
228
242
}
229
243
230
244
/**
245
+ * Get SearchCriteriaBuilder
246
+ *
231
247
* @return SearchCriteriaBuilder
232
248
*/
233
249
private function getSearchCriteriaBuilder ()
234
250
{
235
251
if (null === $ this ->searchCriteriaBuilder ) {
236
- $ this ->searchCriteriaBuilder = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
237
- ->get (\ Magento \ Framework \ Api \ SearchCriteriaBuilder::class);
252
+ $ this ->searchCriteriaBuilder = ObjectManager::getInstance ()
253
+ ->get (SearchCriteriaBuilder::class);
238
254
}
239
255
return $ this ->searchCriteriaBuilder ;
240
256
}
241
257
242
258
/**
259
+ * Get AttributeManagementInterface
260
+ *
243
261
* @return AttributeManagementInterface
244
262
*/
245
263
private function getAttributeManagement ()
246
264
{
247
265
if (null === $ this ->attributeManagement ) {
248
- $ this ->attributeManagement = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
249
- ->get (\ Magento \ Eav \ Api \ AttributeManagementInterface::class);
266
+ $ this ->attributeManagement = ObjectManager::getInstance ()
267
+ ->get (AttributeManagementInterface::class);
250
268
}
251
269
return $ this ->attributeManagement ;
252
270
}
253
271
254
272
/**
273
+ * Get LoggerInterface
274
+ *
255
275
* @return LoggerInterface
256
276
*/
257
277
private function getLogger ()
258
278
{
259
279
if (null === $ this ->logger ) {
260
- $ this ->logger = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
261
- ->get (\ Psr \ Log \ LoggerInterface::class);
280
+ $ this ->logger = ObjectManager::getInstance ()
281
+ ->get (LoggerInterface::class);
262
282
}
263
283
return $ this ->logger ;
264
284
}
265
285
266
286
/**
287
+ * Get ExtensionAttributesFactory.
288
+ *
267
289
* @return ExtensionAttributesFactory
268
290
*/
269
291
private function getExtensionAttributesFactory ()
270
292
{
271
293
if (null === $ this ->extensionAttributesFactory ) {
272
- $ this ->extensionAttributesFactory = \ Magento \ Framework \ App \ ObjectManager::getInstance ()
273
- ->get (\ Magento \ Framework \ Api \ ExtensionAttributesFactory::class);
294
+ $ this ->extensionAttributesFactory = ObjectManager::getInstance ()
295
+ ->get (ExtensionAttributesFactory::class);
274
296
}
275
297
return $ this ->extensionAttributesFactory ;
276
298
}
0 commit comments