9
9
* The MailChimp eCommerce settings form.
10
10
*/
11
11
function mailchimp_ecommerce_admin_settings () {
12
- $ form ['mailchimp_ecommerce_integration ' ] = array (
13
- '#type ' => 'radios ' ,
14
- '#title ' => 'Enabled Integration ' ,
15
- '#options ' => array (
16
- '' => t ('None ' ),
17
- ),
18
- '#default_value ' => variable_get ('mailchimp_ecommerce_integration ' , '' ),
19
- );
20
- $ form ['mailchimp_ecommerce_notice ' ] = array (
12
+ $ form ['mailchimp_ecommerce_notice ' ] = [
21
13
'#markup ' => t ('This page will allow you to create a store. Once created, you cannot change the list associated with the store. ' ),
22
- ) ;
23
- $ form ['mailchimp_ecommerce_store_name ' ] = array (
14
+ ] ;
15
+ $ form ['mailchimp_ecommerce_store_name ' ] = [
24
16
'#type ' => 'textfield ' ,
25
17
'#title ' => t ('Store Name ' ),
26
18
'#required ' => TRUE ,
27
19
'#default_value ' => variable_get ('mailchimp_ecommerce_store_name ' , '' ),
28
20
'#description ' => t ('The name of your store as it should appear in your MailChimp account. ' ),
29
- ) ;
21
+ ] ;
30
22
31
23
$ mailchimp_lists = mailchimp_get_lists ();
32
- $ list_options = array (
24
+ $ list_options = [
33
25
'' => '-- Select -- ' ,
34
- ) ;
26
+ ] ;
35
27
36
28
foreach ($ mailchimp_lists as $ list_id => $ list ) {
37
29
$ list_options [$ list_id ] = $ list ->name ;
38
30
}
39
31
40
32
if (!empty (variable_get ('mailchimp_ecommerce_list_id ' , '' ))) {
41
33
$ existing_store_id = variable_get ('mailchimp_ecommerce_list_id ' );
42
- $ form ['mailchimp_ecommerce_list_id_existing ' ] = array (
34
+ $ form ['mailchimp_ecommerce_list_id_existing ' ] = [
43
35
'#markup ' => t ('Once created, the list cannot be changed for a given store. This store is connected to the list named ' ) . ' ' . $ list_options [$ existing_store_id ],
44
- ) ;
36
+ ] ;
45
37
}
46
38
else {
47
- $ form ['mailchimp_ecommerce_list_id ' ] = array (
39
+ $ form ['mailchimp_ecommerce_list_id ' ] = [
48
40
'#type ' => 'select ' ,
49
41
'#title ' => t ('Store List ' ),
50
42
'#required ' => TRUE ,
51
43
'#options ' => $ list_options ,
52
44
'#default_value ' => variable_get ('mailchimp_ecommerce_list_id ' , '' ),
53
- ) ;
45
+ ] ;
54
46
}
55
47
56
- // TODO: Can this be moved into the mailchimp_ecommerce_commerce module?
57
48
if (module_exists ('commerce ' )) {
58
- $ form ['mailchimp_ecommere_commerce_default_currency ' ] = array (
49
+ $ form ['mailchimp_ecommere_commerce_default_currency ' ] = [
59
50
'#type ' => 'checkbox ' ,
60
51
'#title ' => t ('Use Commerce Default Currency ' ),
61
52
'#description ' => t ('Drupal Commerce was detected as being installed. Check this box to use the default currency of Commerce ' ),
62
53
'#default_value ' => variable_get ('mailchimp_ecommere_commerce_default_currency ' , '' ),
63
- ) ;
54
+ ] ;
64
55
}
65
56
66
57
// @TODO Make this item go away with AJAX if the Drupal commerce box is checked.
67
- $ list_options_currency = array (
68
- '' => '-- Select -- ' ,
69
- ) + mailchimp_ecommerce_get_currency_codes ();
70
- $ form ['mailchimp_ecommerce_currency ' ] = array (
58
+ $ list_options_currency = [
59
+ '' => '-- Select -- ' ,
60
+ ] + mailchimp_ecommerce_get_currency_codes ();
61
+ $ form ['mailchimp_ecommerce_currency ' ] = [
71
62
'#type ' => 'select ' ,
72
63
'#options ' => $ list_options_currency ,
73
64
'#title ' => t ('Store Currency Code ' ),
74
- );
65
+ '#description ' => t ('This is overridden if you have selected to use the default currency from Commerce. ' ),
66
+ ];
67
+
68
+ $ list_options = [
69
+ '' => '-- Select -- ' ,
70
+ 'TRUE ' => 'Normal Subscriber ' ,
71
+ 'FALSE ' => 'Transactional Subscriber ' ,
72
+ ];
73
+
74
+ $ form ['mailchimp_ecommerce_opt_in ' ] = [
75
+ '#type ' => 'fieldset ' ,
76
+ '#title ' => t ('New User Opt-In Status ' ),
77
+ '#collapsible ' => FALSE ,
78
+ ];
79
+ $ form ['mailchimp_ecommerce_opt_in ' ]['mailchimp_ecommerce_opt_in_status_markup ' ] = [
80
+ '#markup ' => t ('You must decide on the status of customers that entered into
81
+ the eCommerce API. By choosing "<b>Normal Subscriber</b>" in the option
82
+ below, users will added as normal subscribers. If you choose
83
+ "Normal Subscriber", be certain your customers know they are subscribing
84
+ to an email list. If you choose "<b>Transactional Subscriber</b>" below,
85
+ the users will be added as "transactional" users. Transactional users
86
+ cannot be changed via the MailChimp UI. Changing the status of a
87
+ "transactional" user call only be accomplished via the API. For additional
88
+ information, please read the ' ) . ' ' . l ('MailChimp Documentation. ' , 'http://developer.mailchimp.com/documentation/mailchimp/guides/getting-started-with-ecommerce/#about-subscribers-and-customers ' , ['external ' => TRUE ]),
89
+ ];
90
+
91
+ $ form ['mailchimp_ecommerce_opt_in ' ]['mailchimp_ecommerce_opt_in_status ' ] = [
92
+ '#type ' => 'select ' ,
93
+ '#title ' => t ('Opt-In Status For Customers ' ),
94
+ '#required ' => TRUE ,
95
+ '#options ' => $ list_options ,
96
+ '#default_value ' => variable_get ('mailchimp_ecommerce_opt_in_status ' , '' ),
97
+ '#description ' => t ('Choose your opt-in status before using this module. ' ),
98
+ ];
75
99
76
100
$ settings_form = system_settings_form ($ form );
77
101
$ settings_form ['#submit ' ][] = 'mailchimp_ecommerce_admin_settings_submit ' ;
@@ -84,9 +108,11 @@ function mailchimp_ecommerce_admin_settings() {
84
108
*/
85
109
function mailchimp_ecommerce_admin_settings_submit ($ form , &$ form_state ) {
86
110
$ store_id = variable_get ('mailchimp_ecommerce_store_id ' , NULL );
111
+ if (variable_get ('mailchimp_ecommerce_store_id ' , NULL ) == NULL ) {
112
+ $ store_id = mailchimp_ecommerce_generate_store_id ();
113
+ variable_set ('mailchimp_ecommerce_store_id ' , $ store_id );
114
+ }
87
115
88
- // Add / update store only if an eCommerce integration is selected.
89
- if (!empty ($ form_state ['values ' ]['mailchimp_ecommerce_integration ' ])) {
90
116
if ($ store_id != NULL ) {
91
117
// Detect if Commerce is installed and use the default currency.
92
118
if (!empty ($ form_state ['values ' ]['mailchimp_ecommere_commerce_default_currency ' ])) {
@@ -114,8 +140,5 @@ function mailchimp_ecommerce_admin_settings_submit($form, &$form_state) {
114
140
$ currency );
115
141
}
116
142
}
117
- }
118
- else {
119
- variable_del ('mailchimp_ecommerce_integration ' );
120
- }
143
+
121
144
}
0 commit comments