-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcolissimo_simplicite.php
1767 lines (1627 loc) · 72.1 KB
/
colissimo_simplicite.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
/**
* 2010-2016 La Poste SA
*
* 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 a 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 Quadra Informatique <[email protected]>
* @copyright 2010-2016 La Poste SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of La Poste SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once _PS_MODULE_DIR_.'colissimo_simplicite/models/ColissimoDeliveryInfo.php';
require_once(_PS_MODULE_DIR_.'colissimo_simplicite/models/ColissimoDeliveryPoint.php');
class Colissimo_simplicite extends CarrierModule
{
protected $config_form = false;
protected $config_single_values_keys = false;
private $api_num_version = '4.0';
protected $initial_cost;
public $url = '';
private $link_to_img = '';
private $config = array(
'name' => 'La Poste - Colissimo Simplicité',
'id_tax_rules_group' => 0,
'url' => 'http://www.colissimo.fr/portail_colissimo/suivreResultat.do?parcelnumber=@',
'active' => true,
'deleted' => 0,
'shipping_handling' => false,
'range_behavior' => 0,
'is_module' => true,
'delay' => array(
'fr' => 'Faites vous livrer en France métropolitaine ou en Europe, dans un des points retrait Colissimo.',
'en' => 'Do you deliver wherever you want in France.'),
'id_zone' => 1,
'shipping_external' => true,
'external_module_name' => 'colissimo_simplicite',
'need_range' => true
);
public function __construct()
{
$this->name = 'colissimo_simplicite';
$this->tab = 'shipping_logistics';
$this->version = '4.0.13';
$this->author = 'Quadra Informatique';
$this->module_key = '8b991db851bdf7c64ca441f1a4481964';
$this->need_instance = 1;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Colissimo Simplicite');
$this->description = $this->l('Offer your customer 5 different delivery methods with LaPoste.');
$this->confirmUninstall = $this->l('Removing the module will also delete the associated carrier');
$this->ps_versions_compliancy = array(
'min' => '1.7',
'max' => _PS_VERSION_);
$protocol = 'http://';
$this->link_to_img = $this->_path.'/views/img/';
if (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) {
$protocol = 'https://';
}
$this->url = $protocol.Tools::getShopDomainSsl().__PS_BASE_URI__.'modules/'.$this->name.'/validation.php';
if (self::isInstalled($this->name)) {
$warning = array();
$so_carrier = new Carrier(Configuration::get('COLISSIMO_CARRIER_ID'));
if (Validate::isLoadedObject($so_carrier)) {
if (!$this->checkZone((int)$so_carrier->id)) {
$warning[] .= $this->l('\'Carrier Zone(s)\'').' ';
}
if (!$this->checkGroup((int)$so_carrier->id)) {
$warning[] .= $this->l('\'Carrier Group\'').' ';
}
if (!$this->checkRange((int)$so_carrier->id)) {
$warning[] .= $this->l('\'Carrier Range(s)\'').' ';
}
if (!$this->checkDelivery((int)$so_carrier->id)) {
$warning[] .= $this->l('\'Carrier price delivery\'').' ';
}
}
//Check config and display warning
if (!Configuration::get('COLISSIMO_ID')) {
$warning[] .= $this->l('\'Id FO\'').' ';
}
if (!Configuration::get('COLISSIMO_KEY')) {
$warning[] .= $this->l('\'Key\'').' ';
}
if (!Configuration::get('COLISSIMO_URL')) {
$warning[] .= $this->l('\'Url So\'').' ';
}
if (count($warning)) {
$this->warning .= implode(' , ', $warning).$this->l('must be configured to use this module correctly').' ';
}
}
$this->config_single_values_keys = array(
'COLISSIMO_CARRIER_ID',
'COLISSIMO_ID',
'COLISSIMO_KEY',
'COLISSIMO_URL',
'COLISSIMO_URL_MOBILE',
'COLISSIMO_URL_POINTDERETRAIT',
'COLISSIMO_WS_URL',
'COLISSIMO_OVERCOST',
'COLISSIMO_COST_SELLER',
'COLISSIMO_SELLER_AMOUNT',
'COLISSIMO_UPG_COUNTRY',
'COLISSIMO_PREPARATION_TIME',
'COLISSIMO_CARRIER_ID',
'COLISSIMO_MIN_COST',
'COLISSIMO_SUP',
'COLISSIMO_SUP_URL',
'COLISSIMO_OVERCOST_TAX',
'COLISSIMO_PERSONAL_PHONE',
'COLISSIMO_PERSONAL_ZIP_CODE',
'COLISSIMO_PERSONAL_QUANTITIES',
'COLISSIMO_PERSONAL_SIRET',
'COLISSIMO_PERSONAL_DATA',
'COLISSIMO_SELLER_IMPACT',
'COLISSIMO_USE_POINTDERETRAIT',
'COLISSIMO_LOGIN',
'COLISSIMO_PASSWORD'
);
$this->config_single_values_keys_exception = array(
'COLISSIMO_PERSONAL_PHONE',
'COLISSIMO_PERSONAL_ZIP_CODE',
'COLISSIMO_PERSONAL_QUANTITIES',
'COLISSIMO_PERSONAL_SIRET',
'COLISSIMO_PERSONAL_DATA',
'COLISSIMO_PERSONAL_ACCEPT'
);
}
public function install()
{
if (extension_loaded('curl') == false) {
$this->_errors[] = $this->l('You have to enable the cURL extension on your server to install this module');
return false;
}
$carrier = $this->addCarrier();
$this->addZones($carrier);
$this->addGroups($carrier);
$this->addRanges($carrier);
if (!Configuration::updateValue('COLISSIMO_ID', null) ||
!Configuration::updateValue('COLISSIMO_KEY', null) ||
!Configuration::updateValue('COLISSIMO_URL', 'ws.colissimo.fr/pudo-fo-frame/storeCall.do') ||
!Configuration::updateValue('COLISSIMO_URL_MOBILE', 'ws-mobile.colissimo.fr/') ||
!Configuration::updateValue('COLISSIMO_PREPARATION_TIME', 1) ||
!Configuration::updateValue('COLISSIMO_OVERCOST', 3.6) ||
!Configuration::updateValue('COLISSIMO_COST_SELLER', false) ||
!Configuration::updateValue('COLISSIMO_SELLER_AMOUNT', 0) ||
!Configuration::updateValue('COLISSIMO_SELLER_IMPACT', 0) ||
!Configuration::updateValue('COLISSIMO_SUP_URL', 'ws.colissimo.fr/supervision-pudo-frame/supervision.jsp') ||
!Configuration::updateValue('COLISSIMO_SUP', true) ||
!Configuration::updateValue('COLISSIMO_TOKEN_POINTDERETRAIT', '') ||
!Configuration::updateValue('COLISSIMO_PDR_TOKEN_HOUR', '') ||
!Configuration::updateValue('COLISSIMO_USE_POINTDERETRAIT', '1') ||
!Configuration::updateValue('COLISSIMO_URL_POINTDERETRAIT', 'ws.colissimo.fr/widget-point-retrait/rest/authenticate.rest') ||
!Configuration::updateValue('COLISSIMO_WS_URL', 'ws.colissimo.fr/') ||
!Configuration::updateValue('COLISSIMO_LOGIN', null) ||
!Configuration::updateValue('COLISSIMO_PASSWORD', null)
) {
return false;
}
include(dirname(__FILE__).'/sql/install.php');
return parent::install() &&
$this->registerHook('header') &&
$this->registerHook('backOfficeHeader') &&
$this->registerHook('updateCarrier') &&
$this->registerHook('actionValidateOrder') &&
$this->registerHook('actionCarrierUpdate') &&
$this->registerHook('displayAdminOrder') &&
$this->registerHook('displayCarrierExtraContent');
}
public function uninstall()
{
$so_id = (int)Configuration::get('COLISSIMO_CARRIER_ID');
//Configuration::deleteByName('COLISSIMO_ID');
//Configuration::deleteByName('COLISSIMO_KEY');
Configuration::deleteByName('COLISSIMO_URL');
Configuration::deleteByName('COLISSIMO_URL_MOBILE');
Configuration::deleteByName('COLISSIMO_OVERCOST');
Configuration::deleteByName('COLISSIMO_COST_SELLER');
Configuration::deleteByName('COLISSIMO_SELLER_AMOUNT');
Configuration::deleteByName('COLISSIMO_SELLER_IMPACT');
Configuration::deleteByName('COLISSIMO_UPG_COUNTRY');
Configuration::deleteByName('COLISSIMO_PREPARATION_TIME');
Configuration::deleteByName('COLISSIMO_CARRIER_ID');
Configuration::deleteByName('COLISSIMO_SUP');
Configuration::deleteByName('COLISSIMO_SUP_URL');
Configuration::deleteByName('COLISSIMO_OVERCOST_TAX');
$carrier = new Carrier($so_id);
$carrier->delete();
include(dirname(__FILE__).'/sql/uninstall.php');
return parent::uninstall();
}
/**
* Load the configuration form
*/
public function getContent()
{
if (((bool)Tools::isSubmit('submitColissimo_simpliciteModule')) == true) {
$this->postProcess();
}
$this->context->smarty->assign(array(
'module_dir' => $this->_path,
'colissimo_version' => $this->version
));
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
if (!Configuration::get('COLISSIMO_PERSONAL_DATA')) {
$output .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure_warning.tpl');
}
return $output.$this->renderForm();
}
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitColissimo_simpliciteModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array(
array(
'form' => $this->getConfigForm()
)
));
}
/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
$form = array(
'legend' => array(
'title' => $this->l('Colissimo Simplicity').' V'.$this->version,
'icon' => 'icon-cogs',
),
'submit' => array(
'title' => $this->l('Save'),
)
);
//======================================================================
// INFO TAB
$form['tabs']['about'] = $this->l('About Colissimo Informations');
// Check current language
$language = new Language($this->context->language->id);
$defaut_tpl = $this->local_path.'views/templates/admin/about_fr.tpl';
if ($language->iso_code != 'fr') {
$defaut_tpl = $this->local_path.'views/templates/admin/about_en.tpl';
}
$form['input'][] = array(
'tab' => 'about',
'type' => 'html',
'name' => 'about',
'html_content' => $this->context->smarty->fetch($defaut_tpl),
);
//======================================================================
// CREDENTIALS TAB
$form['tabs']['credentials'] = $this->l('Merchant Informations');
$form['input'][] = array(
'tab' => 'credentials',
'type' => 'text',
'col' => 2,
'required' => true,
'label' => $this->l('Phone number'),
'name' => 'COLISSIMO_PERSONAL_PHONE',
'desc' => $this->l('Example 0144183004'),
);
$form['input'][] = array(
'tab' => 'credentials',
'type' => 'text',
'col' => 2,
'required' => true,
'label' => $this->l('Zip code'),
'name' => 'COLISSIMO_PERSONAL_ZIP_CODE',
'desc' => $this->l('Example 92300'),
);
$form['input'][] = array(
'tab' => 'credentials',
'type' => 'select',
'required' => true,
'label' => $this->l('Mean number of parcels'),
'name' => 'COLISSIMO_PERSONAL_QUANTITIES',
'options' => array(
'query' => array(
array(
'id' => '< 250 colis / mois',
'name' => $this->l('< 250 colis / mois')
),
array(
'id' => '> 250 colis / mois',
'name' => $this->l('> 250 colis / mois')
),
),
'id' => 'id',
'name' => 'name'
),
);
$form['input'][] = array(
'tab' => 'credentials',
'type' => 'text',
'col' => 2,
'required' => true,
'label' => $this->l('Siret'),
'name' => 'COLISSIMO_PERSONAL_SIRET',
'desc' => $this->l('Siret is 14 number'),
);
$form['input'][] = array(
'tab' => 'credentials',
'type' => 'checkbox',
'required' => true,
'label' => $this->l('Terms & conditions'),
'name' => 'COLISSIMO_PERSONAL',
'desc' => $this->l('In case of refusal, you can sent an email at the following address').
' : <a style="color: #268ccd;" href="mailto: [email protected]">[email protected]</a>',
'values' => array(
'query' => array(
array(
'id' => 'ACCEPT',
'name' => $this->l('I accept that informations concerning the number of parcels are sent to our partner La poste - Colissimo'),
'val' => 1
),
),
'id' => 'id',
'name' => 'name',
)
);
//======================================================================
// GENERAL TAB
$form['tabs']['general'] = $this->l('Your Colissimo Box');
$form['input'][] = array(
'tab' => 'general',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Encryption key'),
'name' => 'COLISSIMO_KEY',
'desc' => $this->l('Available in your ').' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'.'<br/>'.
$this->l('by using the menu "Applications > Delivery > Choice of delivery methods" ')
);
$form['input'][] = array(
'tab' => 'general',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Front Office Identifier'),
'name' => 'COLISSIMO_ID',
'desc' => $this->l('Available in your ').' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'.'<br/>'.
$this->l('by using the menu "Applications > Delivery > Choice of delivery methods" ')
);
$form['input'][] = array(
'tab' => 'general',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Order Preparation time'),
'suffix' => $this->l('Day(s)'),
'name' => 'COLISSIMO_PREPARATION_TIME',
'desc' => $this->l('Business days from Monday to Friday').
'<br/>'.$this->l('Must be the same parameter as in your ').
' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'
);
$form['input'][] = array(
'tab' => 'general',
'type' => 'html',
'name' => 'url_note',
'html_content' => '<hr/><strong>'.$this->l('Please fill in these two addresses in your').
' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a></strong><ul>'.
'<li>'.$this->l('In the "Delivery options selection page"').'</li>'.
'<li>'.$this->l('In the "Delivery options selection page (mobile version)"').'</li></ul>',
);
$form['input'][] = array(
'tab' => 'general',
'type' => 'free',
'label' => $this->l('When the customer has successfully selected the delivery method (Validation)'),
'name' => 'VALIDATION_URL',
);
$form['input'][] = array(
'tab' => 'general',
'type' => 'free',
'label' => $this->l('When the client could not select the delivery method (Failed)'),
'name' => 'RETURN_URL',
);
//======================================================================
// SYSTEM TAB
$form['tabs']['system'] = $this->l('Colissimo simplicity system parameters');
$form['input'][] = array(
'tab' => 'system',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Url of back office Colissimo.'),
'name' => 'COLISSIMO_URL',
'desc' => $this->l('Url of back office Colissimo.')
);
$form['input'][] = array(
'tab' => 'system',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Url So Mobile'),
'name' => 'COLISSIMO_URL_MOBILE',
'desc' => $this->l('Url of back office Colissimo Mobile. Customers with smartphones or ipad will be redirect there. Warning, this url do not allow delivery in belgium ')
);
$form['input'][] = array(
'tab' => 'system',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Url web service la poste'),
'name' => 'COLISSIMO_WS_URL',
'desc' => $this->l('Url of web service la poste')
);
$form['input'][] = array(
'tab' => 'system',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Url authentification Point de retrait'),
'name' => 'COLISSIMO_URL_POINTDERETRAIT',
'desc' => $this->l('Url of point de retrait option')
);
$form['input'][] = array(
'tab' => 'system',
'type' => 'switch',
'label' => $this->l('Supervision'),
'name' => 'COLISSIMO_SUP',
'is_bool' => true,
'required' => true,
'desc' => $this->l('Enable or disable the check availability of Colissimo service.'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
);
$form['input'][] = array(
'tab' => 'system',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Url Supervision'),
'name' => 'COLISSIMO_SUP_URL',
'desc' => $this->l('The monitor URL is to ensure the availability of the socolissimo service. We strongly recommend that you do not disable it')
);
//======================================================================
// PRESTASHOP TAB
$form['tabs']['prestashop'] = $this->l('Colissimo simplicity prestashop parameters');
$form['input'][] = array(
'tab' => 'prestashop',
'type' => 'select',
'required' => true,
'label' => $this->l('Home carrier'),
'name' => 'COLISSIMO_CARRIER_ID',
'options' => array(
'query' => Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::ALL_CARRIERS),
'id' => 'id_carrier',
'name' => 'name'
),
'desc' => $this->l('Carrier used to get "Colissimo at home" cost')
);
$form['input'][] = array(
'tab' => 'prestashop',
'type' => 'switch',
'col' => 4,
'label' => $this->l('Withdrawal point cost'),
'name' => 'COLISSIMO_COST_SELLER',
'is_bool' => true,
'required' => true,
'desc' => $this->l('This cost override the normal cost for seller delivery.'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
);
$form['input'][] = array(
'tab' => 'prestashop',
'col' => 4,
'type' => 'text',
'required' => true,
'label' => $this->l('Withdrawal cost'),
'name' => 'COLISSIMO_SELLER_AMOUNT',
'desc' => $this->l('Withdrawal cost for "Colissimo at a withdrawal point"')
);
$form['input'][] = array(
'tab' => 'prestashop',
'col' => 3,
'type' => 'radio',
'label' => $this->l('Price impact'),
'name' => 'COLISSIMO_SELLER_IMPACT',
'required' => false,
'desc' => $this->l('Choose your impact on the price for Withdrawal cost'),
'values' => array(
array
(
'id' => 'price_down',
'value' => 0,
'label' => $this->l('Down the price')
),
array(
'id' => 'price_up',
'value' => 1,
'label' => $this->l('Up the price')
),
)
);
//======================================================================
// WITHDRAWAL TAB
$form['tabs']['withdrawal'] = $this->l('Front page Withdrawal');
$form['input'][] = array(
'tab' => 'withdrawal',
'type' => 'switch',
'label' => $this->l('Activate Colissimo withdrawal point, free option'),
'name' => 'COLISSIMO_USE_POINTDERETRAIT',
'is_bool' => true,
'required' => true,
'desc' => $this->l('Enable Colissimo withdrawal point, if you have Profesionnal contrat, disable this'),
'values' => array(
array(
'id' => 'active_on',
'value' => '1',
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => '0',
'label' => $this->l('Disabled')
)
),
);
$form['input'][] = array(
'tab' => 'withdrawal',
'col' => 3,
'type' => 'text',
'required' => false,
'id' => 'colissimo_login',
'label' => $this->l('Login Colissimo'),
'name' => 'COLISSIMO_LOGIN',
'desc' => $this->l('Your connexion login at(only for free option) ').' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'
);
$form['input'][] = array(
'tab' => 'withdrawal',
'col' => 3,
'type' => 'text',
'required' => false,
'id' => 'colissimo_password',
'label' => $this->l('Password Colissimo'),
'name' => 'COLISSIMO_PASSWORD',
'desc' => $this->l('Your connexion password at(only for free option) ').' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'
);
$form['input'][] = array(
'tab' => 'withdrawal',
'col' => 3,
'type' => 'text',
'required' => true,
'label' => $this->l('Order Preparation time'),
'suffix' => $this->l('Day(s)'),
'name' => 'COLISSIMO_PREPARATION_TIME',
'desc' => $this->l('Business days from Monday to Friday').
'<br/>'.$this->l('Must be the same parameter as in your ').
' <a href="https://www.colissimo.entreprise.laposte.fr" target="_blank" >Colissimo Box </a>'
);
return $form;
}
/**
* Set values for the inputs.
*/
protected function getConfigFormValues()
{
$return = array();
foreach ($this->config_single_values_keys as $key) {
$return[$key] = Configuration::get($key);
}
$return['VALIDATION_URL'] = '<p class="form-control-static">'.htmlentities($this->url, ENT_NOQUOTES, 'UTF-8').'</p>';
$return['RETURN_URL'] = '<p class="form-control-static">'.htmlentities($this->url, ENT_NOQUOTES, 'UTF-8').'</p>';
return $return;
}
protected function savePreactivationRequest()
{
$employee = new Employee((int)Context::getContext()->cookie->id_employee);
$data = array(
'iso_lang' => Tools::strtolower($this->context->language->iso_code),
'iso_country' => Tools::strtoupper($this->context->country->iso_code),
'host' => $_SERVER['HTTP_HOST'],
'ps_version' => _PS_VERSION_,
'ps_creation' => _PS_CREATION_DATE_,
'partner' => $this->name,
'firstname' => $employee->firstname,
'lastname' => $employee->lastname,
'email' => $employee->email,
'shop' => Configuration::get('PS_SHOP_NAME'),
'type' => 'home',
'phone' => Configuration::get('COLISSIMO_PERSONAL_PHONE'),
'zipcode' => Configuration::get('COLISSIMO_PERSONAL_ZIP_CODE'),
'fields' => serialize(
array(
'quantities' => Configuration::get('COLISSIMO_PERSONAL_QUANTITIES'),
'siret' => Configuration::get('COLISSIMO_PERSONAL_SIRET'),
)
),
);
$query = http_build_query($data);
return @Tools::file_get_contents('http://api.prestashop.com/partner/premium/set_request.php?'.$query);
}
/**
* Save form data.
*/
protected function postProcess()
{
if (Tools::getValue('COLISSIMO_ID') == null && (!Configuration::get('COLISSIMO_USE_POINTDERETRAIT')) && (Tools::getValue('COLISSIMO_USE_POINTDERETRAIT') == 0)) {
$this->context->controller->errors[] = $this->l('ID SO not specified');
}
if (Tools::getValue('COLISSIMO_KEY') == null && (Configuration::get('COLISSIMO_USE_POINTDERETRAIT') == 0) && (Tools::getValue('COLISSIMO_USE_POINTDERETRAIT') == 0)) {
$this->context->controller->errors[] = $this->l('Key SO not specified');
}
if (Tools::getValue('COLISSIMO_LOGIN') == null && (Configuration::get('COLISSIMO_USE_POINTDERETRAIT') == 1) && (Tools::getValue('COLISSIMO_USE_POINTDERETRAIT') == 1 )) {
$this->context->controller->errors[] = $this->l('Login Colissimo is not specified, required for free option');
}
if (Tools::getValue('COLISSIMO_PASSWORD') == null && (Configuration::get('COLISSIMO_USE_POINTDERETRAIT') == 1) && (Tools::getValue('COLISSIMO_USE_POINTDERETRAIT') == 1 )) {
$this->context->controller->errors[] = $this->l('Pass Colissimo is not specified, required for free option');
}
if (Tools::getValue('COLISSIMO_PREPARATION_TIME') == null) {
$this->context->controller->errors[] = $this->l('Preparation time not specified');
} elseif (!Validate::isInt(Tools::getValue('COLISSIMO_PREPARATION_TIME'))) {
$this->context->controller->errors[] = $this->l('Invalid preparation time');
}
if (Tools::getValue('COLISSIMO_URL') == null) {
$this->context->controller->errors[] = $this->l('Front URL is not specified');
}
if (Tools::getValue('COLISSIMO_URL_MOBILE') == null) {
$this->context->controller->errors[] = $this->l('Front mobile URL is not specified');
}
if (Tools::getValue('COLISSIMO_SUP_URL') == null) {
$this->context->controller->errors[] = $this->l('Supervision URL is not specified');
}
if (!count($this->context->controller->errors)) {
// re allocation id socolissimo if needed
if ((int)Tools::getValue('COLISSIMO_CARRIER_ID') != (int)Configuration::get('COLISSIMO_CARRIER_ID')) {
Configuration::updateValue(
'COLISSIMO_CARRIER_ID',
(int)Tools::getValue('COLISSIMO_CARRIER_ID')
);
$this->reallocationCarrier((int)Configuration::get('COLISSIMO_CARRIER_ID'));
}
foreach ($this->config_single_values_keys as $key) {
if (!array_search($key, $this->config_single_values_keys_exception)) {
Configuration::updateValue($key, Tools::getValue($key));
}
}
}
$reload_credit = false;
if (Configuration::get('COLISSIMO_PERSONAL_DATA')) {
if (Tools::getValue('COLISSIMO_PERSONAL_PHONE') && (Tools::getValue('COLISSIMO_PERSONAL_PHONE') != Configuration::get('COLISSIMO_PERSONAL_PHONE'))) {
$reload_credit = true;
}
if (Tools::getValue('COLISSIMO_PERSONAL_ZIP_CODE') && (Tools::getValue('COLISSIMO_PERSONAL_ZIP_CODE') != Configuration::get('COLISSIMO_PERSONAL_ZIP_CODE'))) {
$reload_credit = true;
}
if (Tools::getValue('COLISSIMO_PERSONAL_QUANTITIES') && (Tools::getValue('COLISSIMO_PERSONAL_QUANTITIES') != Configuration::get('COLISSIMO_PERSONAL_QUANTITIES'))) {
$reload_credit = true;
}
if (Tools::getValue('COLISSIMO_PERSONAL_SIRET') && (Tools::getValue('COLISSIMO_PERSONAL_SIRET') != Configuration::get('COLISSIMO_PERSONAL_SIRET'))) {
$reload_credit = true;
}
}
if (!Configuration::get('COLISSIMO_PERSONAL_DATA') || $reload_credit) {
if (!(bool)preg_match('#^(([\d]{2})([\s]){0,1}){5}$#', Tools::getValue('COLISSIMO_PERSONAL_PHONE'))) {
$this->context->controller->errors[] = $this->l('Phone number is incorrect');
}
if (!(bool)preg_match('#^(([0-8][0-9])|(9[0-5]))[0-9]{3}$#', Tools::getValue('COLISSIMO_PERSONAL_ZIP_CODE'))) {
$this->context->controller->errors[] = $this->l('Zip code is incorrect');
}
if (!Tools::getValue('COLISSIMO_PERSONAL_QUANTITIES')) {
$this->context->controller->errors[] = $this->l('Mean number is incorrect');
}
if (!$this->isSiret(Tools::getValue('COLISSIMO_PERSONAL_SIRET'))) {
$this->context->controller->errors[] = $this->l('Siret is incorrect');
}
if (!Tools::getValue('COLISSIMO_PERSONAL_ACCEPT')) {
$this->context->controller->errors[] = $this->l('You must accept terms and conditions');
}
if (!count($this->context->controller->errors)) {
Configuration::updateValue('COLISSIMO_PERSONAL_PHONE', Tools::getValue('COLISSIMO_PERSONAL_PHONE'));
Configuration::updateValue('COLISSIMO_PERSONAL_ZIP_CODE', Tools::getValue('COLISSIMO_PERSONAL_ZIP_CODE'));
Configuration::updateValue('COLISSIMO_PERSONAL_QUANTITIES', Tools::getValue('COLISSIMO_PERSONAL_QUANTITIES'));
Configuration::updateValue('COLISSIMO_PERSONAL_SIRET', Tools::getValue('COLISSIMO_PERSONAL_SIRET'));
Configuration::updateValue('COLISSIMO_PERSONAL_ACCEPT', Tools::getValue('COLISSIMO_PERSONAL_ACCEPT'));
Configuration::updateValue('COLISSIMO_USE_POINTDERETRAIT', Tools::getValue('COLISSIMO_USE_POINTDERETRAIT'));
if ($this->savePreactivationRequest()) {
Configuration::updateValue('COLISSIMO_PERSONAL_DATA', 1);
}
}
}
}
public function getOrderShippingCost($params, $shipping_cost)
{
// for order in BO
if (!$this->context->cart instanceof Cart || !$this->context->cart->id) {
$this->context->cart = new Cart($params->id);
}
// check colissimopass module installed and used
if (Module::isEnabled('colissimopass')) {
// is user connect ?
require_once(_PS_MODULE_DIR_.'colissimopass/classes/ColissimoPassUser.php');
if (ColissimoPassUser::isActive()) {
return 0;
}
// is product pass in cart ?
$cart = $this->context->cart;
$products = $cart->getProducts();
if (is_array($products)) {
foreach ($products as $product) {
if ($product['id_product'] == (int)Configuration::get('ID_COLISSIMO_PASS_PDT')) {
return 0;
}
}
}
}
if (!$this->initial_cost) {
$this->initial_cost = $shipping_cost;
}
// check api already return a shipping cost ?
$api_price = $this->getApiPrice((int)$this->context->cart->id);
if ($api_price) {
$carrier_colissimo = new Carrier((int)Configuration::get('COLISSIMO_CARRIER_ID'));
$address = new Address((int)$this->context->cart->id_address_delivery);
$tax = $carrier_colissimo->getTaxesRate($address);
// must retrieve the price without tax if needed
if ($tax) {
(float)$tax_rate = ((float)$tax / 100) + 1;
$api_price = (float)$api_price / (float)$tax_rate;
}
return (float)$api_price;
}
return $shipping_cost;
}
public function getOrderShippingCostExternal($params)
{
return true;
}
protected function addCarrier()
{
$carrier = new Carrier();
$carrier->name = $this->config['name'];
$carrier->id_tax_rules_group = $this->config['id_tax_rules_group'];
$carrier->id_zone = $this->config['id_zone'];
$carrier->url = $this->config['url'];
$carrier->active = $this->config['active'];
$carrier->deleted = $this->config['deleted'];
$carrier->shipping_handling = $this->config['shipping_handling'];
$carrier->range_behavior = $this->config['range_behavior'];
$carrier->is_module = $this->config['is_module'];
$carrier->shipping_external = $this->config['shipping_external'];
$carrier->external_module_name = $this->config['external_module_name'];
$carrier->need_range = $this->config['need_range'];
foreach (Language::getLanguages() as $lang) {
if ($lang['iso_code'] == 'fr') {
$carrier->delay[$lang['id_lang']] = $this->config['delay'][$lang['iso_code']];
}
if ($lang['iso_code'] == 'en') {
$carrier->delay[$lang['id_lang']] = $this->config['delay'][$lang['iso_code']];
}
}
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if ($carrier->add() == true) {
@copy(dirname(__FILE__).'/views/img/colissimo.jpg', _PS_SHIP_IMG_DIR_.'/'.(int)$carrier->id.'.jpg');
Configuration::updateValue('COLISSIMO_CARRIER_ID', (int)$carrier->id);
return $carrier;
}
return false;
}
protected function addGroups($carrier)
{
$groups_ids = array();
$groups = Group::getGroups(Context::getContext()->language->id);
foreach ($groups as $group) {
$groups_ids[] = $group['id_group'];
}
$carrier->setGroups($groups_ids);
}
protected function addRanges($carrier)
{
$range_price = new RangePrice();
$range_price->id_carrier = $carrier->id;
$range_price->delimiter1 = '0';
$range_price->delimiter2 = '10000';
$range_price->add();
$range_weight = new RangeWeight();
$range_weight->id_carrier = $carrier->id;
$range_weight->delimiter1 = '0';
$range_weight->delimiter2 = '10000';
$range_weight->add();
}
protected function addZones($carrier)
{
$zones = Zone::getZones();
foreach ($zones as $zone) {
$carrier->addZone($zone['id_zone']);
}
}
/**
* Add the CSS & JavaScript files you want to be loaded in the BO.
*/
public function hookBackOfficeHeader()
{
$this->context->controller->addCSS($this->_path.'views/css/back.css');
}
/**
* Add the CSS & JavaScript files you want to be added on the FO.
*/
public function hookHeader()
{
if (isset($this->context->controller->page_name) && $this->context->controller->page_name == "checkout") {
if (Configuration::get('COLISSIMO_USE_POINTDERETRAIT')) {
$this->context->controller->addJS($this->_path.'views/js/jquery.frameColiposte.js');
$this->context->controller->addJS($this->_path.'views/js/front_delivery_point.js');
} else {
$this->context->controller->addJS($this->_path.'/views/js/front.js');
$this->context->controller->addJqueryPlugin(array(
'fancybox'));
}
} else {
$this->context->controller->addJS($this->_path.'/views/js/redirect.js');
}
$this->context->controller->addCSS($this->_path.'/views/css/front.css');
}
public function hookActionValidateOrder($params)
{
if ($params['order']->id_carrier != Configuration::get('COLISSIMO_CARRIER_ID')) {
return;
}
$order = $params['order'];
if (Configuration::get('COLISSIMO_USE_POINTDERETRAIT')) {
$order->id_address_delivery = $this->isExist(
(int)$order->id_address_delivery,
(int)$order->id_cart,
(int)$order->id_customer
);
} else {
$order->id_address_delivery = $this->isSameAddress((int)$order->id_address_delivery, (int)$order->id_cart, (int)$order->id_customer);
}
$order->update();
Configuration::updateValue('COLISSIMO_CONFIGURATION_OK', true);
if (Module::isEnabled('colissimopass')) {
// is user connect ?
require_once(_PS_MODULE_DIR_.'colissimopass/colissimopass.php');
if (ColissimoPassUser::isActive()) {
Colissimopass::sendConsignment($order);
}
}
}
public function getDeliveryInfosPointderetrait($id_cart, $id_customer)
{
return Db::getInstance()->getRow(
'SELECT * FROM '._DB_PREFIX_.'colissimo_delivery_point
WHERE id_cart = '.(int)$id_cart.' AND id_customer = '.(int)$id_customer
);
}
public function isExist($id_address, $id_cart, $id_customer)
{
$id_socolissimo_deliverypoint_info_exist = ColissimoDeliveryPoint::alreadyExists((int)$id_cart, (int)$id_customer);
$return = Db::getInstance()->getRow(
'SELECT * FROM '._DB_PREFIX_.'colissimo_delivery_point
WHERE id_cart =\''.(int)$id_cart.'\' AND id_customer =\''.(int)$id_customer.'\''
);
if (!$return) {
return $id_address;
}
$socolissimo_deliverypoint_info = new ColissimoDeliveryPoint((int)$id_socolissimo_deliverypoint_info_exist);
$new_address = new Address();
$customer = new Customer($id_customer);
$sql = Db::getInstance()->getRow('SELECT c.id_country, cl.name FROM '._DB_PREFIX_.'country c
LEFT JOIN '._DB_PREFIX_.'country_lang cl ON cl.id_lang = '.(int)$this->context->language->id.'
AND cl.id_country = c.id_country WHERE iso_code = "'.pSQL($socolissimo_deliverypoint_info->codePays).'"');
$iso_code = $sql['id_country'];
$new_address->id_customer = (int)$id_customer;
$new_address->firstname = preg_replace('/\d/', '', Tools::substr($customer->firstname, 0, 32));
$new_address->lastname = preg_replace('/\d/', '', Tools::substr($customer->lastname, 0, 32));
$new_address->postcode = $socolissimo_deliverypoint_info->codePostal;
$new_address->city = str_replace('\'', ' ', $socolissimo_deliverypoint_info->localite);
$new_address->id_country = $iso_code;
$new_address->company = 'Livraison en Point de Retrait';
$new_address->alias = 'Col-Point de retrait-'.date('d-m-Y');