This repository has been archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfedexcarrier.php
1814 lines (1607 loc) · 91.2 KB
/
fedexcarrier.php
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
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
class FedexCarrier extends CarrierModule
{
public $id_carrier;
private $_html = '';
private $_postErrors = array();
private $_webserviceTestResult = '';
private $_webserviceError = '';
private $_fieldsList = array();
private $_pickupTypeList = array();
private $_packagingTypeList = array();
private $_calculModeList = array();
private $_serviceTypeList = array();
private $_dimensionUnit = '';
private $_weightUnit = '';
private $_dimensionUnitList = array('CM' => 'CM', 'IN' => 'IN', 'CMS' => 'CM', 'INC' => 'IN');
private $_weightUnitList = array('KG' => 'KGS', 'KGS' => 'KGS', 'LBS' => 'LBS', 'LB' => 'LBS');
private $_moduleName = 'fedexcarrier';
/*
** Construct Method
**
*/
public function __construct()
{
$this->name = 'fedexcarrier';
$this->tab = 'shipping_logistics';
$this->version = '1.6';
$this->author = 'PrestaShop';
$this->limited_countries = array('us');
$this->module_key = 'e690479f7f292afefbef7e55f884527d';
parent::__construct ();
$this->displayName = $this->l('Fedex Carrier');
$this->description = $this->l('Offer your customers, different delivery methods with Fedex');
/** Backward compatibility 1.4 / 1.5 */
require(dirname(__FILE__).'/backward_compatibility/backward.php');
if (self::isInstalled($this->name))
{
// Loading Var
$warning = array();
$this->loadingVar();
// Check Class Soap availibility
if (!extension_loaded('soap'))
$warning[] = "'".$this->l('Class Soap')."', ";
// Check Configuration Values
foreach ($this->_fieldsList as $keyConfiguration => $name)
if (!Configuration::get($keyConfiguration) && !empty($name))
$warning[] = '\''.$name.'\' ';
// Check calcul mode
if (!Configuration::get('FEDEX_CARRIER_CALCUL_MODE'))
Configuration::updateValue('FEDEX_CARRIER_CALCUL_MODE', 'onepackage');
// Checking Unit
$this->_dimensionUnit = isset($this->_dimensionUnitList[strtoupper(Configuration::get('PS_DIMENSION_UNIT'))]) ? $this->_dimensionUnitList[strtoupper(Configuration::get('PS_DIMENSION_UNIT'))] : false;
$this->_weightUnit = isset($this->_weightUnitList[strtoupper(Configuration::get('PS_WEIGHT_UNIT'))]) ? $this->_weightUnitList[strtoupper(Configuration::get('PS_WEIGHT_UNIT'))] : false;
if (!$this->_weightUnit || !$this->_weightUnitList[$this->_weightUnit])
$warning[] = $this->l('\'Weight Unit (LB or KG).\'').' ';
if (!$this->_dimensionUnit || !$this->_dimensionUnitList[$this->_dimensionUnit])
$warning[] = $this->l('\'Dimension Unit (CM or IN).\'').' ';
// Generate Warnings
if (count($warning))
$this->warning .= implode(' , ',$warning).$this->l('must be configured to use this module correctly').' ';
}
}
public function loadingVar()
{
// Loading Fields List
$this->_fieldsList = array(
'FEDEX_CARRIER_ACCOUNT' => $this->l('Fedex account'),
'FEDEX_CARRIER_METER' => $this->l('Fedex meter'),
'FEDEX_CARRIER_PASSWORD' => $this->l('Fedex password'),
'FEDEX_CARRIER_API_KEY' => $this->l('Fedex Authentication Key'),
'FEDEX_CARRIER_PICKUP_TYPE' => $this->l('Fedex default pickup type'),
'FEDEX_CARRIER_PACKAGING_TYPE' => $this->l('Fedex default packaging type'),
'FEDEX_CARRIER_PACKAGING_WEIGHT' => $this->l('Packaging weight'),
'FEDEX_CARRIER_HANDLING_FEE' => $this->l('Handling fee'),
'FEDEX_CARRIER_ADDRESS1' => '',
'FEDEX_CARRIER_ADDRESS2' => '',
'FEDEX_CARRIER_POSTAL_CODE' => '',
'FEDEX_CARRIER_CITY' => '',
'FEDEX_CARRIER_STATE' => '',
'FEDEX_CARRIER_COUNTRY' => '',
'FEDEX_CARRIER_CALCUL_MODE' => '',
);
// Loading pickup type list
$this->_pickupTypeList = array(
'BUSINESS_SERVICE_CENTER' => $this->l('Business service center'),
'DROP_BOX' => $this->l('Drop box'),
'REGULAR_PICKUP' => $this->l('Regular pickup'),
'REQUEST_COURIER' => $this->l('Request courier'),
'STATION' => $this->l('Station')
);
// Loading packaging type list
$this->_packagingTypeList = array(
'FEDEX_10KG_BOX' => $this->l('Fedex 10Kg Box'),
'FEDEX_25KG_BOX' => $this->l('Fedex 25Kg Box'),
'FEDEX_BOX' => $this->l('Fedex Box'),
'FEDEX_ENVELOPE' => $this->l('Fedex Envelope'),
'FEDEX_PAK' => $this->l('Fedex Pak'),
'FEDEX_TUBE' => $this->l('Fedex Tube'),
'YOUR_PACKAGING' => $this->l('Your Packaging'),
);
// Loading service type list
$this->_serviceTypeList = array(
'EUROPE_FIRST_INTERNATIONAL_PRIORITY' => $this->l('Europe first international priority'),
'FEDEX_1_DAY_FREIGHT' => $this->l('Fedex 1 day freight'),
'FEDEX_2_DAY' => $this->l('Fedex 2 day'),
'FEDEX_2_DAY_FREIGHT' => $this->l('Fedex 2 day freight'),
'FEDEX_3_DAY_FREIGHT' => $this->l('Fedex 3 day freight'),
'FEDEX_EXPRESS_SAVER' => $this->l('Fedex express saver'),
'FEDEX_FREIGHT' => $this->l('Fedex freight'),
'FEDEX_GROUND' => $this->l('Fedex ground'),
'FEDEX_NATIONAL_FREIGHT' => $this->l('Fedex national freight'),
'FIRST_OVERNIGHT' => $this->l('First overnight'),
'GROUND_HOME_DELIVERY' => $this->l('Ground home delivery'),
'INTERNATIONAL_ECONOMY' => $this->l('International economy'),
'INTERNATIONAL_ECONOMY_FREIGHT' => $this->l('International economy freight'),
'INTERNATIONAL_FIRST' => $this->l('International first'),
'INTERNATIONAL_GROUND' => $this->l('International ground'),
'INTERNATIONAL_PRIORITY' => $this->l('International priority'),
'INTERNATIONAL_PRIORITY_FREIGHT' => $this->l('International priority freight'),
'PRIORITY_OVERNIGHT' => $this->l('Priority overnight'),
'SMART_POST' => $this->l('Smart post'),
'STANDARD_OVERNIGHT' => $this->l('Standard overnight')
);
// Loading calcul mode list
$this->_calculModeList = array(
'onepackage' => $this->l('All items in one package'),
'split' => $this->l('Split one item per package')
);
}
/*
** Install / Uninstall Methods
**
*/
public function install()
{
// Install SQL
include(dirname(__FILE__).'/sql-install.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
// Install Carriers
$this->installCarriers();
// Install Module
if (!parent::install() OR !$this->registerHook('updateCarrier'))
return false;
return true;
}
public function uninstall()
{
// Uninstall Carriers
Db::getInstance()->autoExecute(_DB_PREFIX_.'carrier', array('deleted' => 1), 'UPDATE', '`external_module_name` = \'fedexcarrier\' OR `id_carrier` IN (SELECT DISTINCT(`id_carrier`) FROM `'._DB_PREFIX_.'fedex_rate_service_code`)');
// Uninstall Config
foreach ($this->_fieldsList as $keyConfiguration => $name)
if (!Configuration::deleteByName($keyConfiguration))
return false;
// Uninstall SQL
include(dirname(__FILE__).'/sql-uninstall.php');
foreach ($sql as $s)
if (!Db::getInstance()->execute($s))
return false;
// Uninstall Module
if (!parent::uninstall() OR !$this->unregisterHook('updateCarrier'))
return false;
return true;
}
public function installCarriers()
{
// Unactive all FEDEX Carriers
Db::getInstance()->autoExecute(_DB_PREFIX_.'fedex_rate_service_code', array('active' => 0), 'UPDATE');
// Get all services availables
$rateServiceList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_service_code`');
foreach ($rateServiceList as $rateService)
if (!$rateService['id_carrier'])
{
$config = array(
'name' => $rateService['service'],
'id_tax_rules_group' => 0,
'active' => true,
'deleted' => 0,
'shipping_handling' => false,
'range_behavior' => 0,
'delay' => array('fr' => $rateService['service'], 'en' => $rateService['service'], Language::getIsoById(Configuration::get('PS_LANG_DEFAULT')) => $rateService['service']),
'id_zone' => 1,
'is_module' => true,
'shipping_external' => true,
'external_module_name' => $this->_moduleName,
'need_range' => true
);
$id_carrier = $this->installExternalCarrier($config);
Db::getInstance()->autoExecute(_DB_PREFIX_.'fedex_rate_service_code', array('id_carrier' => (int)($id_carrier), 'id_carrier_history' => (int)($id_carrier)), 'UPDATE', '`id_fedex_rate_service_code` = '.(int)($rateService['id_fedex_rate_service_code']));
}
}
public static function installExternalCarrier($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->id_zone = $config['id_zone'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Language::getLanguages(true);
foreach ($languages as $language)
{
if ($language['iso_code'] == 'fr')
$carrier->delay[(int)$language['id_lang']] = $config['delay'][$language['iso_code']];
if ($language['iso_code'] == 'en')
$carrier->delay[(int)$language['id_lang']] = $config['delay'][$language['iso_code']];
if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT')))
$carrier->delay[(int)$language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($carrier->add())
{
$groups = Group::getGroups(true);
foreach ($groups as $group)
Db::getInstance()->autoExecute(_DB_PREFIX_.'carrier_group', array('id_carrier' => (int)($carrier->id), 'id_group' => (int)($group['id_group'])), 'INSERT');
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
$zones = Zone::getZones(true);
foreach ($zones as $zone)
{
Db::getInstance()->autoExecute(_DB_PREFIX_.'carrier_zone', array('id_carrier' => (int)($carrier->id), 'id_zone' => (int)($zone['id_zone'])), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.'delivery', array('id_carrier' => (int)($carrier->id), 'id_range_price' => (int)($rangePrice->id), 'id_range_weight' => NULL, 'id_zone' => (int)($zone['id_zone']), 'price' => '0'), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_.'delivery', array('id_carrier' => (int)($carrier->id), 'id_range_price' => NULL, 'id_range_weight' => (int)($rangeWeight->id), 'id_zone' => (int)($zone['id_zone']), 'price' => '0'), 'INSERT');
}
// Copy Logo
if (!copy(dirname(__FILE__).'/carrier.jpg', _PS_SHIP_IMG_DIR_.'/'.(int)$carrier->id.'.jpg'))
return false;
// Return ID Carrier
return (int)($carrier->id);
}
return false;
}
/*
** Global Form Config Methods
**
*/
public function getContent()
{
$this->_html .= '<h2>' . $this->l('FEDEX Carrier').'</h2>';
if (!empty($_POST) AND Tools::isSubmit('submitSave'))
{
$this->_postValidation();
if (!sizeof($this->_postErrors))
$this->_postProcess();
else
foreach ($this->_postErrors AS $err)
$this->_html .= '<div class="alert error"><img src="'._PS_IMG_.'admin/forbbiden.gif" alt="nok" /> '.$err.'</div>';
}
$this->_displayForm();
return $this->_html;
}
private function _displayForm()
{
$this->_html .= '<fieldset>
<legend><img src="'.$this->_path.'img/delivery.gif" alt="" /> '.$this->l('Fedex Module Status').'</legend>';
$alert = array();
$this->_webserviceTestResult = $this->webserviceTest();
if (!Configuration::get('FEDEX_CARRIER_ACCOUNT'))
$alert['generalSettings'] = 1;
if (Db::getInstance()->getValue('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_service_code` WHERE `active` = 1') < 1)
$alert['deliveryServices'] = 1;
if (!$this->_webserviceTestResult)
$alert['webserviceTest'] = 1;
if (!extension_loaded('soap'))
$alert['soap'] = 1;
if (!ini_get('allow_url_fopen'))
$alert['url_fopen'] = 1;
if (!extension_loaded('openssl'))
$alert['openssl'] = 1;
if (!count($alert))
$this->_html .= '<img src="'._PS_IMG_.'admin/module_install.png" /><strong>'.$this->l('FEDEX Carrier is configured and online!').'</strong>';
else
{
$this->_html .= '<img src="'._PS_IMG_.'admin/warn2.png" /><strong>'.$this->l('FEDEX Carrier is not configured yet, you must:').'</strong>';
$this->_html .= '<br />'.(isset($alert['generalSettings']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 1) '.$this->l('Fill the "General Settings" form');
$this->_html .= '<br />'.(isset($alert['deliveryServices']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 2) '.$this->l('Select your available delivery service');
$this->_html .= '<br />'.(isset($alert['webserviceTest']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 3) '.$this->l('Webservice test connection').($this->_webserviceError ? ' : '.$this->_webserviceError : '');
$this->_html .= '<br />'.(isset($alert['soap']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 4) '.$this->l('Soap is enabled');
$this->_html .= '<br />'.(isset($alert['url_fopen']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 5) '.$this->l('Url fopen is enabled');
$this->_html .= '<br />'.(isset($alert['openssl']) ? '<img src="'._PS_IMG_.'admin/warn2.png" />' : '<img src="'._PS_IMG_.'admin/module_install.png" />').' 6) '.$this->l('OpenSSL is enabled');
}
$this->_html .= '</fieldset><div class="clear"> </div>';
$this->_html .= $this->_displayFormConfig();
}
private function _postValidation()
{
if (Tools::getValue('section') == 'general')
$this->_postValidationGeneral();
elseif (Tools::getValue('section') == 'category')
$this->_postValidationCategory();
elseif (Tools::getValue('section') == 'product')
$this->_postValidationProduct();
}
private function _postProcess()
{
if (Tools::getValue('section') == 'general')
$this->_postProcessGeneral();
elseif (Tools::getValue('section') == 'category')
$this->_postProcessCategory();
elseif (Tools::getValue('section') == 'product')
$this->_postProcessProduct();
}
/*
** General Form Config Methods
**
*/
private function _displayFormConfig()
{
$html = '
<ul id="menuTab">
<li id="menuTab1" class="menuTabButton selected">1. '.$this->l('General Settings').'</li>
<li id="menuTab2" class="menuTabButton">2. '.$this->l('Categories Settings').'</li>
<li id="menuTab3" class="menuTabButton">3. '.$this->l('Products Settings').'</li>
<li id="menuTab4" class="menuTabButton">4. '.$this->l('Help').'</li>
</ul>
<div id="tabList">
<div id="menuTab1Sheet" class="tabItem selected">'.$this->_displayFormGeneral().'</div>
<div id="menuTab2Sheet" class="tabItem">'.$this->_displayFormCategory().'</div>
<div id="menuTab3Sheet" class="tabItem">'.$this->_displayFormProduct().'</div>
<div id="menuTab4Sheet" class="tabItem">'.$this->_displayHelp().'</div>
</div>
<br clear="left" />
<br />
<style>
#menuTab { float: left; padding: 0; margin: 0; text-align: left; }
#menuTab li { text-align: left; float: left; display: inline; padding: 5px; padding-right: 10px; background: #EFEFEF; font-weight: bold; cursor: pointer; border-left: 1px solid #EFEFEF; border-right: 1px solid #EFEFEF; border-top: 1px solid #EFEFEF; }
#menuTab li.menuTabButton.selected { background: #FFF6D3; border-left: 1px solid #CCCCCC; border-right: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; }
#tabList { clear: left; }
.tabItem { display: none; }
.tabItem.selected { display: block; background: #FFFFF0; border: 1px solid #CCCCCC; padding: 10px; padding-top: 20px; }
</style>
<script>
$(".menuTabButton").click(function () {
$(".menuTabButton.selected").removeClass("selected");
$(this).addClass("selected");
$(".tabItem.selected").removeClass("selected");
$("#" + this.id + "Sheet").addClass("selected");
});
</script>
';
if (isset($_GET['id_tab']))
$html .= '<script>
$(".menuTabButton.selected").removeClass("selected");
$("#menuTab'.Tools::safeOutput(Tools::getValue('id_tab')).'").addClass("selected");
$(".tabItem.selected").removeClass("selected");
$("#menuTab'.Tools::safeOutput(Tools::getValue('id_tab')).'Sheet").addClass("selected");
</script>';
return $html;
}
private function _displayFormGeneral()
{
$configCurrency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'));
$html = '<script>
$(document).ready(function() {
var country = $("#fedex_carrier_country");
country.change(function() {
if ($("#fedex_carrier_state_" + country.val()))
{
$(".stateInput.selected").removeClass("selected");
if ($("#fedex_carrier_state_" + country.val()).size())
$("#fedex_carrier_state_" + country.val()).addClass("selected");
else
$("#fedex_carrier_state_none").addClass("selected");
}
});
$("#configForm").submit(function() {
$("#fedex_carrier_state").val($(".stateInput.selected").val());
});
});
</script>
<style>
.stateInput { display: none; }
.stateInput.selected { display: block; }
.margin-form { padding: 0 0 1em 260px; }
label { width: 250px; }
</style>
<form action="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=1§ion=general" method="post" class="form" id="configForm">
<fieldset style="border: 0px;">
<h4>'.$this->l('General configuration').' :</h4>
<label>'.$this->l('Your Fedex account').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_account" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_account', Configuration::get('FEDEX_CARRIER_ACCOUNT'))).'" /></div>
<label>'.$this->l('Your Fedex meter number').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_meter" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_meter', Configuration::get('FEDEX_CARRIER_METER'))).'" /></div>
<label>'.$this->l('Your Fedex password').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_password" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_password', Configuration::get('FEDEX_CARRIER_PASSWORD'))).'" /></div>
<label>'.$this->l('Your Fedex Authentication Key').' : </label>
<div class="margin-form">
<input type="text" size="20" name="fedex_carrier_api_key" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_api_key', Configuration::get('FEDEX_CARRIER_API_KEY'))).'" />
<p><a href="http://www.fedex.com/webtools/" target="_blank">' . $this->l('Please click here to get your Fedex Authentication Key.') . '</a></p>
</div>
<br /><br />
<label>'.$this->l('Packaging Weight').' : </label>
<div class="margin-form">
<input type="text" size="5" name="fedex_carrier_packaging_weight" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_packaging_weight', Configuration::get('FEDEX_CARRIER_PACKAGING_WEIGHT'))).'" />
'.Tools::safeOutput(Tools::getValue('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT'))).'
</div>
<label>'.$this->l('Handling Fee').' : </label>
<div class="margin-form">
<input type="text" size="5" name="fedex_carrier_handling_fee" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_handling_fee', Configuration::get('FEDEX_CARRIER_HANDLING_FEE'))).'" />
'.$configCurrency->sign.'
</div>
</fieldset>
<fieldset style="border: 0px;">
<h4>'.$this->l('Localization configuration').' :</h4>
<label>'.$this->l('Weight unit').' : </label>
<div class="margin-form">
<input type="text" size="20" name="ps_weight_unit" value="'.Tools::safeOutput(Tools::getValue('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT'))).'" />
<p>'.$this->l('The weight unit of your shop (eg. kg or lbs)').'</p>
</div>
<label>'.$this->l('Dimension unit').' : </label>
<div class="margin-form">
<input type="text" size="20" name="ps_dimension_unit" value="'.Tools::safeOutput(Tools::getValue('ps_dimension_unit', Configuration::get('PS_DIMENSION_UNIT'))).'" />
<p>'.$this->l('The dimension unit of your shop (eg. cm or in)').'</p>
</div>
</fieldset>
<fieldset style="border: 0px;">
<h4>'.$this->l('Address configuration').' :</h4>
<label>'.$this->l('Your address line 1').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_address1" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_address1', Configuration::get('FEDEX_CARRIER_ADDRESS1'))).'" /></div>
<label>'.$this->l('Your address line 2').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_address2" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_address2', Configuration::get('FEDEX_CARRIER_ADDRESS2'))).'" /></div>
<label>'.$this->l('Zip / Postal Code').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_postal_code" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_postal_code', Configuration::get('FEDEX_CARRIER_POSTAL_CODE'))).'" /></div><br />
<label>'.$this->l('Your City').' : </label>
<div class="margin-form"><input type="text" size="20" name="fedex_carrier_city" value="'.Tools::safeOutput(Tools::getValue('fedex_carrier_city', Configuration::get('FEDEX_CARRIER_CITY'))).'" /></div>
<label>'.$this->l('Country').' : </label>
<div class="margin-form">
<select name="fedex_carrier_country" id="fedex_carrier_country">
<option value="0">'.$this->l('Select a country ...').'</option>';
$idcountries = array();
foreach (Country::getCountries($this->context->language->id) as $v)
{
$html .= '<option value="'.$v['id_country'].'" '.($v['id_country'] == (int)(Tools::getValue('fedex_carrier_country', Configuration::get('FEDEX_CARRIER_COUNTRY'))) ? 'selected="selected"' : '').'>'.$v['name'].'</option>';
$idcountries[] = $v['id_country'];
}
$html .= '</select>
<p>' . $this->l('Select country from within the list.') . '</p>
</div>
<label>'.$this->l('State').' : </label>
<div class="margin-form">';
$id_country_current = 0;
$statesList = Db::getInstance()->executeS('
SELECT `id_state`, `id_country`, `name`
FROM `'._DB_PREFIX_.'state` WHERE `active` = 1
ORDER BY `id_country`, `name` ASC');
foreach ($statesList as $v)
{
if ($id_country_current != $v['id_country'])
{
if ($id_country_current != 0)
$html .= '</select>';
$html .= '<select id="fedex_carrier_state_'.$v['id_country'].'" class="stateInput">
<option value="0">'.$this->l('Select a state ...').'</option>';
}
$html .= '<option value="'.$v['id_state'].'" '.($v['id_state'] == (int)(Tools::getValue('fedex_carrier_state', Configuration::get('FEDEX_CARRIER_STATE'))) ? 'selected="selected"' : '').'>'.$v['name'].'</option>';
$id_country_current = $v['id_country'];
}
$html .= '</select><div id="fedex_carrier_state_none" class="stateInput selected">'.$this->l('There is no state configuration for this country').'</div>
<input type="hidden" id="fedex_carrier_state" name="fedex_carrier_state" value="s" />
</div>
</fieldset>
<fieldset style="border: 0px;">
<h4>'.$this->l('Service configuration').' :</h4>
<label>'.$this->l('Default pickup type').' : </label>
<div class="margin-form">
<select name="fedex_carrier_pickup_type">
<option value="0">'.$this->l('Select a default pickup type ...').'</option>';
foreach($this->_pickupTypeList as $kpickup => $vpickup)
$html .= '<option value="'.$kpickup.'" '.($kpickup == pSQL(Configuration::get('FEDEX_CARRIER_PICKUP_TYPE')) ? 'selected="selected"' : '').'>'.$vpickup.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Default packaging type').' : </label>
<div class="margin-form">
<select name="fedex_carrier_packaging_type">
<option value="0">'.$this->l('Select a default packaging type ...').'</option>';
foreach($this->_packagingTypeList as $kpackaging => $vkpackaging)
$html .= '<option value="'.$kpackaging.'" '.($kpackaging == pSQL(Configuration::get('FEDEX_CARRIER_PACKAGING_TYPE')) ? 'selected="selected"' : '').'>'.$vkpackaging.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Calcul mode').' : </label>
<div class="margin-form">
<select name="fedex_carrier_calcul_mode">';
$idcalculmode = array();
foreach($this->_calculModeList as $kcalculmode => $vcalculmode)
$html .= '<option value="'.$kcalculmode.'" '.($kcalculmode == (Tools::getValue('fedex_carrier_calcul_mode', Configuration::get('FEDEX_CARRIER_CALCUL_MODE'))) ? 'selected="selected"' : '').'>'.$vcalculmode.'</option>';
$html .= '</select>
<p>' . $this->l('Using the calcul mode "All items in one package" will automatically use default packaging size, packaging type and delivery services. Specifics configurations for categories or product won\'t be use.') . '</p>
</div>
<label>'.$this->l('Delivery Service').' : </label>
<div class="margin-form">';
$rateServiceList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_service_code`');
foreach($rateServiceList as $rateService)
$html .= '<input type="checkbox" name="service[]" value="'.$rateService['id_fedex_rate_service_code'].'" '.(($rateService['active'] == 1) ? 'checked="checked"' : '').' /> '.$rateService['service'].'<br />';
$html .= '
<p>' . $this->l('Choose the delivery service which will be available for customers.') . '</p>
</div>
</fieldset>
<div class="margin-form"><input class="button" name="submitSave" type="submit" value="'.$this->l('Save').'"></div>
</form>
<script>
var id_country = '.(int)(Tools::getValue('fedex_carrier_country', Configuration::get('FEDEX_CARRIER_COUNTRY'))).';
if ($("#fedex_carrier_state_" + id_country))
{
$(".stateInput.selected").removeClass("selected");
if ($("#fedex_carrier_state_" + id_country).size())
$("#fedex_carrier_state_" + id_country).addClass("selected");
else
$("#fedex_carrier_state_none").addClass("selected");
}
</script>';
return $html;
}
private function _postValidationGeneral()
{
// Check configuration values
if (Tools::getValue('fedex_carrier_account') == NULL)
$this->_postErrors[] = $this->l('Your Fedex account is not specified');
elseif (Tools::getValue('fedex_carrier_meter') == NULL)
$this->_postErrors[] = $this->l('Your Fedex meter is not specified');
elseif (Tools::getValue('fedex_carrier_password') == NULL)
$this->_postErrors[] = $this->l('Your Fedex password is not specified');
elseif (Tools::getValue('fedex_carrier_api_key') == NULL)
$this->_postErrors[] = $this->l('Your Fedex Authentication Key is not specified');
elseif (Tools::getValue('fedex_carrier_pickup_type') == NULL OR Tools::getValue('fedex_carrier_pickup_type') == '0')
$this->_postErrors[] = $this->l('Your pickup type is not specified');
elseif (Tools::getValue('fedex_carrier_packaging_type') == NULL OR Tools::getValue('fedex_carrier_packaging_type') == '0')
$this->_postErrors[] = $this->l('Your packaging type is not specified');
elseif (Tools::getValue('fedex_carrier_postal_code') == NULL)
$this->_postErrors[] = $this->l('Your Zip / Postal code is not specified');
elseif (Tools::getValue('fedex_carrier_city') == NULL)
$this->_postErrors[] = $this->l('Your city is not specified');
elseif (Tools::getValue('fedex_carrier_country') == NULL OR Tools::getValue('fedex_carrier_country') == 0)
$this->_postErrors[] = $this->l('Your country is not specified');
// Check fedex webservice availibity
if (!$this->_postErrors)
{
// Unactive all FEDEX Carriers
Db::getInstance()->autoExecute(_DB_PREFIX_.'fedex_rate_service_code', array('active' => 0), 'UPDATE');
// If no errors appear, the carrier is being activated, else, the carrier is being deactivated
if (!$this->_postErrors)
{
// Get available services
$serviceSelected = Tools::getValue('service');
// Active available carrier
if ($serviceSelected)
foreach ($serviceSelected as $ss)
{
$id_carrier = Db::getInstance()->getValue('SELECT `id_carrier` FROM `'._DB_PREFIX_.'fedex_rate_service_code` WHERE `id_fedex_rate_service_code` = '.(int)($ss));
Db::getInstance()->autoExecute(_DB_PREFIX_.'fedex_rate_service_code', array('active' => 1), 'UPDATE', '`id_fedex_rate_service_code` = '.(int)($ss));
}
}
// All new configurations values are saved to be sure to test webservices with it
Configuration::updateValue('FEDEX_CARRIER_ACCOUNT', Tools::getValue('fedex_carrier_account'));
Configuration::updateValue('FEDEX_CARRIER_METER', Tools::getValue('fedex_carrier_meter'));
Configuration::updateValue('FEDEX_CARRIER_PASSWORD', Tools::getValue('fedex_carrier_password'));
Configuration::updateValue('FEDEX_CARRIER_API_KEY', Tools::getValue('fedex_carrier_api_key'));
Configuration::updateValue('FEDEX_CARRIER_PICKUP_TYPE', Tools::getValue('fedex_carrier_pickup_type'));
Configuration::updateValue('FEDEX_CARRIER_PACKAGING_TYPE', Tools::getValue('fedex_carrier_packaging_type'));
Configuration::updateValue('FEDEX_CARRIER_PACKAGING_WEIGHT', Tools::getValue('fedex_carrier_packaging_weight'));
Configuration::updateValue('FEDEX_CARRIER_HANDLING_FEE', Tools::getValue('fedex_carrier_handling_fee'));
Configuration::updateValue('FEDEX_CARRIER_ADDRESS1', Tools::getValue('fedex_carrier_address1'));
Configuration::updateValue('FEDEX_CARRIER_ADDRESS2', Tools::getValue('fedex_carrier_address2'));
Configuration::updateValue('FEDEX_CARRIER_POSTAL_CODE', Tools::getValue('fedex_carrier_postal_code'));
Configuration::updateValue('FEDEX_CARRIER_CITY', Tools::getValue('fedex_carrier_city'));
Configuration::updateValue('FEDEX_CARRIER_STATE', Tools::getValue('fedex_carrier_state'));
Configuration::updateValue('FEDEX_CARRIER_COUNTRY', Tools::getValue('fedex_carrier_country'));
Configuration::updateValue('FEDEX_CARRIER_CALCUL_MODE', Tools::getValue('fedex_carrier_calcul_mode'));
Configuration::updateValue('PS_WEIGHT_UNIT', $this->_weightUnitList[strtoupper(Tools::getValue('ps_weight_unit'))]);
Configuration::updateValue('PS_DIMENSION_UNIT', $this->_dimensionUnitList[strtoupper(Tools::getValue('ps_dimension_unit'))]);
if (isset($this->_weightUnitList[strtoupper(Tools::getValue('ps_weight_unit'))]))
$this->_weightUnit = $this->_weightUnitList[strtoupper(Tools::getValue('ps_weight_unit'))];
if (isset($this->_dimensionUnitList[strtoupper(Tools::getValue('ps_dimension_unit'))]))
$this->_dimensionUnit = $this->_dimensionUnitList[strtoupper(Tools::getValue('ps_dimension_unit'))];
if (!$this->webserviceTest())
$this->_postErrors[] = $this->l('Prestashop could not connect to FEDEX webservices').' :<br />'.($this->_webserviceError ? $this->_webserviceError : $this->l('No error description found'));
else
Configuration::updateValue('FEDEXCARRIER_CONFIGURATION_OK', true);
}
}
private function _postProcessGeneral()
{
// Saving new configurations
if (Configuration::updateValue('FEDEX_CARRIER_ACCOUNT', Tools::getValue('fedex_carrier_account')) AND
Configuration::updateValue('FEDEX_CARRIER_METER', Tools::getValue('fedex_carrier_meter')) AND
Configuration::updateValue('FEDEX_CARRIER_PASSWORD', Tools::getValue('fedex_carrier_password')) AND
Configuration::updateValue('FEDEX_CARRIER_API_KEY', Tools::getValue('fedex_carrier_api_key')) AND
Configuration::updateValue('FEDEX_CARRIER_PACKAGING_WEIGHT', Tools::getValue('fedex_carrier_packaging_weight')) AND
Configuration::updateValue('FEDEX_CARRIER_HANDLING_FEE', Tools::getValue('fedex_carrier_handling_fee')) AND
Configuration::updateValue('FEDEX_CARRIER_PICKUP_TYPE', Tools::getValue('fedex_carrier_pickup_type')) AND
Configuration::updateValue('FEDEX_CARRIER_PACKAGING_TYPE', Tools::getValue('fedex_carrier_packaging_type')) AND
Configuration::updateValue('FEDEX_CARRIER_POSTAL_CODE', Tools::getValue('fedex_carrier_postal_code')) AND
Configuration::updateValue('FEDEX_CARRIER_CITY', Tools::getValue('fedex_carrier_city')) AND
Configuration::updateValue('FEDEX_CARRIER_STATE', Tools::getValue('fedex_carrier_state')) AND
Configuration::updateValue('FEDEX_CARRIER_COUNTRY', Tools::getValue('fedex_carrier_country')) AND
Configuration::updateValue('FEDEX_CARRIER_CALCUL_MODE', Tools::getValue('fedex_carrier_calcul_mode')) AND
Configuration::updateValue('PS_WEIGHT_UNIT', $this->_weightUnitList[strtoupper(Tools::getValue('ps_weight_unit'))]) AND
Configuration::updateValue('PS_DIMENSION_UNIT', $this->_dimensionUnitList[strtoupper(Tools::getValue('ps_dimension_unit'))]))
$this->_html .= $this->displayConfirmation($this->l('Settings updated'));
else
$this->_html .= $this->displayErrors($this->l('Settings failed'));
}
/*
** Category Form Config Methods
**
*/
private function _getPathInTab($id_category)
{
$category = Db::getInstance()->getRow('
SELECT id_category, level_depth, nleft, nright
FROM '._DB_PREFIX_.'category
WHERE id_category = '.(int)$id_category);
if (isset($category['id_category']))
{
$categories = Db::getInstance()->executeS('
SELECT c.id_category, cl.name, cl.link_rewrite
FROM '._DB_PREFIX_.'category c
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category'.(version_compare(_PS_VERSION_, '1.5.0') >= 0 ? ' '.$this->context->shop->addSqlRestrictionOnLang('cl') : '').')
WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)$this->context->language->id.'
ORDER BY c.level_depth ASC
LIMIT '.(int)($category['level_depth'] + 1));
$n = 1;
$pathTab = array();
$nCategories = (int)sizeof($categories);
foreach ($categories AS $category)
$pathTab[] = htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8');
return $pathTab;
}
}
private function _getChildCategories($categories, $id, $path = array(), $pathAdd = '')
{
$html = '';
if ($pathAdd != '')
$path[] = $pathAdd;
if (isset($categories[$id]))
foreach ($categories[$id] as $idc => $cc)
{
$html .= '<option value="'.$cc['infos']['id_category'].'" '.($cc['infos']['id_category'] == (int)(Tools::getValue('id_category')) ? 'selected="selected"' : '').'>';
if ($path)
foreach ($path as $p)
$html .= $p.' > ';
$html .= $cc['infos']['name'];
$html .= '</option>';
$html .= $this->_getChildCategories($categories, $idc, $path, $cc['infos']['name']);
}
return $html;
}
private function _isPostCheck($id_fedex_rate_service_code)
{
$services = Tools::getValue('service');
if ($services)
foreach ($services as $s)
if ($s == $id_fedex_rate_service_code)
return 1;
return 0;
}
private function _displayFormCategory()
{
// Check if the module is configured
if (!$this->_webserviceTestResult)
return '<p><b>'.$this->l('You have to configure "General Settings" tab before using this tab.').'</b></p><br />';
// Display header
$html = '<p><b>'.$this->l('In this tab, you can set a specific configuration for each category.').'</b></p><br />
<table class="table tableDnD" cellpadding="0" cellspacing="0" width="90%">
<thead>
<tr class="nodrag nodrop">
<th>'.$this->l('ID Config').'</th>
<th>'.$this->l('Category').'</th>
<th>'.$this->l('Pickup type').'</th>
<th>'.$this->l('Packaging type').'</th>
<th>'.$this->l('Additional charges').'</th>
<th>'.$this->l('Services').'</th>
<th>'.$this->l('Actions').'</th>
</tr>
</thead>
<tbody>';
// Loading config list
$configCategoryList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_config` WHERE `id_category` > 0');
if (!$configCategoryList)
$html .= '<tr><td colspan="6">'.$this->l('There is no specific FEDEX configuration for categories at this point.').'</td></tr>';
foreach ($configCategoryList as $k => $c)
{
// Category Path
$path = '';
$pathTab = $this->_getPathInTab($c['id_category']);
foreach ($pathTab as $p)
{
if (!empty($path)) { $path .= ' > '; }
$path .= $p;
}
// Loading config currency
$configCurrency = new Currency($c['id_currency']);
// Loading services attached to this config
$services = '';
$servicesTab = Db::getInstance()->executeS('
SELECT ursc.`service`
FROM `'._DB_PREFIX_.'fedex_rate_config_service` urcs
LEFT JOIN `'._DB_PREFIX_.'fedex_rate_service_code` ursc ON (ursc.`id_fedex_rate_service_code` = urcs.`id_fedex_rate_service_code`)
WHERE urcs.`id_fedex_rate_config` = '.(int)$c['id_fedex_rate_config']);
foreach ($servicesTab as $s)
$services .= $s['service'].'<br />';
// Display line
$alt = 0;
if ($k % 2 != 0)
$alt = ' class="alt_row"';
$html .= '
<tr'.$alt.'>
<td>'.$c['id_fedex_rate_config'].'</td>
<td>'.$path.'</td>
<td>'.(isset($this->_pickupTypeList[$c['pickup_type_code']]) ? $this->_pickupTypeList[$c['pickup_type_code']] : '-').'</td>
<td>'.(isset($this->_packagingTypeList[$c['packaging_type_code']]) ? $this->_packagingTypeList[$c['packaging_type_code']] : '-').'</td>
<td>'.$c['additional_charges'].' '.$configCurrency->sign.'</td>
<td>'.$services.'</td>
<td>
<a href="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=2§ion=category&action=edit&id_fedex_rate_config='.(int)($c['id_fedex_rate_config']).'" style="float: left;">
<img src="'._PS_IMG_.'admin/edit.gif" />
</a>
<form action="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=2§ion=category&action=delete&id_fedex_rate_config='.(int)($c['id_fedex_rate_config']).'&id_category='.(int)($c['id_category']).'" method="post" class="form" style="float: left;">
<input name="submitSave" type="image" src="'._PS_IMG_.'admin/delete.gif" OnClick="return confirm(\''.$this->l('Are you sure you want to delete this specific FEDEX configuration for this category ?').'\');" />
</form>
</td>
</tr>';
}
$html .= '
</tbody>
</table><br /><br />';
// Add or Edit Category Configuration
if (Tools::getValue('action') == 'edit' && Tools::getValue('section') == 'category')
{
// Loading config
$configSelected = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_config` WHERE `id_fedex_rate_config` = '.(int)(Tools::getValue('id_fedex_rate_config')));
// Category Path
$path = '';
$pathTab = $this->_getPathInTab($configSelected['id_category']);
foreach ($pathTab as $p)
{
if (!empty($path)) { $path .= ' > '; }
$path .= $p;
}
$html .= '<p align="center"><b>'.$this->l('Update a rule').' (<a href="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=2§ion=category&action=add">'.$this->l('Add a rule').' ?</a>)</b></p>
<form action="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=2§ion=category&action=edit&id_fedex_rate_config='.(int)(Tools::getValue('id_fedex_rate_config')).'" method="post" class="form">
<label>'.$this->l('Category').' :</label>
<div class="margin-form" style="padding: 0.2em 0.5em 0 0; font-size: 12px;">'.$path.' <input type="hidden" name="id_category" value="'.(int)($configSelected['id_category']).'" /></div><br clear="left" />
<label>'.$this->l('Pickup Type').' : </label>
<div class="margin-form">
<select name="pickup_type_code">
<option value="0">'.$this->l('Select a pickup type ...').'</option>';
foreach($this->_pickupTypeList as $kpickup => $vpickup)
$html .= '<option value="'.$kpickup.'" '.($kpickup == pSQL(Tools::getValue('pickup_type_code', $configSelected['pickup_type_code'])) ? 'selected="selected"' : '').'>'.$vpickup.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Packaging Type').' : </label>
<div class="margin-form">
<select name="packaging_type_code">
<option value="0">'.$this->l('Select a packaging type ...').'</option>';
foreach($this->_packagingTypeList as $kpackaging => $vpackaging)
$html .= '<option value="'.$kpackaging.'" '.($kpackaging == pSQL(Tools::getValue('packaging_type_code', $configSelected['packaging_type_code'])) ? 'selected="selected"' : '').'>'.$vpackaging.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Additional charges').' : </label>
<div class="margin-form"><input type="text" size="20" name="additional_charges" value="'.Tools::safeOutput(Tools::getValue('additional_charges', $configSelected['additional_charges'])).'" /></div><br />
<label>'.$this->l('Delivery Service').' : </label>
<div class="margin-form">';
$rateServiceList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_service_code`');
foreach($rateServiceList as $rateService)
{
$configServiceSelected = Db::getInstance()->getValue('SELECT `id_fedex_rate_service_code` FROM `'._DB_PREFIX_.'fedex_rate_config_service` WHERE `id_fedex_rate_config` = '.(int)(Tools::getValue('id_fedex_rate_config')).' AND `id_fedex_rate_service_code` = '.(int)($rateService['id_fedex_rate_service_code']));
$html .= '<input type="checkbox" name="service[]" value="'.$rateService['id_fedex_rate_service_code'].'" '.(($this->_isPostCheck($rateService['id_fedex_rate_service_code']) == 1 || $configServiceSelected > 0) ? 'checked="checked"' : '').' /> '.$rateService['service'].'<br />';
}
$html .= '
<p>' . $this->l('Choose the delivery service which will be available for customers.') . '</p>
</div>
<div class="margin-form"><input class="button" name="submitSave" type="submit"></div>
</form>';
}
else
{
$html .= '<p align="center"><b>'.$this->l('Add a rule').'</b></p>
<form action="index.php?tab='.Tools::safeOutput(Tools::getValue('tab')).'&configure='.Tools::safeOutput(Tools::getValue('configure')).'&token='.Tools::safeOutput(Tools::getValue('token')).'&tab_module='.Tools::safeOutput(Tools::getValue('tab_module')).'&module_name='.Tools::safeOutput(Tools::getValue('module_name')).'&id_tab=2§ion=category&action=add" method="post" class="form">
<label>'.$this->l('Category').' : </label>
<div class="margin-form">
<select name="id_category">
<option value="0">'.$this->l('Select a category ...').'</option>
'.$this->_getChildCategories(Category::getCategories($this->context->language->id), 0).'
</select>
</div>
<label>'.$this->l('Pickup Type').' : </label>
<div class="margin-form">
<select name="pickup_type_code">
<option value="0">'.$this->l('Select a pickup type ...').'</option>';
foreach($this->_pickupTypeList as $kpickup => $vpickup)
$html .= '<option value="'.$kpickup.'" '.($kpickup === pSQL(Tools::getValue('pickup_type_code')) ? 'selected="selected"' : '').'>'.$vpickup.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Packaging Type').' : </label>
<div class="margin-form">
<select name="packaging_type_code">
<option value="0">'.$this->l('Select a packaging type ...').'</option>';
foreach($this->_packagingTypeList as $kpackaging => $vpackaging)
$html .= '<option value="'.$kpackaging.'" '.($kpackaging == pSQL(Tools::getValue('packaging_type_code')) ? 'selected="selected"' : '').'>'.$vpackaging.'</option>';
$html .= '</select>
</div>
<label>'.$this->l('Additional charges').' : </label>
<div class="margin-form"><input type="text" size="20" name="additional_charges" value="'.Tools::safeOutput(Tools::getValue('additional_charges')).'" /></div><br />
<label>'.$this->l('Delivery Service').' : </label>
<div class="margin-form">';
$rateServiceList = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fedex_rate_service_code`');
foreach($rateServiceList as $rateService)
$html .= '<input type="checkbox" name="service[]" value="'.$rateService['id_fedex_rate_service_code'].'" '.(($this->_isPostCheck($rateService['id_fedex_rate_service_code']) == 1) ? 'checked="checked"' : '').' /> '.$rateService['service'].'<br />';
$html .= '
<p>' . $this->l('Choose the delivery service which will be available for customers.') . '</p>
</div>
<div class="margin-form"><input class="button" name="submitSave" type="submit"></div>
</form>';
}
return $html;
}
private function _postValidationCategory()
{
// Check post values
if (Tools::getValue('id_category') == NULL)
$this->_postErrors[] = $this->l('You have to select a category.');
if (!$this->_postErrors)
{
$id_fedex_rate_config = Db::getInstance()->getValue('SELECT `id_fedex_rate_config` FROM `'._DB_PREFIX_.'fedex_rate_config` WHERE `id_category` = '.(int)Tools::getValue('id_category'));
// Check if a config does not exist in Add case
if ($id_fedex_rate_config > 0 && Tools::getValue('action') == 'add')
$this->_postErrors[] = $this->l('This category already has a specific FEDEX configuration.');
// Check if a config exists and if the IDs config correspond in Upd case
if (Tools::getValue('action') == 'edit' && (!isset($id_fedex_rate_config) || $id_fedex_rate_config != Tools::getValue('id_fedex_rate_config')))
$this->_postErrors[] = $this->l('An error occurred, please try again.');
// Check if a config exists in Delete case
if (Tools::getValue('action') == 'delete' && !isset($id_fedex_rate_config))
$this->_postErrors[] = $this->l('An error occurred, please try again.');
}
}
private function _postProcessCategory()
{
// Init Var
$date = date('Y-m-d H:i:s');
$services = Tools::getValue('service');
// Add Script
if (Tools::getValue('action') == 'add')
{
$addTab = array(
'id_product' => 0,
'id_category' => (int)(Tools::getValue('id_category')),
'id_currency' => (int)(Configuration::get('PS_CURRENCY_DEFAULT')),
'pickup_type_code' => pSQL(Tools::getValue('pickup_type_code')),
'packaging_type_code' => pSQL(Tools::getValue('packaging_type_code')),
'additional_charges' => pSQL(Tools::getValue('additional_charges')),
'date_add' => pSQL($date),
'date_upd' => pSQL($date)
);