22
22
*/
23
23
24
24
namespace Lof \CustomCustomerInfo \Setup ;
25
-
26
25
use Magento \Framework \Setup \UpgradeDataInterface ;
27
- use Magento \Framework \Setup \ModuleContextInterface ;
28
26
use Magento \Framework \Setup \ModuleDataSetupInterface ;
27
+ use Magento \Framework \Setup \ModuleContextInterface ;
28
+ use Magento \Customer \Setup \CustomerSetupFactory ;
29
+ use Magento \Customer \Model \Customer ;
30
+ use Magento \Eav \Model \Entity \Attribute \Set as AttributeSet ;
31
+ use Magento \Eav \Model \Entity \Attribute \SetFactory as AttributeSetFactory ;
32
+
29
33
30
- class UpgradeData implements UpgradeDataInterface
31
- {
34
+ class UpgradeData implements UpgradeDataInterface {
32
35
33
- /**
34
- * {@inheritdoc}
35
- */
36
- public function upgrade (
37
- ModuleDataSetupInterface $ setup ,
38
- ModuleContextInterface $ context
36
+ protected $ customerSetupFactory ;
37
+ private $ attributeSetFactory ;
38
+
39
+ public function __construct (
40
+ CustomerSetupFactory $ customerSetupFactory , AttributeSetFactory $ attributeSetFactory
39
41
) {
40
- if (version_compare ($ context ->getVersion (), "1.0.0 " , "< " )) {
41
- //Your upgrade script
42
+ $ this ->customerSetupFactory = $ customerSetupFactory ;
43
+ $ this ->attributeSetFactory = $ attributeSetFactory ;
44
+ }
45
+
46
+
47
+ public function upgrade ( ModuleDataSetupInterface $ setup , ModuleContextInterface $ context ) {
48
+
49
+ if (version_compare ($ context ->getVersion (), '1.0.4 ' ) < 0 ) {
50
+
51
+ $ setup ->startSetup ();
52
+ $ customerSetup = $ this ->customerSetupFactory ->create (['setup ' => $ setup ]);
53
+
54
+ $ customerEntity = $ customerSetup ->getEavConfig ()->getEntityType ('customer ' );
55
+ $ attributeSetId = $ customerEntity ->getDefaultAttributeSetId ();
56
+
57
+ $ attributeSet = $ this ->attributeSetFactory ->create ();
58
+ $ attributeGroupId = $ attributeSet ->getDefaultGroupId ($ attributeSetId );
59
+
60
+ $ customerSetup ->addAttribute (\Magento \Customer \Model \Customer::ENTITY , 'customer_avatar ' , [
61
+ 'type ' => 'text ' ,
62
+ 'label ' => 'Image ' ,
63
+ 'input ' => 'file ' ,
64
+ "source " => '' ,
65
+ 'required ' => false ,
66
+ 'default ' => '0 ' ,
67
+ 'visible ' => true ,
68
+ 'user_defined ' => true ,
69
+ 'sort_order ' => 210 ,
70
+ 'position ' => 210 ,
71
+ 'system ' => false ,
72
+ ]);
73
+
74
+ $ image = $ customerSetup ->getEavConfig ()->getAttribute (Customer::ENTITY , 'customer_avatar ' )
75
+ ->addData ([
76
+ 'attribute_set_id ' => $ attributeSetId ,
77
+ 'attribute_group_id ' => $ attributeGroupId ,
78
+ 'used_in_forms ' => ['adminhtml_customer ' , 'customer_account_create ' , 'customer_account_edit ' ],
79
+ ]);
80
+
81
+ $ image ->save ();
82
+ $ setup ->endSetup ();
42
83
}
43
84
}
44
- }
85
+ }
0 commit comments