-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnk.install
693 lines (608 loc) · 20.7 KB
/
cnk.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
<?php
/**
* cnk profile install hooks - things to do when install is run
TO DO
profile specific shortcuts
v GST
GST rules
v roles
permissions
v dummy conten
locale
imagecache presets
v default currencies
v ratings
australia post ( look to sandbox )
*/
/**
* @file
* Performs a standard Drupal installation with additional configuration of the
* Drupal Commerce modules and components.
*/
// Define some Commerce Kickstart specific components.
define('KICKSTART_DEFAULT_THEME', 'bartik');
define('KICKSTART_ADMIN_THEME', 'seven');
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*/
function cnk_install() {
print "Running standard install\n";
// from the drupal standard profile
include_once DRUPAL_ROOT . '/profiles/standard/standard.install';
standard_install();
// Set some variables
$acme_settings = array(
'image_jpeg_quality' => '90',
);
foreach ($acme_settings as $v_name => $v_value) {
variable_set($v_name, $v_value);
}
// our own install
//include("cnk.settings.inc");
print "Running cnk install\n";
_cnk_install();
}
/**
* Performs additional configuration for the CNK profile
*/
function _cnk_install() {
// more menu items
// $set = shortcut_set_load(st('Store administration'));
// $set->links[] = array('link_path' => 'node/add/product-display', 'link_title' => st('Add product display'));
// shortcut_set_save($set);
print "Running commerce kickstart install\n";
// from the commerce kickstart
_commerce_kickstart_install();
variable_set('site_default_country', 'AU');
_cnk_configure_roles();
_cnk_configure_currency();
// look to the commerce_australia module
// _cnk_configure_gst(10);
_cnk_configure_stock();
// _cnk_configure_fivestar("product_display");
//_cnk_configure_facebook();
// for share this
// _cnk_configure_share();
// for paypal
// _cnk_configure_payments();
// not working
// _cnk_dummy_content(10);
}
function _cnk_configure_stock($types=array("product")) {
if ( module_exists("commerce_stock") ) {
module_load_include("module", "commerce_stock");
foreach($types as $type) {
commerce_stock_create_instance('commerce_stock', 'number_integer', TRUE, 'commerce_product', $type, t('Stock'));
}
}
}
function _cnk_configure_payments() {
if ( module_exists("commerce_paypal_wps") ) {
db_insert('rules_config')
->fields(array(
'name' => 'commerce_payment_paypal_wps',
'label' => 'PayPal WPS',
'plugin' => 'reaction rule',
'active' => 1,
'status' => 3,
'module' => 'commerce_payment',
'data' => $data
// serialize(array(
// 'components' => array(),
// 'include_tax'=>'gst'
// ))
))
->execute();
}
}
function _cnk_configure_share() {
if ( module_exists("sharethis") ) {
$data = array(
'buttons' => 'stbc_hcount',
'node_type' => 'product_display',
'publisherID' => '',
'services' => '"Email:email","Tweet:twitter","Facebook:facebook","Fblike:fblike","Plusone:plusone"',
'viewMode' => '1', // 0 shows in teaser too
'widget' => 'st_multi',
);
foreach ( $data as $key=>$value ) {
db_insert('st_table')
->fields(array(
'st_option' => $key,
'st_value' => $value,
))
->execute();
}
}
}
function _cnk_configure_facebook() {
// need to link in app for anything to work
// print "_cnk_configure_facebook\n";
if ( module_exists("fb_app") ) {
$result = module_enable(array("fb", "fb_app", "fb_connect", "fb_user", "fb_registration"));
// include drupal_get_path('module', 'fb') . '/fb.admin.inc';
// module_load_include('inc', 'fb', 'fb.admin');
module_load_include('inc', 'fb_app');
module_load_include('inc', 'fb_app', 'fb_app.admin');
// print "Loaded fb_app\n";
$app_label = 'connect';
$form_state = array();
$form_state['values']['label'] = $app_label;
$form_state['values']['status'] = 1;
$form_state['values']['id'] = FB_KEY;
$form_state['values']['apikey'] = FB_KEY;
$form_state['values']['secret'] = FB_SECRET;
$form_state['values']['fb_app_data']['fb_app']['set_app_props'] = 1;
// this is the only one that doesn't get stored when calling the method directly
$form_state['values']['fb_app_data']['fb_connect']['primary'] = 1;
$form_state['values']['fb_app_data']['fb_user']['create_account'] = 2;
$form_state['values']['fb_app_data']['fb_user']['map_account'][2] = 2;
$form_state['values']['fb_app_data']['fb_user']['map_account'][3] = 3;
$form_state['values']['fb_app_data']['fb_permission']['prompt']['email'] = 'email';
$form_state['values']['fb_app_data']['fb_permission']['map']['contact_email'] = 'contact_email';
$form_state['values']['fb_app_data']['fb_permission']['map']['user_birthday'] = 'user_birthday';
$form_state['values']['fb_app_data']['fb_permission']['map']['user_mobile_phone'] = 'user_mobile_phone';
$form_state['values']['op'] = st('Save');
// print "Printing form\n";
// print_r($form_state);
$form_state['values']['op'] = t('Create new account');
// drupal_form_submit('fb_app_admin_form', $form_state);
// this runs but doesn't create an app
// $result = drupal_form_submit('fb_app_edit_form', $form_state);
// this runs and fails (not a valid callback - probably because the form fails .)
// $result = drupal_form_submit('fb_app_admin_form', $form_state);
// what about calling the method directly ?
$result = fb_app_admin_form_submit(null, $form_state);
variable_set('fb_connect_primary_label', $app_label);
// this results in fb_connect remaining unset-so do it again
// still doesn't work . must be a typ-oh
/*
$num_updated = db_update('fb_app') // Table name no longer needs {}
->fields(array(
'data' => serialize($form_state['values']['fb_app_data'])
))
->condition('fba_id', 1)
->execute();
*/
// print "Printing results\n";
// print_r($result);
/*
$data = Array (
'fb_app' => Array (
'set_app_props' => 1
),
'fb_connect' => Array (
'primary' => 1
),
'fb_user' => Array (
'create_account' => 2,
'map_account' => Array (
2 => 2,
3 => 3
),
'new_user_rid' => 0,
'connected_user_rid' => 0
)
);
db_insert('fb_app')
->fields(array(
'title' => 'connect',
'label' => 'connect',
'id' => FB_KEY,
'apikey' => FB_KEY,
'secret' => FB_SECRET,
'data' => $data
))
->execute();
*/
// need to turn on fb_user
// need permission for email for fb_user
}
// a different module that just handles auth
if ( module_exists("fbconnect") ) {
variable_set('fbconnect_appid', FB_KEY);
variable_set('fbconnect_skey', FB_SECRET);
variable_set('fbconnect_language_code', "en_AU");
}
}
/**
* Create a dummy product and product display
*/
function _cnk_dummy_content($num_products = 10) {
/*
// taken from commerce_devel_generate.drush.inc
module_load_include('inc', 'commerce_devel_generate', 'devel_generate');
$values = array(
'kill_products' => 0,
'num_products' => $num_products,
'product_types' => array('products'),
'title_length' => 2, // @todo: Make this configurable.
);
// doesn't do gst or stock
commerce_devel_generate_products(array('values' => $values));
*/
for ( $i = 0; $i < $num_products; $i++ ) {
db_insert('commerce_product')
->fields(array(
'sku' => 'test-' . $i,
'type' => 'product',
'title' => 'Test ' . $i,
'language' => 'und',
'status' => 1,
'uid' => $i
))
->execute();
db_insert('field_data_commerce_price')
->fields(array(
'entity_type' => 'commerce_product',
'bundle' => 'product',
'deleted' => 0,
'entity_id' => $i+1,
'revision_id' => 1,
'language' => 'und',
'delta' => 0,
'commerce_price_amount' => 1100 * ($i+1),
'commerce_price_currency_code' => 'AUD',
'commerce_price_data' => serialize(array(
'components' => array(),
'include_tax'=>'gst'
))
))
->execute();
if ( module_exists("commerce_stock") ) {
db_insert('field_data_commerce_stock')
->fields(array(
'entity_type' => 'commerce_product',
'bundle' => 'product',
'deleted' => 0,
'entity_id' => $i+1,
'revision_id' => 1,
'language' => 'und',
'delta' => 0,
'commerce_stock_value' => rand(0, 100)
))
->execute();
}
$node = new StdClass();
$node->type = 'product_display';
node_object_prepare($node);
// print_r($node);
$node->title = 'Test ' . $i;
$node->status = 1;
$node->promote = 1;
$node->uid = 1;
$node->body = "Body Body body";
$node->language = LANGUAGE_NONE;
# $node->language = "und";
module_load_include('inc', 'commerce_pdm', 'commerce_pdm');
if ( function_exists('_commerce_pdm_get_product_reference_fields') ) {
$field_names = _commerce_pdm_get_product_reference_fields($node);
$reference_field = $field_names[0];
// doesnt work, causes errors.
// Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 177 of /Users/rossetti/Documents/jobs/laudanum/cashmereandkaye/public_html/drupal-commerce/includes/entity.inc).
// $node->{$field_names[0]}['und'][0]['value'] = $i;
} else {
$reference_field = 'field_product';
print "Module commerce_pdm not loaded\n";
}
$node_lanugage = $node->language;
$product_id = $i+1;
$node->{$reference_field}[$node_lanugage][] = array('product_id' => $product_id);
## $node->field_data_commerce_product[0]['value'] = $i
# $key = 'data_commerce_product';
// $node->{'field_'.$key}[$node->language][0]['value'] = $value;
node_save($node);
/*
db_insert('node')
->fields(array(
'type' => 'product_display',
'title' => 'Test ' . $i,
'uid' => 1,
'language' => 'und',
'promote' => 1,
'status' => 1
))
->execute();
*/
}
}
/**
* add the storekeeper role
*/
function _cnk_configure_roles() {
// permissions authenticated users need to view their own orders
// View own orders of any type
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('view own commerce_order entities'));
// storekeeper role
$storeadmin_role = new stdClass();
$storeadmin_role->name = 'storekeeper';
$storeadmin_role->weight = 2;
user_role_save($storeadmin_role);
// user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Set this as the administrator role.
// variable_set('user_admin_role', $admin_role->rid);
// Assign user 1 the "storekeeper" role.
db_insert('users_roles')
->fields(array('uid' => 1, 'rid' => $storeadmin_role->rid))
->execute();
}
/*
* set the default and available currencies
*/
function _cnk_configure_currency() {
// default currency
variable_set('commerce_default_currency', 'AUD');
// enabled currencies
$currencies = array('AUD', 'CAD', 'EUR', 'GBP', 'HKD', 'JPY', 'NZD', 'SGD', 'USD');
variable_set('commerce_enabled_currencies', $currencies);
}
/*
* setup GST. pass in the rate (defaults to 10%)
*/
function _cnk_configure_gst($rate=10) {
// gst
db_insert('commerce_tax_rate')
->fields(array(
'name' => 'gst',
'title' => 'GST',
'display_title' => 'GST',
'rate' => $rate/100,
'type' => 'vat',
'description' => 'Australian Goods and Services tax (10%)',
// 'rules_component' => 1,
'module' => 'commerce_tax_ui'
))
->execute();
}
/**
* allow product types to use fivestar
*/
function _cnk_configure_fivestar($content_type) {
if ( module_exists("fivestar") ) {
/*
- fivestar_feedback_product_display i:1;
- fivestar_labels_enable_product_display i:1;
- fivestar_labels_product_display a:11:{i:0;s:13:"Cancel rating";i:1;s:4:"Poor";i:2;s:4:"Okay";i:3;s:4:"Good";i:4;s:5:"Great";i:5;s:7:"Awesome";i:6;s:20:"Give it @star/@count";i:7;s:20:"Give it @star/@count";i:8;s:20:"Give it @star/@count";i:9;s:20:"Give it @star/@count";i:10;s:20:"Give it @star/@count";}
- fivestar_position_product_display s:5:"below";
- fivestar_position_teaser_product_display s:6:"hidden";
- fivestar_product_display i:1;
- fivestar_stars_product_display s:1:"5";
- fivestar_style_product_display s:7:"average";
- fivestar_tags s:4:"vote";
- fivestar_text_product_display s:4:"dual";
- fivestar_title_product_display i:1;
- fivestar_unvote_product_display i:0;
- fivestar_widget s:52:"sites/all/modules/fivestar/widgets/hearts/hearts.css";
*/
$fivestar_path = drupal_get_path("module", "fivestar");
// which widget are we using?
variable_set("fivestar_widget", $fivestar_path . "/widgets/hearts/hearts.css");
variable_set("fivestar_tags", "vote");
// enable for our content type
variable_set("fivestar_" . $content_type, 1);
// number of stars
variable_set("fivestar_stars_" . $content_type, 5);
// position of stars
variable_set("fivestar_position_" . $content_type, "below");
variable_set("fivestar_position_teaser_" . $content_type, "below");
// display of stars
variable_set("fivestar_style_" . $content_type, "average");
variable_set("fivestar_text_" . $content_type, "dual");
variable_set("fivestar_title_" . $content_type, 1);
variable_set("fivestar_feedback_" . $content_type, 1);
variable_set("fivestar_unvote_" . $content_type, 0);
// labels
variable_set("fivestar_labels_enable_" . $content_type, 1);
variable_set("fivestar_labels_" . $content_type,
array(
"Cancel rating",
"Poor",
"Okay",
"Good",
"Great",
"Awesome"
)
);
}
}
/**
* Performs additional configuration for Drupal Commerce modules and components.
*/
function _commerce_kickstart_install() {
// Enable Commerce blocks.
$default_theme = variable_get('theme_default', KICKSTART_DEFAULT_THEME);
$admin_theme = KICKSTART_ADMIN_THEME;
$values = array(
array(
'module' => 'commerce_cart',
'delta' => 'cart',
'theme' => $default_theme,
'status' => 1,
'weight' => 0,
'region' => 'sidebar_first',
'pages' => "cart\ncheckout/*",
'cache' => -1,
),
);
$query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($values as $record) {
$query->values($record);
}
$query->execute();
// _commerce_kickstart_create_product();
// Give checkout access to anonymous and authenticated users.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access checkout'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access checkout'));
// Disable Views' Advanced Help module nag message until it's production ready.
variable_set('views_hide_help_message', TRUE);
// Add a shortcut set for store administration.
$set = new stdClass;
$set->title = st('Store administration');
$set->links = array(
array('link_path' => 'admin/commerce/products/add', 'link_title' => st('Add product')),
array('link_path' => 'node/add/product-display', 'link_title' => st('Add product display')),
array('link_path' => 'admin/commerce/products', 'link_title' => st('View products')),
array('link_path' => 'admin/commerce/orders', 'link_title' => st('View orders')),
array('link_path' => 'admin/commerce/config', 'link_title' => st('Configure store')),
);
shortcut_set_save($set);
// Apply the shortcut set to the first user.
shortcut_set_assign_user($set, (object) array('uid' => 1));
}
function _commerce_kickstart_create_product() {
// Insert a product display node type into the database.
$types = array(
array(
'type' => 'product_display',
'name' => st('Product display'),
'base' => 'node_content',
'description' => st('Use <em>product displays</em> to present Add to Cart form for products to your customers.'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
);
foreach ($types as $type) {
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
// Update "Product" comment and author information settings.
variable_set('comment_product_display', COMMENT_NODE_HIDDEN);
variable_set('node_submitted_product_display', FALSE);
// Create a default Catalog vocabulary for the Product display node type.
$description = st('Describes a hierarchy for the product catalog.');
$vocabulary = (object) array(
'name' => st('Catalog'),
'description' => $description,
'machine_name' => 'catalog',
'help' => '',
);
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$instance = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => st('Catalog category'),
'bundle' => 'product_display',
'description' => '',
'widget' => array(
'type' => 'options_select',
),
);
field_create_instance($instance);
// Add a default image field to the basic product type.
$instance = array(
'field_name' => 'field_image',
'entity_type' => 'commerce_product',
'label' => st('Image'),
'bundle' => 'product',
'description' => st('Upload an image for this product.'),
'required' => FALSE,
'settings' => array(
'file_directory' => 'field/image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '',
'max_resolution' => '',
'min_resolution' => '',
'alt_field' => TRUE,
'title_field' => '',
),
'widget' => array(
'type' => 'image_image',
'settings' => array(
'progress_indicator' => 'throbber',
'preview_image_style' => 'thumbnail',
),
'weight' => -1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'line_item' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'thumbnail', 'image_link' => ''),
'weight' => -1,
),
'node_full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'node_teaser' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'thumbnail', 'image_link' => 'content'),
'weight' => -1,
),
'node_rss' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => ''),
'weight' => -1,
),
),
);
field_create_instance($instance);
// Add a product reference field to the Product display node type.
$field = array(
'field_name' => 'field_product',
'type' => 'commerce_product_reference',
'cardinality' => 1,
'translatable' => FALSE,
);
field_create_field($field);
$instance = array(
'field_name' => 'field_product',
'entity_type' => 'node',
'label' => st('Product'),
'bundle' => 'product_display',
'description' => 'Choose a product to display for sale.',
'required' => TRUE,
'widget' => array(
'type' => 'options_select',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'full' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
),
);
field_create_instance($instance);
}