5
5
*/
6
6
namespace Magento \Catalog \Setup ;
7
7
8
+ use Magento \Catalog \Api \Data \ProductAttributeInterface ;
9
+ use Magento \Eav \Model \Entity \Attribute \ScopedAttributeInterface ;
8
10
use Magento \Framework \Setup \UpgradeDataInterface ;
9
11
use Magento \Framework \Setup \ModuleContextInterface ;
10
12
use Magento \Framework \Setup \ModuleDataSetupInterface ;
11
13
use Magento \Eav \Setup \EavSetup ;
14
+ use Magento \Eav \Setup \EavSetupFactory ;
12
15
13
16
/**
14
17
* Upgrade Data script
@@ -26,32 +29,20 @@ class UpgradeData implements UpgradeDataInterface
26
29
/**
27
30
* EAV setup factory
28
31
*
29
- * @var \Magento\Eav\Setup\ EavSetupFactory
32
+ * @var EavSetupFactory
30
33
*/
31
34
private $ eavSetupFactory ;
32
35
33
- /**
34
- * Attributes cache management.
35
- *
36
- * @var \Magento\Eav\Model\Entity\AttributeCache
37
- */
38
- private $ attributeCache ;
39
-
40
36
/**
41
37
* Init
42
38
*
43
39
* @param CategorySetupFactory $categorySetupFactory
44
- * @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
45
- * @param \Magento\Eav\Model\Entity\AttributeCache $attributeCache
40
+ * @param EavSetupFactory $eavSetupFactory
46
41
*/
47
- public function __construct (
48
- CategorySetupFactory $ categorySetupFactory ,
49
- \Magento \Eav \Setup \EavSetupFactory $ eavSetupFactory ,
50
- \Magento \Eav \Model \Entity \AttributeCache $ attributeCache
51
- ) {
42
+ public function __construct (CategorySetupFactory $ categorySetupFactory , EavSetupFactory $ eavSetupFactory )
43
+ {
52
44
$ this ->categorySetupFactory = $ categorySetupFactory ;
53
45
$ this ->eavSetupFactory = $ eavSetupFactory ;
54
- $ this ->attributeCache = $ attributeCache ;
55
46
}
56
47
57
48
/**
@@ -96,7 +87,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
96
87
97
88
if (version_compare ($ context ->getVersion (), '2.0.2 ' ) < 0 ) {
98
89
// set new resource model paths
99
- /** @var CategorySetup $categorySetup */
90
+ /** @var \Magento\Catalog\Setup\ CategorySetup $categorySetup */
100
91
$ categorySetup = $ this ->categorySetupFactory ->create (['setup ' => $ setup ]);
101
92
$ categorySetup ->updateEntityType (
102
93
\Magento \Catalog \Model \Category::ENTITY ,
@@ -137,157 +128,151 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
137
128
}
138
129
139
130
if (version_compare ($ context ->getVersion (), '2.0.3 ' ) < 0 ) {
140
- /** @var CategorySetup $categorySetup */
131
+ /** @var \Magento\Catalog\Setup\ CategorySetup $categorySetup */
141
132
$ categorySetup = $ this ->categorySetupFactory ->create (['setup ' => $ setup ]);
142
133
$ categorySetup ->updateAttribute (3 , 54 , 'default_value ' , 1 );
143
134
}
144
135
145
136
if (version_compare ($ context ->getVersion (), '2.0.4 ' ) < 0 ) {
146
- $ mediaBackendType = 'static ' ;
147
- $ mediaBackendModel = null ;
148
- /** @var CategorySetup $categorySetup */
137
+ /** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
149
138
$ categorySetup = $ this ->categorySetupFactory ->create (['setup ' => $ setup ]);
150
139
$ categorySetup ->updateAttribute (
151
140
'catalog_product ' ,
152
141
'media_gallery ' ,
153
142
'backend_type ' ,
154
- $ mediaBackendType
143
+ ' static '
155
144
);
156
145
$ categorySetup ->updateAttribute (
157
146
'catalog_product ' ,
158
147
'media_gallery ' ,
159
- 'backend_model ' ,
160
- $ mediaBackendModel
148
+ 'backend_model '
161
149
);
162
-
163
- $ this ->changeMediaGalleryAttributeInCache ($ mediaBackendType , $ mediaBackendModel );
164
150
}
165
151
166
152
if (version_compare ($ context ->getVersion (), '2.0.5 ' , '< ' )) {
167
- /** @var CategorySetup $categorySetup */
153
+ /** @var \Magento\Catalog\Setup\ CategorySetup $categorySetup */
168
154
$ categorySetup = $ this ->categorySetupFactory ->create (['setup ' => $ setup ]);
169
155
170
156
//Product Details tab
171
157
$ categorySetup ->updateAttribute (
172
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
158
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
173
159
'status ' ,
174
160
'frontend_label ' ,
175
161
'Enable Product ' ,
176
162
5
177
163
);
178
164
$ categorySetup ->updateAttribute (
179
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
165
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
180
166
'name ' ,
181
167
'frontend_label ' ,
182
168
'Product Name '
183
169
);
184
- $ attributeSetId = $ categorySetup ->getDefaultAttributeSetId (\Magento \Catalog \Model \Product::ENTITY );
185
170
$ categorySetup ->addAttributeToGroup (
186
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
187
- $ attributeSetId ,
171
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
172
+ ' Default ' ,
188
173
'Product Details ' ,
189
174
'visibility ' ,
190
175
80
191
176
);
192
177
$ categorySetup ->addAttributeToGroup (
193
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
194
- $ attributeSetId ,
178
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
179
+ ' Default ' ,
195
180
'Product Details ' ,
196
181
'news_from_date ' ,
197
182
90
198
183
);
199
184
$ categorySetup ->addAttributeToGroup (
200
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
201
- $ attributeSetId ,
185
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
186
+ ' Default ' ,
202
187
'Product Details ' ,
203
188
'news_to_date ' ,
204
189
100
205
190
);
206
191
$ categorySetup ->addAttributeToGroup (
207
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
208
- $ attributeSetId ,
192
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
193
+ ' Default ' ,
209
194
'Product Details ' ,
210
195
'country_of_manufacture ' ,
211
196
110
212
197
);
213
198
214
199
//Content tab
215
200
$ categorySetup ->addAttributeGroup (
216
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
217
- $ attributeSetId ,
201
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
202
+ ' Default ' ,
218
203
'Content ' ,
219
204
15
220
205
);
221
206
$ categorySetup ->updateAttributeGroup (
222
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
223
- $ attributeSetId ,
207
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
208
+ ' Default ' ,
224
209
'Content ' ,
225
210
'tab_group_code ' ,
226
211
'basic '
227
212
);
228
213
$ categorySetup ->addAttributeToGroup (
229
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
230
- $ attributeSetId ,
214
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
215
+ ' Default ' ,
231
216
'Content ' ,
232
217
'description '
233
218
);
234
219
$ categorySetup ->addAttributeToGroup (
235
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
236
- $ attributeSetId ,
220
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
221
+ ' Default ' ,
237
222
'Content ' ,
238
223
'short_description ' ,
239
224
100
240
225
);
241
226
242
227
//Images tab
243
228
$ groupId = (int )$ categorySetup ->getAttributeGroupByCode (
244
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
245
- $ attributeSetId ,
229
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
230
+ ' Default ' ,
246
231
'image-management ' ,
247
232
'attribute_group_id '
248
233
);
249
234
$ categorySetup ->addAttributeToGroup (
250
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
251
- $ attributeSetId ,
235
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
236
+ ' Default ' ,
252
237
$ groupId ,
253
238
'image ' ,
254
239
1
255
240
);
256
241
$ categorySetup ->updateAttributeGroup (
257
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
258
- $ attributeSetId ,
242
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
243
+ ' Default ' ,
259
244
$ groupId ,
260
245
'attribute_group_name ' ,
261
246
'Images '
262
247
);
263
248
$ categorySetup ->updateAttribute (
264
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
249
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
265
250
'image ' ,
266
251
'frontend_label ' ,
267
252
'Base '
268
253
);
269
254
$ categorySetup ->updateAttribute (
270
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
255
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
271
256
'small_image ' ,
272
257
'frontend_label ' ,
273
258
'Small '
274
259
);
275
260
$ categorySetup ->updateAttribute (
276
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
261
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
277
262
'image ' ,
278
263
'frontend_input_renderer ' ,
279
264
null
280
265
);
281
266
282
267
//Design tab
283
268
$ categorySetup ->updateAttribute (
284
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
269
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
285
270
'page_layout ' ,
286
271
'frontend_label ' ,
287
272
'Layout '
288
273
);
289
274
$ categorySetup ->updateAttribute (
290
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
275
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
291
276
'custom_layout_update ' ,
292
277
'frontend_label ' ,
293
278
'Layout Update XML ' ,
@@ -296,70 +281,70 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
296
281
297
282
//Schedule Design Update tab
298
283
$ categorySetup ->addAttributeGroup (
299
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
300
- $ attributeSetId ,
284
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
285
+ ' Default ' ,
301
286
'Schedule Design Update ' ,
302
287
55
303
288
);
304
289
$ categorySetup ->updateAttributeGroup (
305
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
306
- $ attributeSetId ,
290
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
291
+ ' Default ' ,
307
292
'Schedule Design Update ' ,
308
293
'tab_group_code ' ,
309
294
'advanced '
310
295
);
311
296
$ categorySetup ->addAttributeToGroup (
312
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
313
- $ attributeSetId ,
297
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
298
+ ' Default ' ,
314
299
'Schedule Design Update ' ,
315
300
'custom_design_from ' ,
316
301
20
317
302
);
318
303
$ categorySetup ->addAttributeToGroup (
319
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
320
- $ attributeSetId ,
304
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
305
+ ' Default ' ,
321
306
'Schedule Design Update ' ,
322
307
'custom_design_to ' ,
323
308
30
324
309
);
325
310
$ categorySetup ->updateAttribute (
326
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
311
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
327
312
'custom_design ' ,
328
313
'frontend_label ' ,
329
314
'New Theme ' ,
330
315
40
331
316
);
332
317
$ categorySetup ->addAttributeToGroup (
333
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
334
- $ attributeSetId ,
318
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
319
+ ' Default ' ,
335
320
'Schedule Design Update ' ,
336
321
'custom_design '
337
322
);
338
323
$ categorySetup ->addAttribute (
339
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
324
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
340
325
'custom_layout ' ,
341
326
[
342
327
'type ' => 'varchar ' ,
343
328
'label ' => 'New Layout ' ,
344
329
'input ' => 'select ' ,
345
- 'source ' => \ Magento \Catalog \Model \Product \Attribute \Source \Layout::class ,
330
+ 'source ' => ' Magento\Catalog\Model\Product\Attribute\Source\Layout ' ,
346
331
'required ' => false ,
347
332
'sort_order ' => 50 ,
348
- 'global ' => \ Magento \ Eav \ Model \ Entity \ Attribute \ ScopedAttributeInterface::SCOPE_STORE ,
333
+ 'global ' => ScopedAttributeInterface::SCOPE_STORE ,
349
334
'group ' => 'Schedule Design Update ' ,
350
335
'is_used_in_grid ' => true ,
351
336
'is_visible_in_grid ' => false ,
352
337
'is_filterable_in_grid ' => false
353
338
]
354
339
);
355
340
}
356
-
341
+
357
342
if (version_compare ($ context ->getVersion (), '2.0.7 ' ) < 0 ) {
358
343
/** @var EavSetup $eavSetup */
359
- $ eavSetup = $ this ->eavSetupFactory ->create (['setup ' => $ setup ]);
344
+ $ eavSetup = $ this ->eavSetupFactory ->create (['setup ' => $ setup ]);
360
345
361
346
$ eavSetup ->updateAttribute (
362
- \ Magento \ Catalog \ Model \Product:: ENTITY ,
347
+ ProductAttributeInterface:: ENTITY_TYPE_CODE ,
363
348
'meta_description ' ,
364
349
[
365
350
'note ' => 'Maximum 255 chars. Meta Description should optimally be between 150-160 characters '
@@ -368,7 +353,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
368
353
}
369
354
370
355
if (version_compare ($ context ->getVersion (), '2.1.3 ' ) < 0 ) {
371
- /** @var CategorySetup $categorySetup */
356
+ /** @var \Magento\Catalog\Setup\ CategorySetup $categorySetup */
372
357
$ categorySetup = $ this ->categorySetupFactory ->create (['setup ' => $ setup ]);
373
358
$ this ->changePriceAttributeDefaultScope ($ categorySetup );
374
359
}
@@ -377,7 +362,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
377
362
}
378
363
379
364
/**
380
- * @param CategorySetup $categorySetup
365
+ * @param \Magento\Catalog\Setup\ CategorySetup $categorySetup
381
366
* @return void
382
367
*/
383
368
private function changePriceAttributeDefaultScope ($ categorySetup )
@@ -394,30 +379,4 @@ private function changePriceAttributeDefaultScope($categorySetup)
394
379
395
380
}
396
381
}
397
-
398
- /**
399
- * Change media_gallery attribute metadata in cache.
400
- *
401
- * @param string $mediaBackendType
402
- * @param string $mediaBackendModel
403
- * @return void
404
- */
405
- private function changeMediaGalleryAttributeInCache ($ mediaBackendType , $ mediaBackendModel )
406
- {
407
- // need to do, because media_gallery has backend model in cache.
408
- $ catalogProductAttributes = $ this ->attributeCache ->getAttributes (
409
- \Magento \Catalog \Model \Product::ENTITY ,
410
- '0-0 '
411
- );
412
-
413
- if (is_array ($ catalogProductAttributes )) {
414
- /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $catalogProductAttribute */
415
- foreach ($ catalogProductAttributes as $ catalogProductAttribute ) {
416
- if ($ catalogProductAttribute ->getAttributeCode () == 'media_gallery ' ) {
417
- $ catalogProductAttribute ->setBackendModel ($ mediaBackendModel );
418
- $ catalogProductAttribute ->setBackendType ($ mediaBackendType );
419
- }
420
- }
421
- }
422
- }
423
382
}
0 commit comments