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