-
Notifications
You must be signed in to change notification settings - Fork 4
/
everpsquotation.php
1227 lines (1157 loc) · 46.2 KB
/
everpsquotation.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
/**
* 2019-2024 Team Ever
*
* 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.
*
* @author Team Ever <https://www.team-ever.com/>
* @copyright 2019-2023 Team Ever
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once _PS_MODULE_DIR_.'everpsquotation/models/EverpsquotationCart.php';
require_once _PS_MODULE_DIR_.'everpsquotation/models/EverpsquotationCartProduct.php';
require_once _PS_MODULE_DIR_.'everpsquotation/models/EverpsquotationClass.php';
require_once _PS_MODULE_DIR_.'everpsquotation/models/EverpsquotationDetail.php';
require_once _PS_MODULE_DIR_.'everpsquotation/models/HTMLTemplateEverQuotationPdf.php';
class Everpsquotation extends PaymentModule
{
private $html;
private $postErrors = [];
private $postSuccess = [];
/**
* Constructor
*/
public function __construct()
{
$this->name = 'everpsquotation';
$this->tab = 'payments_gateways';
$this->version = '5.1.1';
$this->author = 'Team Ever';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Ever PS Quotation');
$this->description = $this->l('Simply accept quotations on your Prestashop !');
$this->confirmUninstall = $this->l('Do you REALLY want to uninstall this awesome module ?');
$this->ps_versions_compliancy = ['min' => '1.7', 'max' => _PS_VERSION_];
}
/**
* The install method
*
* @see prestashop/classes/Module#install()
*/
public function install()
{
Configuration::updateValue(
'EVERPSQUOTATION_LOGO_WIDTH',
180
);
// Install SQL
$sql = [];
include(dirname(__FILE__).'/sql/install.php');
foreach ($sql as $s) {
if (!Db::getInstance()->execute($s)) {
return false;
}
}
$this->createQuoteHooks();
return (parent::install()
&& $this->checkHooks()
&& $this->installModuleTab('AdminEverPsQuotation'));
}
public function checkHooks()
{
return ($this->registerHook('header')
&& $this->registerHook('displayAfterProductActions')
&& $this->registerHook('displayCustomerAccount')
&& $this->registerHook('displayShoppingCart')
&& $this->registerHook('displayReassurance')
&& $this->registerHook('paymentOptions')
&& $this->registerHook('displayAdminEndContent')
&& $this->registerHook('displayCartModalFooter'));
}
public function createQuoteHooks()
{
$result = true;
// Hook before quote creation
if (!Hook::getIdByName('actionBeforeCreateEverQuote')) {
$hook = new Hook();
$hook->name = 'actionBeforeCreateEverQuote';
$hook->title = 'Before quotation creation';
$hook->description = 'This hook is triggered before quote is created';
$result &= $hook->save();
}
// Hook after quote creation
if (!Hook::getIdByName('actionAfterCreateEverQuote')) {
$hook = new Hook();
$hook->name = 'actionAfterCreateEverQuote';
$hook->title = 'After quotation creation';
$hook->description = 'This hook is triggered after quote is created';
$result &= $hook->save();
}
return $result;
}
public function deleteQuoteHooks()
{
$result = true;
// Hook before quote creation
$actionBeforeCreateEverQuote = Hook::getIdByName('actionBeforeCreateEverQuote');
if ($actionBeforeCreateEverQuote) {
$hook = new Hook(
(int)$actionBeforeCreateEverQuote
);
$result &= $hook->delete();
}
// Hook after quote creation
$actionAfterCreateEverQuote = Hook::getIdByName('actionAfterCreateEverQuote');
if ($actionAfterCreateEverQuote) {
$hook = new Hook(
(int)$actionAfterCreateEverQuote
);
$result &= $hook->delete();
}
return $result;
}
/**
* The uninstall method
*
* @see prestashop/classes/Module#uninstall()
*/
public function uninstall()
{
if ((bool) Configuration::get('EVERPSQUOTATION_DROP_SQL') === true) {
// Uninstall SQL
$sql = [];
include(dirname(__FILE__).'/sql/uninstall.php');
foreach ($sql as $s) {
if (!Db::getInstance()->execute($s)) {
return false;
}
}
}
$this->deleteQuoteHooks();
Db::getInstance()->delete(
'hook_module',
'id_module = ' . (int) $this->id
);
return (parent::uninstall()
&& Configuration::deleteByName('EVERPSQUOTATION_ACCOUNT_EMAIL')
&& Configuration::deleteByName('EVERPSQUOTATION_LOGO_WIDTH')
&& Configuration::deleteByName('EVERPSQUOTATION_PREFIX')
&& Configuration::deleteByName('EVERPSQUOTATION_TEXT')
&& Configuration::deleteByName('EVERPSQUOTATION_MAIL_SUBJECT')
&& $this->uninstallModuleTab('AdminEverPsQuotation'));
}
/**
* The installModuleTab method
*
* @param string $tabClass
* @param string $tabName
* @param integer $idTabParent
* @return boolean
*/
private function installModuleTab($tabClass)
{
$tab = new Tab();
$tab->active = 1;
$tab->class_name = $tabClass;
$tab->id_parent = (int) Tab::getIdFromClassName('AdminParentOrders');
$tab->position = Tab::getNewLastPosition($tab->id_parent);
foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = 'Devis';
}
$tab->module = $this->name;
return $tab->add();
}
/**
* The uninstallModuleTab method
*
* @param string $tabClass
* @return boolean
*/
private function uninstallModuleTab($tabClass)
{
$tab = new Tab((int) Tab::getIdFromClassName($tabClass));
return $tab->delete();
}
/**
* Load the configuration form
*/
public function getContent()
{
if (Tools::isSubmit('submitEverpsquotationModule')) {
$this->postValidation();
if (!count($this->postErrors)) {
$this->postProcess();
}
}
// Display errors
if (count($this->postErrors)) {
foreach ($this->postErrors as $error) {
$this->html .= $this->displayError($error);
}
}
// Display confirmations
if (count($this->postSuccess)) {
foreach ($this->postSuccess as $success) {
$this->html .= $this->displayConfirmation($success);
}
}
/**
* Mod rewrite must be set to allows quotations
*/
if (!Configuration::get('PS_REWRITING_SETTINGS')) {
$rewriteMode = true;
} else {
$rewriteMode = false;
}
$quote_controller_link = 'index.php?controller=AdminEverPsQuotation&token=';
$quote_controller_link .= Tools::getAdminTokenLite('AdminEverPsQuotation');
$this->context->smarty->assign([
'quote_controller_link' => $quote_controller_link,
'everpsquotation_dir' => $this->_path,
'rewrite_mode' => $rewriteMode,
]);
if ($this->checkLatestEverModuleVersion()) {
$this->html .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/upgrade.tpl');
}
$this->html .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/header.tpl');
$this->html .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
$this->html .= $this->renderForm();
$this->html .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/footer.tpl');
return $this->html;
}
/**
* Create the form that will be displayed in the configuration of your module.
*/
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 = 'submitEverpsquotationModule';
$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 = [
'fields_value' => $this->getConfigFormValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
];
return $helper->generateForm([$this->getConfigForm()]);
}
/**
* Create the structure of your form.
*/
protected function getConfigForm()
{
$selectedCategories = Configuration::get(
'EVERPSQUOTATION_CATEGORIES'
);
if (!$selectedCategories) {
$selectedCategories = [];
} else {
$selectedCategories = json_decode($selectedCategories);
}
$tree = [
'selected_categories' => $selectedCategories,
'use_search' => true,
'use_checkbox' => true,
'id' => 'id_category_tree',
];
if (file_exists(_PS_MODULE_DIR_.'everpsquotation/views/img/quotation.jpg')) {
$defaultUrlImage = $this->_path . '/views/img/quotation.jpg';
} else {
$defaultUrlImage = Tools::getHttpHost(true) . __PS_BASE_URI__ . 'img/' . Configuration::get(
'PS_LOGO'
);
}
$defaultImage = '<img src="' . $defaultUrlImage . '" style="max-width:150px;"/>';
return [
'form' => [
'legend' => [
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'switch',
'label' => $this->l('Drop all quotations on module uninstall ?'),
'desc' => $this->l('Will delete all quotations on module uninstall'),
'hint' => $this->l('Else all quotations will be keeped on module uninstall'),
'name' => 'EVERPSQUOTATION_DROP_SQL',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'select',
'label' => $this->l('Allowed customer groups'),
'desc' => $this->l('Choose allowed groups, customers must be logged'),
'hint' => $this->l('Customers must be logged and have a registered address'),
'name' => 'EVERPSQUOTATION_GROUPS[]',
'class' => 'chosen',
'identifier' => 'name',
'multiple' => true,
'options' => [
'query' => Group::getGroups(
(int) $this->context->language->id,
(int) $this->context->shop->id
),
'id' => 'id_group',
'name' => 'name',
],
],
[
'col' => 3,
'type' => 'text',
'lang' => false,
'label' => $this->l('Quotation duration'),
'desc' => $this->l('Duration in days of validity of the estimate'),
'hint' => $this->l('Will display a quote expiration date (leave empty for no use)'),
'name' => 'EVERPSQUOTATION_DURATION',
],
[
'col' => 3,
'type' => 'text',
'label' => $this->l('Quotation minimum amount'),
'desc' => $this->l('Minimum amount without taxes to allow quotations'),
'hint' => $this->l('Leave empty for no use'),
'name' => 'EVERPSQUOTATION_MIN_AMOUNT',
],
[
'type' => 'switch',
'label' => $this->l('Enable quotes creation on product pages'),
'desc' => $this->l('Will show a "download quotation" on product page'),
'hint' => $this->l('Will show a button next to "Add to cart".'),
'name' => 'EVERPSQUOTATION_PRODUCT',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'file',
'label' => $this->l('Quotation logo'),
'desc' => $this->l('Quotation logo on PDF files'),
'hint' => $this->l('Default will be shop logo'),
'name' => 'image',
'display_image' => true,
'image' => $defaultImage,
'desc' => sprintf($this->l('
maximum image size: %s.'), ini_get('upload_max_filesize')),
],
[
'col' => 3,
'type' => 'text',
'label' => $this->l('Logo width'),
'desc' => $this->l('Logo width (pixel value) on quotes'),
'hint' => $this->l('Will define your logo width on quotes'),
'name' => 'EVERPSQUOTATION_LOGO_WIDTH',
'required' => true,
],
[
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'label' => $this->l('Email'),
'desc' => $this->l('Admin email for quotation mails copy'),
'hint' => $this->l('Leave empty for no use'),
'name' => 'EVERPSQUOTATION_ACCOUNT_EMAIL',
],
[
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-download"></i>',
'label' => $this->l('Quotation prefix'),
'desc' => $this->l('Please specify quotation prefix'),
'hint' => $this->l('Every quote will start with this prefix'),
'name' => 'EVERPSQUOTATION_PREFIX',
],
[
'col' => 3,
'type' => 'text',
'lang' => true,
'label' => $this->l('Quotation mail subject'),
'desc' => $this->l('Please specify subject of mails send'),
'hint' => $this->l('Quotations will be sent by email using tihs subject'),
'name' => 'EVERPSQUOTATION_MAIL_SUBJECT',
],
[
'type' => 'textarea',
'lang' => true,
'label' => $this->l('File name for quotations'),
'desc' => $this->l('PDF filename'),
'hint' => $this->l('Every quote file will have this name. Required.'),
'name' => 'EVERPSQUOTATION_FILENAME',
'required' => true,
],
[
'type' => 'textarea',
'autoload_rte' => true,
'lang' => true,
'label' => $this->l('Quotation specific mentions'),
'desc' => $this->l('These mentions will be displayed at the bottom of the estimate, after the list of products and the totals'),
'hint' => $this->l('You can specify for example your bank details as well as the mention of good for agreement'),
'name' => 'EVERPSQUOTATION_MENTIONS',
],
[
'type' => 'textarea',
'autoload_rte' => true,
'lang' => true,
'label' => $this->l('Quotation text on footer'),
'desc' => $this->l('Please specify quotation text on footer'),
'hint' => $this->l('Add more informations, like SIRET, APE...'),
'name' => 'EVERPSQUOTATION_TEXT',
],
[
'type' => 'switch',
'label' => $this->l('Render PDF on validation page ?'),
'desc' => $this->l('Will download PDF on validation page without redirection'),
'hint' => $this->l('Else PDF will be sent by email only, validation page will be shown'),
'name' => 'EVERPSQUOTATION_RENDER_ON_VALIDATION',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'switch',
'label' => $this->l('Suggest unlogged users to log in ?'),
'desc' => $this->l('Suggests people who are not logged in to log in or create an account'),
'hint' => $this->l('Else a custom modal will be shown'),
'name' => 'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => true,
'label' => $this->l('Yes'),
],
[
'id' => 'active_off',
'value' => false,
'label' => $this->l('No'),
],
],
],
[
'type' => 'categories',
'name' => 'EVERPSQUOTATION_CATEGORIES',
'label' => $this->l('Category'),
'desc' => $this->l('Allow only these categories on quotations'),
'hint' => $this->l('Only products in selected categories will be allowed for quotes'),
'required' => true,
'tree' => $tree,
],
],
'submit' => [
'title' => $this->l('Save'),
],
],
];
}
private function postValidation()
{
if (Tools::isSubmit('submitEverpsquotationModule')) {
if (Tools::getValue('EVERPSQUOTATION_DROP_SQL')
&& !Validate::isBool(Tools::getValue('EVERPSQUOTATION_DROP_SQL'))
) {
$this->postErrors[] = $this->l('Error: drop quotations on uninstall is not valid');
}
if (!Tools::getValue('EVERPSQUOTATION_LOGO_WIDTH')
|| !Validate::isInt(Tools::getValue('EVERPSQUOTATION_LOGO_WIDTH'))
) {
$this->postErrors[] = $this->l('Error: logo width is not valid');
}
if (!Tools::getIsset('EVERPSQUOTATION_ACCOUNT_EMAIL')
|| !Validate::isEmail(Tools::getValue('EVERPSQUOTATION_ACCOUNT_EMAIL'))
) {
$this->postErrors[] = $this->l('Error: email is not valid');
}
if (!Tools::getIsset('EVERPSQUOTATION_CATEGORIES')
|| !Validate::isArrayWithIds(Tools::getValue('EVERPSQUOTATION_CATEGORIES'))
) {
$this->postErrors[] = $this->l('Error: allowed categories is not valid');
}
if (!Tools::getIsset('EVERPSQUOTATION_GROUPS')
|| !Validate::isArrayWithIds(Tools::getValue('EVERPSQUOTATION_GROUPS'))
) {
$this->postErrors[] = $this->l('Error: allowed groups is not valid');
}
if (!Tools::getIsset('EVERPSQUOTATION_PREFIX')
|| !Validate::isGenericName(Tools::getValue('EVERPSQUOTATION_PREFIX'))
) {
$this->postErrors[] = $this->l('Error: allowed groups is not valid');
}
if (Tools::getValue('EVERPSQUOTATION_MIN_AMOUNT')
&& !Validate::isPrice(Tools::getValue('EVERPSQUOTATION_MIN_AMOUNT'))
) {
$this->postErrors[] = $this->l('Error: minimum amount is not valid');
}
if (Tools::getValue('EVERPSQUOTATION_PRODUCT')
&& !Validate::isBool(Tools::getValue('EVERPSQUOTATION_PRODUCT'))
) {
$this->postErrors[] = $this->l('Error: allow on product page is not valid');
}
if (Tools::getValue('EVERPSQUOTATION_RENDER_ON_VALIDATION')
&& !Validate::isBool(Tools::getValue('EVERPSQUOTATION_RENDER_ON_VALIDATION'))
) {
$this->postErrors[] = $this->l('Error: render PDF on validation is not valid');
}
if (Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED')
&& !Validate::isBool(Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED'))
) {
$this->postErrors[] = $this->l('Error: render PDF on validation is not valid');
}
// Multilingual validation
foreach (Language::getLanguages(false) as $lang) {
if (!Tools::getIsset('EVERPSQUOTATION_TEXT_'.$lang['id_lang'])
|| !Validate::isCleanHtml(Tools::getValue('EVERPSQUOTATION_TEXT_'.$lang['id_lang']))
) {
$this->postErrors[] = $this->l(
'Error: text on footer is not valid for lang '
).$lang['iso_code'];
}
if (!Tools::getIsset('EVERPSQUOTATION_MENTIONS_'.$lang['id_lang'])
|| !Validate::isCleanHtml(Tools::getValue('EVERPSQUOTATION_MENTIONS_'.$lang['id_lang']))
) {
$this->postErrors[] = $this->l(
'Error: Mentions is not valid for lang '
).$lang['iso_code'];
}
if (!Tools::getIsset('EVERPSQUOTATION_MAIL_SUBJECT_'.$lang['id_lang'])
|| !Validate::isMailSubject(Tools::getValue('EVERPSQUOTATION_MAIL_SUBJECT_'.$lang['id_lang']))
) {
$this->postErrors[] = $this->l(
'Error: mail subject is not valid for lang '
).$lang['iso_code'];
}
if (Tools::getIsset('EVERPSQUOTATION_FILENAME_'.$lang['id_lang'])
&& !Validate::isGenericName(Tools::getValue('EVERPSQUOTATION_FILENAME_'.$lang['id_lang']))
) {
$this->postErrors[] = $this->l(
'Error: filename is not valid for lang '
).$lang['iso_code'];
}
}
}
}
/**
* Save form data.
*/
protected function postProcess()
{
$everpsquotation_subject = [];
$everpsquotation_filename = [];
$everpsquotation_text = [];
foreach (Language::getLanguages(false) as $lang) {
$everpsquotation_subject[$lang['id_lang']] = (
Tools::getValue('EVERPSQUOTATION_MAIL_SUBJECT_'
.$lang['id_lang'])
) ? Tools::getValue(
'EVERPSQUOTATION_MAIL_SUBJECT_'
.$lang['id_lang']
) : '';
$everpsquotation_filename[$lang['id_lang']] = (
Tools::getValue('EVERPSQUOTATION_FILENAME_'
.$lang['id_lang'])
) ? Tools::getValue(
'EVERPSQUOTATION_FILENAME_'
.$lang['id_lang']
) : '';
$everpsquotation_text[$lang['id_lang']] = (
Tools::getValue('EVERPSQUOTATION_TEXT_'
.$lang['id_lang'])
) ? Tools::getValue(
'EVERPSQUOTATION_TEXT_'
.$lang['id_lang']
) : '';
$everpsquotation_mentions[$lang['id_lang']] = (
Tools::getValue('EVERPSQUOTATION_MENTIONS_'
.$lang['id_lang'])
) ? Tools::getValue(
'EVERPSQUOTATION_MENTIONS_'
.$lang['id_lang']
) : '';
}
Configuration::updateValue(
'EVERPSQUOTATION_DROP_SQL',
Tools::getValue('EVERPSQUOTATION_DROP_SQL')
);
Configuration::updateValue(
'EVERPSQUOTATION_DURATION',
Tools::getValue('EVERPSQUOTATION_DURATION')
);
Configuration::updateValue(
'EVERPSQUOTATION_LOGO_WIDTH',
Tools::getValue('EVERPSQUOTATION_LOGO_WIDTH')
);
Configuration::updateValue(
'EVERPSQUOTATION_CATEGORIES',
json_encode(Tools::getValue('EVERPSQUOTATION_CATEGORIES')),
true
);
Configuration::updateValue(
'EVERPSQUOTATION_GROUPS',
json_encode(Tools::getValue('EVERPSQUOTATION_GROUPS')),
true
);
Configuration::updateValue(
'EVERPSQUOTATION_MIN_AMOUNT',
Tools::getValue('EVERPSQUOTATION_MIN_AMOUNT')
);
Configuration::updateValue(
'EVERPSQUOTATION_PRODUCT',
Tools::getValue('EVERPSQUOTATION_PRODUCT')
);
Configuration::updateValue(
'EVERPSQUOTATION_ACCOUNT_EMAIL',
Tools::getValue('EVERPSQUOTATION_ACCOUNT_EMAIL')
);
Configuration::updateValue(
'EVERPSQUOTATION_PREFIX',
Tools::getValue('EVERPSQUOTATION_PREFIX')
);
Configuration::updateValue(
'EVERPSQUOTATION_MAIL_SUBJECT',
$everpsquotation_subject,
true
);
Configuration::updateValue(
'EVERPSQUOTATION_FILENAME',
$everpsquotation_filename,
true
);
Configuration::updateValue(
'EVERPSQUOTATION_TEXT',
$everpsquotation_text,
true
);
Configuration::updateValue(
'EVERPSQUOTATION_MENTIONS',
$everpsquotation_mentions,
true
);
Configuration::updateValue(
'EVERPSQUOTATION_RENDER_ON_VALIDATION',
Tools::getValue('EVERPSQUOTATION_RENDER_ON_VALIDATION')
);
Configuration::updateValue(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
Tools::getValue('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED')
);
/* Uploads image */
$type = Tools::strtolower(Tools::substr(strrchr($_FILES['image']['name'], '.'), 1));
$imagesize = @getimagesize($_FILES['image']['tmp_name']);
if (isset($_FILES['image']) &&
isset($_FILES['image']['tmp_name']) &&
!empty($_FILES['image']['tmp_name']) &&
!empty($imagesize) &&
in_array(
Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)),
[
'jpg',
'gif',
'jpeg',
'png',
]
) &&
in_array($type, ['jpg', 'gif', 'jpeg', 'png'])
) {
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if ($error = ImageManager::validateUpload($_FILES['image'])) {
$this->postErrors[] = $error;
} elseif (!$temp_name
|| !move_uploaded_file($_FILES['image']['tmp_name'], $temp_name)
) {
$this->postErrors[] = $this->l('An error occurred during the image upload process.');
} elseif (!ImageManager::resize(
$temp_name,
dirname(__FILE__).'/views/img/quotation.jpg',
null,
null,
$type
)) {
$this->postErrors[] = $this->l('An error occurred during the image upload process.');
}
if (isset($temp_name)) {
@unlink($temp_name);
}
}
$this->postSuccess[] = $this->l('All settings have been saved :-)');
}
/**
* Set values for the inputs.
*/
protected function getConfigFormValues()
{
return [
'EVERPSQUOTATION_CATEGORIES' => Tools::getValue(
'EVERPSQUOTATION_CATEGORIES',
json_decode(
Configuration::get(
'EVERPSQUOTATION_CATEGORIES'
)
)
),
'EVERPSQUOTATION_GROUPS[]' => Tools::getValue(
'EVERPSQUOTATION_GROUPS',
json_decode(
Configuration::get(
'EVERPSQUOTATION_GROUPS',
(int)$this->context->language->id
)
)
),
'EVERPSQUOTATION_MIN_AMOUNT' => Tools::getValue(
'EVERPSQUOTATION_MIN_AMOUNT',
Configuration::get(
'EVERPSQUOTATION_MIN_AMOUNT',
(int)$this->context->language->id
)
),
'EVERPSQUOTATION_PRODUCT' => Tools::getValue(
'EVERPSQUOTATION_PRODUCT',
Configuration::get(
'EVERPSQUOTATION_PRODUCT',
(int)$this->context->language->id
)
),
'EVERPSQUOTATION_DROP_SQL' => Tools::getValue(
'EVERPSQUOTATION_DROP_SQL',
Configuration::get(
'EVERPSQUOTATION_DROP_SQL'
)
),
'EVERPSQUOTATION_LOGO_WIDTH' => Tools::getValue(
'EVERPSQUOTATION_LOGO_WIDTH',
Configuration::get(
'EVERPSQUOTATION_LOGO_WIDTH'
)
),
'EVERPSQUOTATION_ACCOUNT_EMAIL' => Tools::getValue(
'EVERPSQUOTATION_ACCOUNT_EMAIL',
Configuration::get(
'EVERPSQUOTATION_ACCOUNT_EMAIL'
)
),
'EVERPSQUOTATION_PREFIX' => Tools::getValue(
'EVERPSQUOTATION_PREFIX',
Configuration::get(
'EVERPSQUOTATION_PREFIX'
)
),
'EVERPSQUOTATION_RENDER_ON_VALIDATION' => Tools::getValue(
'EVERPSQUOTATION_RENDER_ON_VALIDATION',
Configuration::get(
'EVERPSQUOTATION_RENDER_ON_VALIDATION'
)
),
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED' => Tools::getValue(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED',
Configuration::get(
'EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED'
)
),
'EVERPSQUOTATION_MAIL_SUBJECT' => self::getConfigInMultipleLangs(
'EVERPSQUOTATION_MAIL_SUBJECT'
),
'EVERPSQUOTATION_FILENAME' => self::getConfigInMultipleLangs(
'EVERPSQUOTATION_FILENAME'
),
'EVERPSQUOTATION_TEXT' => self::getConfigInMultipleLangs(
'EVERPSQUOTATION_TEXT'
),
'EVERPSQUOTATION_MENTIONS' => self::getConfigInMultipleLangs(
'EVERPSQUOTATION_MENTIONS'
),
'EVERPSQUOTATION_DURATION' => Configuration::get(
'EVERPSQUOTATION_DURATION'
),
];
}
/**
* Hook payment, PS 1.7 only.
*/
public function hookPaymentOptions($params)
{
if (!$this->active) {
return;
}
$cart = $this->context->cart;
$total_cart = $this->context->cart->getOrderTotal(
false,
Cart::BOTH_WITHOUT_SHIPPING,
null,
null,
true
);
if ((float)Configuration::get('EVERPSQUOTATION_MIN_AMOUNT') > 0
&& $total_cart < Configuration::get('EVERPSQUOTATION_MIN_AMOUNT')) {
return;
}
$cartproducts = $cart->getProducts();
$customerGroups = Customer::getGroupsStatic((int)$cart->id_customer);
$selected_cat = $this->getAllowedCategories();
$allowed_groups = $this->getAllowedGroups();
foreach ($cartproducts as $cartproduct) {
$product = new Product((int)$cartproduct['id_product']);
if (!in_array($product->id_category_default, $selected_cat)) {
return;
}
if ($product->visibility == 'none'
|| (bool)$product->available_for_order === false
|| (bool)$product->show_price === false
) {
return;
}
}
if (!array_intersect($allowed_groups, $customerGroups)
|| empty($allowed_groups)
) {
return;
}
$newOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption;
$newOption->setModuleName($this->name)
->setCallToActionText($this->l('Request for a quote'))
->setAction($this->context->link->getModuleLink($this->name, 'validation', [], true))
->setAdditionalInformation(
$this->fetch('module:everpsquotation/views/templates/front/payment_infos.tpl')
);
return [$newOption];
}
public function hookHeader($params)
{
$controller_name = Tools::getValue('controller');
$token = Tools::encrypt(
$this->name . '_token/setquote'
);
$quoteAjaxLink = $this->context->link->getModuleLink(
$this->name,
'quote',
[
'action' => 'SetQuote',
'token' => $token,
]
);
$quoteRequestAjaxLink = $this->context->link->getModuleLink(
$this->name,
'mail',
[
'action' => 'SetRequest',
'token' => $token,
]
);
if (!$this->context->customer->isLogged()) {
$this->context->controller->registerJavascript(
'module-modal-' . $this->name,
'modules/' . $this->name . '/views/js/modal.js',
[
'attributes' => 'defer'
]
);
} else {
$this->context->controller->registerJavascript(
'module-' . $this->name,
'modules/' . $this->name . '/views/js/' . $this->name . '.js',
[
'attributes' => 'defer'
]
);
}
Media::addJsDef([
$this->name . '_quote_link ' => $quoteAjaxLink,
$this->name . '_quoterequest_link ' => $quoteRequestAjaxLink,
]);
if ($controller_name == 'product') {
$this->context->controller->addJs($this->_path.'views/js/createProductQuote.js');
$this->context->controller->addCss($this->_path.'views/css/everpsquotation.css');
}
}
public function hookDisplayAdminEndContent($params)
{
$controller_name = Tools::getValue('controller');
if ($controller_name == 'AdminCarts')
{
$token = Tools::getAdminToken('AdminEverPsQuotation'.(int)Tab::getIdFromClassName('AdminEverPsQuotation').(int)Context::getContext()->employee->id);
$id_cart = Tools::getValue('id_cart');
$cart = new Cart(
(int) $id_cart
);
$cartproducts = $cart->getProducts();
if (count($cartproducts) <= 0) {
return;
}
$href = 'index.php?controller=AdminEverPsQuotation&transformThisCartId=' . $id_cart . '&token=' . $token;
return '<a class="btn btn-default" href="' . $href . '"><i class="icon-shopping-cart"></i> ' . $this->l('Create a quotation from this cart') . '</a>';
}
}
public function hookDisplayShoppingCartFooter()
{
$suggestLogIn = Configuration::get('EVERPSQUOTATION_SUGGEST_CONNECT_UNLOGGED');
if ((bool) $suggestLogIn === true && !$this->context->customer->isLogged()) {
return;
}
return $this->display(__FILE__, 'views/templates/hook/form.tpl');
}
public function hookDisplayCartModalFooter()
{
return $this->hookDisplayShoppingCart();
}
public function hookDisplayLeftColumn()