-
Notifications
You must be signed in to change notification settings - Fork 10
/
uc_store.module
1940 lines (1732 loc) · 54.1 KB
/
uc_store.module
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Contains global Ubercart functions and store administration functionality.
*
* The store module is a container of sorts for various helper functions used
* in different parts of the Ubercart core. It also provides screens and
* settings pages for use in store administration.
*/
/**
* Weight unit conversion constants, used by uc_weight_conversion().
*/
/**
* Converts kilograms to kilograms.
*/
define('KG_TO_KG', 1);
/**
* Converts kilograms to grams.
*/
define('KG_TO_G', 1000);
/**
* Converts kilograms to pounds.
*/
define('KG_TO_LB', 2.204622621849);
/**
* Converts kilograms to ounces.
*/
define('KG_TO_OZ', 35.27396194958);
/**
* Converts grams to grams.
*/
define('G_TO_G', 1);
/**
* Converts grams to kilograms.
*/
define('G_TO_KG', 0.001);
/**
* Converts grams to pounds.
*/
define('G_TO_LB', 0.002204622622);
/**
* Converts grams to ounces.
*/
define('G_TO_OZ', 0.03527396195);
/**
* Converts pounds to pounds.
*/
define('LB_TO_LB', 1);
/**
* Converts pounds to ounces.
*/
define('LB_TO_OZ', 16);
/**
* Converts pounds to kilograms.
*/
define('LB_TO_KG', 0.45359237);
/**
* Converts pounds to grams.
*/
define('LB_TO_G', 453.59237);
/**
* Converts ounces to ounces.
*/
define('OZ_TO_OZ', 1);
/**
* Converts ounces to pounds.
*/
define('OZ_TO_LB', 0.0625);
/**
* Converts ounces to kilograms.
*/
define('OZ_TO_KG', 0.028349523);
/**
* Converts ounces to grams.
*/
define('OZ_TO_G', 28.349523125);
/**
* Length unit conversion constants, used by uc_length_conversion().
*/
/**
* Converts inches to inches.
*/
define('IN_TO_IN', 1);
/**
* Converts inches to feet.
*/
define('IN_TO_FT', 0.083333333333);
/**
* Converts inches to centimeters.
*/
define('IN_TO_CM', 2.54);
/**
* Converts inches to millimeters.
*/
define('IN_TO_MM', 25.4);
/**
* Converts feet to feet.
*/
define('FT_TO_FT', 1);
/**
* Converts feet to inches.
*/
define('FT_TO_IN', 12);
/**
* Converts feet to centimeters.
*/
define('FT_TO_CM', 30.48);
/**
* Converts feet to millimeters.
*/
define('FT_TO_MM', 304.8);
/**
* Converts centimeters to centimeters.
*/
define('CM_TO_CM', 1);
/**
* Converts centimeters to inches.
*/
define('CM_TO_IN', 0.393700787402);
/**
* Converts centimeters to feet.
*/
define('CM_TO_FT', 0.03280839895);
/**
* Converts centimeters to millimeters.
*/
define('CM_TO_MM', 10);
/**
* Converts millimeters to millimeters.
*/
define('MM_TO_MM', 1);
/**
* Converts millimeters to inches.
*/
define('MM_TO_IN', 0.03937007874);
/**
* Converts millimeters to feet.
*/
define('MM_TO_FT', 0.003280839895);
/**
* Converts millimeters to centimeters.
*/
define('MM_TO_CM', 0.1);
/**
* Implements hook_menu().
*/
function uc_store_menu() {
$items = array();
$items['admin/store'] = array(
'title' => 'Store',
'description' => 'Administer orders, products, customers, store settings, etc.',
'page callback' => 'uc_store_admin',
'access callback' => 'uc_store_admin_access',
'weight' => -12,
'icon' => 'shopping-cart-simple-fill',
'file' => 'uc_store.admin.inc',
);
$items['admin/store/reports'] = array(
'title' => 'Reports',
'description' => 'Browse various store reports.',
'page callback' => 'uc_store_reports',
'access arguments' => array('view reports'),
'weight' => 2,
'file' => 'uc_store.admin.inc',
'position' => 'right',
);
$items['admin/store/settings'] = array(
'title' => 'Configuration',
'description' => 'Adjust configuration settings for Ubercart.',
'page callback' => 'uc_store_configuration_page',
'access arguments' => array('administer store'),
'weight' => -10,
'file' => 'uc_store.admin.inc',
'position' => 'right',
);
$items['admin/store/settings/countries'] = array(
'title' => 'Countries and addresses',
'description' => 'Manage available countries and configure address formats.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('uc_country_import_form'),
'access arguments' => array('administer store'),
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/countries/import'] = array(
'title' => 'Countries',
'description' => 'Import and manage countries.',
'access arguments' => array('administer store'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/countries/fields'] = array(
'title' => 'Address fields',
'description' => 'Edit the address field settings.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('uc_store_address_fields_form'),
'access arguments' => array('administer store'),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'uc_store.admin.inc',
);
$items['admin/store/settings/countries/formats'] = array(
'title' => 'Address formats',
'description' => 'Edit country specific address format settings.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('uc_country_formats_form'),
'access arguments' => array('administer store'),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/store'] = array(
'title' => 'Store',
'description' => 'Configure basic store settings.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('uc_store_settings_form'),
'access arguments' => array('administer store'),
'file' => 'uc_store.admin.inc',
'weight' => -1,
);
$items['admin/store/settings/countries/%/disable'] = array(
'title' => 'Disable a country',
'description' => 'Disable a country from use.',
'page callback' => '_uc_country_perform_country_action',
'page arguments' => array('uc_country_disable', 4),
'access arguments' => array('administer store'),
'type' => MENU_CALLBACK,
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/countries/%/enable'] = array(
'title' => 'Enable a country',
'description' => 'Enable a disabled country.',
'page callback' => '_uc_country_perform_country_action',
'page arguments' => array('uc_country_enable', 4),
'access arguments' => array('administer store'),
'type' => MENU_CALLBACK,
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/countries/%/remove'] = array(
'title' => 'Remove a country',
'description' => 'Remove an installed country.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('uc_country_remove_form', 4),
'access arguments' => array('administer store'),
'file' => 'uc_store.countries.inc',
);
$items['admin/store/settings/countries/%/update/%'] = array(
'title' => 'Update a country',
'description' => 'Update an installed country.',
'page callback' => '_uc_country_perform_country_action',
'page arguments' => array('uc_country_update', 4, 6),
'access arguments' => array('administer store'),
'type' => MENU_CALLBACK,
'file' => 'uc_store.countries.inc',
);
return $items;
}
/**
* Access callback for top-level store administration menu item.
*/
function uc_store_admin_access() {
return user_access('administer store')
|| user_access('view all orders')
|| user_access('view customers')
|| user_access('administer products')
|| user_access('view reports');
}
/**
* Implements hook_init().
*/
function uc_store_init() {
module_load_include('inc', 'uc_store', 'includes/tapir');
$parts = explode('.', BACKDROP_VERSION);
if ($parts[1] < 28) {
// For Backdrop versions below 1.28.0, use a CSS icon for the Store menu in
// the admin bar. 1.28.0 and higher will use a core icon.
global $base_url;
$path = $base_url . '/' . backdrop_get_path('module', 'uc_store');
backdrop_add_css('
#admin-bar #admin-bar-menu > li > .dropdown > li > a.admin-store {
background: transparent url(' . $path . '/images/cart--white--64.png) 5% center no-repeat;
background-size: 16px;
}', 'inline');
}
}
/**
* Implements hook_layout_access_info().
*/
function uc_store_layout_access_info() {
$info['uc_store_path'] = array(
'title' => t('Ubercart page'),
'description' => t('Control access by whether the current page is an Ubercart page.'),
'class' => 'UcLayoutAccess',
);
return $info;
}
/**
* Implements hook_element_info().
*/
function uc_store_element_info() {
$types = array();
$types['tapir_table'] = array(
'#columns' => array(),
'#rows' => array(),
'#tree' => TRUE,
'#value' => NULL,
'#pre_render' => array('tapir_gather_rows'),
'#theme' => 'tapir_table',
'#process' => array('ajax_process_form'),
);
$types['uc_address'] = array(
'#input' => TRUE,
'#required' => TRUE,
'#process' => array('uc_store_process_address_field'),
'#attributes' => array('class' => array('uc-store-address-field')),
'#theme_wrappers' => array('container'),
'#key_prefix' => '',
'#hidden' => FALSE,
);
$sign_flag = config_get('uc_store.settings', 'uc_sign_after_amount');
$currency_sign = config_get('uc_store.settings', 'uc_currency_sign');
$types['uc_price'] = array(
'#input' => TRUE,
'#size' => 15,
'#maxlength' => 15,
'#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'),
'#element_validate' => array('uc_store_validate_number'),
'#theme' => 'textfield',
'#theme_wrappers' => array('form_element'),
'#field_prefix' => $sign_flag ? '' : $currency_sign,
'#field_suffix' => $sign_flag ? $currency_sign : '',
'#allow_negative' => FALSE,
'#empty_zero' => TRUE,
);
$types['uc_quantity'] = array(
'#input' => TRUE,
'#size' => 5,
'#maxlength' => 6,
'#required' => TRUE,
'#autocomplete_path' => FALSE,
'#process' => array('ajax_process_form'),
'#element_validate' => array('uc_store_validate_uc_quantity'),
'#theme' => 'textfield',
'#theme_wrappers' => array('form_element'),
'#allow_zero' => FALSE,
);
return $types;
}
/**
* Element process hook for address fields.
*/
function uc_store_process_address_field($element, $form_state) {
$element['#tree'] = TRUE;
$prefix = $element['#key_prefix'] ? ($element['#key_prefix'] . '_') : '';
$weight = uc_store_address_field_weights();
if (isset($form_state['uc_address'])) {
// Use submitted Ajax values.
$value = $form_state['uc_address'];
}
elseif (is_array($element['#value']) || is_object($element['#value'])) {
// Use provided default value.
$value = (array) $element['#value'];
}
else {
$value = array();
}
$countries = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE version > :version", array(':version' => 0))->fetchAllKeyed();
foreach ($countries as $country_id => $country_name) {
$countries[$country_id] = t($country_name);
}
natcasesort($countries);
// Force the selected country to a valid one, so the zone dropdown matches.
if (isset($value[$prefix . 'country']) && !isset($countries[$value[$prefix . 'country']])) {
$country_keys = array_keys($countries);
$value[$prefix . 'country'] = $country_keys[0];
}
// Iterating on the UcAddress object excludes non-public properties, which
// is exactly what we want to do.
$address = new UcAddress();
foreach ($address as $base_field => $field_value) {
$field = $prefix . $base_field;
if (!isset($value[$field])) {
continue;
}
switch ($base_field) {
case 'country':
$subelement = array(
'#type' => 'select',
'#options' => $countries,
'#ajax' => array(
'callback' => 'uc_store_update_address_field_zones',
'wrapper' => 'uc-store-address-' . str_replace('_', '-', $prefix) . 'zone-wrapper',
'progress' => array(
'type' => 'throbber',
),
),
'#element_validate' => array('uc_store_validate_address_field_country'),
'#key_prefix' => $element['#key_prefix'],
);
break;
case 'zone':
$subelement = array(
'#prefix' => '<div id="uc-store-address-' . str_replace('_', '-', $prefix) . 'zone-wrapper">',
'#suffix' => '</div>',
);
$zones = db_query("SELECT zone_id, zone_name FROM {uc_zones} WHERE zone_country_id = :country", array(':country' => $value[$prefix . 'country']))->fetchAllKeyed();
if (!empty($zones)) {
natcasesort($zones);
$subelement += array(
'#type' => 'select',
'#options' => $zones,
'#empty_value' => 0,
);
}
else {
$subelement += array(
'#type' => 'hidden',
'#value' => 0,
'#required' => FALSE,
);
}
break;
case 'postal_code':
$subelement = array(
'#type' => 'textfield',
'#size' => 10,
'#maxlength' => 10,
);
break;
case 'phone':
$subelement = array(
'#type' => 'textfield',
'#size' => 16,
'#maxlength' => 32,
);
break;
default:
$subelement = array(
'#type' => 'textfield',
'#size' => 32,
);
}
// Copy JavaScript states from the parent element.
if (isset($element['#states'])) {
$subelement['#states'] = $element['#states'];
}
// Set common values for all address fields.
$label = uc_get_field_name($base_field);
$element[$field] = $subelement + array(
'#title' => $label ? $label : ' ',
'#default_value' => $value[$field],
'#parents' => array_merge(array_slice($element['#parents'], 0, -1), array($field)),
'#pre_render' => array('uc_store_pre_render_address_field'),
'#access' => $element['#hidden'] ? FALSE : uc_address_field_enabled($base_field),
'#required' => $element['#required'] ? uc_address_field_required($base_field) : FALSE,
'#weight' => (isset($weight[$base_field])) ? $weight[$base_field] : 0,
);
}
return $element;
}
/**
* Element validation callback for country field.
*
* Store the current address for use when rebuilding the form.
*/
function uc_store_validate_address_field_country($element, &$form_state) {
$address = backdrop_array_get_nested_value($form_state['values'], array_slice($element['#parents'], 0, -1));
$form_state['uc_address'] = isset($form_state['uc_address']) ? array_merge($form_state['uc_address'], $address) : $address;
}
/**
* Ajax callback: updates the zone select box when the country is changed.
*/
function uc_store_update_address_field_zones($form, &$form_state) {
$element = &$form;
foreach (array_slice($form_state['triggering_element']['#array_parents'], 0, -1) as $field) {
$element = &$element[$field];
}
$prefix = empty($element['#key_prefix']) ? '' : ($element['#key_prefix'] . '_');
return $element[$prefix . 'zone'];
}
/**
* Prerenders address field elements to move the required marker when needed.
*/
function uc_store_pre_render_address_field($element) {
if (!empty($element['#required'])) {
$element['#title'] = theme('form_required_marker', $element) . ' ' . $element['#title'];
unset($element['#required']);
}
return $element;
}
/**
* Helper function to determine the value for a uc_price form element.
*/
function form_type_uc_price_value($element, $input = FALSE) {
if ($input === FALSE && !empty($element['#default_value'])) {
return uc_store_format_price_field_value($element['#default_value']);
}
elseif (empty($input) && empty($element['#required']) && !empty($element['#empty_zero'])) {
// Empty non-required prices should be treated as zero.
return 0;
}
}
/**
* Generic form element validation handler for numbers.
*/
function uc_store_validate_number(&$element, &$form_state) {
$value = $element['#value'];
if ($value != '') {
if (!is_numeric($value)) {
form_error($element, t('%name must be a number.', array('%name' => $element['#title'])));
}
elseif (empty($element['#allow_negative']) && $value < 0) {
form_error($element, t('%name must not be negative.', array('%name' => $element['#title'])));
}
}
}
/**
* Form element validation handler for #type 'uc_quantity'.
*/
function uc_store_validate_uc_quantity(&$element, &$form_state) {
if (!preg_match('/^\d+$/', $element['#value'])) {
form_error($element, t('The quantity must be an integer.'));
}
elseif (empty($element['#allow_zero']) && !$element['#value']) {
form_error($element, t('The quantity cannot be zero.'));
}
}
/**
* Implements hook_theme().
*/
function uc_store_theme() {
return array(
'uc_store_footer' => array(
'variables' => array('message' => ''),
'file' => 'uc_store.theme.inc',
),
'uc_store_address_fields_form' => array(
'render element' => 'form',
'file' => 'uc_store.admin.inc',
),
'uc_pane_sort_table' => array(
'render element' => 'form',
'file' => 'uc_store.theme.inc',
),
'tapir_table' => array(
'render element' => 'element',
),
'uc_price' => array(
'variables' => array('price' => 0, 'suffixes' => array()),
'file' => 'uc_store.theme.inc',
),
'uc_qty_label' => array(
'variables' => array(),
'file' => 'uc_store.theme.inc',
),
'uc_qty' => array(
'variables' => array('qty' => 1),
'file' => 'uc_store.theme.inc',
),
'uc_uid' => array(
'variables' => array('uid' => 0),
'file' => 'uc_store.theme.inc',
),
);
}
/**
* Implements hook_permission().
*/
function uc_store_permission() {
return array(
'administer store' => array(
'title' => t('Administer store'),
'restrict access' => TRUE,
),
'view reports' => array(
'title' => t('View reports'),
),
);
}
/**
* Implements hook_date_formats().
*/
function uc_store_date_formats() {
return array(
array(
'type' => 'uc_store',
'format' => 'Y-m-d',
'locales' => array(),
),
array(
'type' => 'uc_store',
'format' => 'm/d/Y',
'locales' => array('en-us'),
),
array(
'type' => 'uc_store',
'format' => 'd/m/Y',
'locales' => array('en-gb', 'en-hk', 'en-ie', 'el-gr', 'es-es', 'fr-be', 'fr-fr', 'fr-lu', 'it-it', 'nl-be', 'pt-pt'),
),
array(
'type' => 'uc_store',
'format' => 'Y/m/d',
'locales' => array('en-ca', 'fr-ca', 'no-no', 'sv-se'),
),
array(
'type' => 'uc_store',
'format' => 'd.m.Y',
'locales' => array('de-ch', 'de-de', 'de-lu', 'fi-fi', 'fr-ch', 'is-is', 'pl-pl', 'ro-ro', 'ru-ru'),
),
);
}
/**
* Implements hook_date_format_types().
*/
function uc_store_date_format_types() {
return array('uc_store' => t('Ubercart'));
}
/**
* Implements hook_block_info().
*/
function uc_store_block_info() {
$blocks = array();
$blocks['uc_store_footer'] = array(
'info' => t('Ubercart store footer'),
'description' => t('Displays a footer for Ubercart store pages.'),
'class' => 'UcBlockFooter',
);
return $blocks;
}
/**
* Implements hook_reviews().
*
* Provides code reviews for coder_review.module.
*/
function uc_store_reviews() {
$coder_reviews = array();
$path = backdrop_get_path('module', 'uc_store') . '/includes';
$files = backdrop_system_listing('/coder_review_.*\.inc$/', $path, 'filepath', 0);
foreach ($files as $file) {
require_once BACKDROP_ROOT . '/' . $file->uri;
$function = $file->name . '_reviews';
if (function_exists($function)) {
if ($review = call_user_func($function)) {
$coder_reviews = array_merge($coder_reviews, $review);
}
}
}
return $coder_reviews;
}
/**
* Returns the default store footer options.
*/
function _uc_store_footer_options() {
$url = array('!url' => 'https://backdropcms.org/project/ubercart');
return array(
1 => t('Powered by <a href="!url">Ubercart</a>', $url),
2 => t('Backdrop e-commerce provided by <a href="!url">Ubercart</a>.', $url),
3 => t('Supported by <a href="!url">Ubercart</a>, an open source e-commerce suite.', $url),
4 => t('Powered by <a href="!url">Ubercart</a>, the free shopping cart software.', $url),
);
}
/**
* Helper function for hook_entity_property_info() and hook_rules_data_info().
*
* Should be used by implementations of those hooks that wish to wrap address
* selectors.
*/
function uc_address_property_info() {
return array(
'first_name' => array(
'type' => 'text',
'label' => t('First name'),
'description' => t('First name of the addressee.'),
),
'last_name' => array(
'type' => 'text',
'label' => t('Last name'),
'description' => t('Last name of the addressee.'),
),
'company' => array(
'type' => 'text',
'label' => t('Company'),
'description' => t('Name of the company at the address.'),
),
'street1' => array(
'type' => 'text',
'label' => t('Street line 1'),
'description' => t('First line of the street address.'),
),
'street2' => array(
'type' => 'text',
'label' => t('Street line 2'),
'description' => t('Second line of the street address.'),
),
'city' => array(
'type' => 'text',
'label' => t('City'),
'description' => t('Address city.'),
),
'zone' => array(
'type' => 'integer',
'label' => t('Zone'),
'description' => t('Address state/province/zone.'),
'options list' => 'uc_zone_option_list',
),
'postal_code' => array(
'type' => 'text',
'label' => t('Postal code'),
'description' => t('Address post code.'),
),
'country' => array(
'type' => 'integer',
'label' => t('Country'),
'description' => t('Address country.'),
'options list' => 'uc_country_option_list',
),
'phone' => array(
'type' => 'text',
'label' => t('Phone'),
'description' => t('Contact phone number.'),
),
'email' => array(
'type' => 'text',
'label' => t('Email'),
'description' => t('Contact email address.'),
),
);
}
/**
* Returns an IMG tag for a store icon. Deprecated; use theme('image') instead.
*
* @param $path
* The Backdrop path of the menu item. Atlernately may specify a filename by
* passing this string as file:filename.png.
* @param $small
* Pass TRUE to get a link to the small version of the icon. If specifying a
* filename, you should let this be FALSE.
*
* @return
* HTML output for the image.
*/
function uc_store_get_icon($path, $small = FALSE, $class = 'uc-store-icon', $alt = NULL) {
$file = FALSE;
switch ($path) {
case 'admin/store':
$file = 'store_monitor';
break;
case 'admin/store/orders':
$file = 'menu_orders';
break;
case 'admin/store/customers':
$file = 'menu_customers';
break;
case 'admin/store/products':
$file = 'menu_products';
break;
case 'admin/store/reports':
$file = 'menu_reports';
break;
case 'admin/store/settings':
$file = 'menu_store_settings';
break;
case 'admin/store/help':
$file = 'menu_help';
break;
}
if (substr($path, 0, 5) == 'file:') {
$file = substr($path, 5);
}
if (!$file) {
// See if it's hooked in anywhere else...
return '';
}
if ($small) {
$file .= '_small';
}
return theme('image', array(
'path' => backdrop_get_path('module', 'uc_store') . '/images/' . $file . '.gif',
'alt' => $alt,
'attributes' => array('class' => array($class)),
));
}
/**
* Formats an amount for display with the store's currency settings.
*
* @param $value
* The numeric value of the currency amount.
* @param $sign
* The currency symbol. If FALSE is given, no symbol is used. The default,
* NULL, causes the variable 'uc_currency_sign' to be used, which defaults to
* '$'.
* @param $thou
* The thousands separator character. If FALSE is given, no separator is used.
* The default, NULL, causes the variable 'uc_currency_sign' to be used, which
* defaults to ','.
* @param $dec
* The decimal separator character. If FALSE is given, confusion will abound,
* because it will look 100 times bigger. The default, NULL, causes the
* variable 'uc_currency_dec' to be used, which defaults to '.'.
*
* @return
* String containing price formatted with currency symbol and separators.
*/
function uc_currency_format($value, $sign = NULL, $thou = NULL, $dec = NULL) {
if ($value === NULL) {
return NULL;
}
$output = '';
$sign_after = config_get('uc_store.settings', 'uc_sign_after_amount');
$prec = config_get('uc_store.settings', 'uc_currency_prec');
if (is_null($sign)) {
$sign = config_get('uc_store.settings', 'uc_currency_sign');
}
if (is_null($thou)) {
$thou = config_get('uc_store.settings', 'uc_currency_thou');
}
if (is_null($dec)) {
$dec = config_get('uc_store.settings', 'uc_currency_dec');
}
// If the value is significantly less than the minimum precision, zero it.
if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
$value = 0;
}
// Force the price to a positive value and add a negative sign if necessary.
if ($value < 0) {
$value = abs($value);
$output .= '-';
}
// Add the currency sign first if specified.
if ($sign && !$sign_after) {
$output .= $sign;
}
// Format the number, like 1234.567 => 1,234.57
$output .= number_format($value, $prec, $dec, $thou);
// Add the currency sign last if specified.
if ($sign && $sign_after) {
$output .= $sign;
}
return $output;
}
/**
* Formats a weight value for display.
*
* @param $value
* Numerical weight value.
* @param $unit
* Weight unit. One of 'lb', 'oz', 'kg', or 'g', or NULL to use store
* default weight units.
*
* @return
* String containing formattted weight, including weight units.
*/
function uc_weight_format($value, $unit = NULL) {
$vars = array('!value' => $value);
if (is_null($unit)) {
$unit = config_get('uc_store.settings', 'uc_weight_unit');
}
$defaults = array(
'lb' => '!value lb',
'oz' => '!value oz',
'kg' => '!value kg',
'g' => '!value g',
);
$pattern = config_get('uc_store.settings', 'uc_weight_format_' . $unit);
if (strpos($pattern, '!value') === FALSE) {
$pattern = $defaults[$unit];
}
$format = strtr($pattern, $vars);
return $format;
}
/**
* Gets the conversion ratio from one unit of weight to another.
*/
function uc_weight_conversion($from_units, $to_units = NULL) {
if (is_null($to_units)) {
$to_units = config_get('uc_store.settings', 'uc_weight_unit');
}
$constant = strtoupper($from_units) . '_TO_' . strtoupper($to_units);
if (defined($constant) && ($conversion = constant($constant)) > 0) {
return $conversion;
}
else {
return 1;
}
}
/**
* Formats a length value for display.
*
* @param $value
* Numerical length value.
* @param $unit
* Length unit. One of 'ft', 'in', 'cm', or 'mm', or NULL to use store
* default length units.
*
* @return
* String containing formattted length, including length units.
*/
function uc_length_format($value, $unit = NULL) {
$vars = array('!value' => $value);
if (is_null($unit)) {
$unit = config_get('uc_store.settings', 'uc_length_unit');
}
$defaults = array(
'in' => '!valuein.',
'ft' => '!valueft.',
'cm' => '!valuecm',
'mm' => '!valuemm',
);
$pattern = config_get('uc_store.settings', 'uc_length_format_' . $unit);
if (strpos($pattern, '!value') === FALSE) {
$pattern = $defaults[$unit];