forked from thirtybees/advancedeucompliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
advancedeucompliance.php
1974 lines (1754 loc) · 73.7 KB
/
advancedeucompliance.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-2016 PrestaShop
*
* Thirty Bees is an extension to the PrestaShop e-commerce software developed by PrestaShop SA
* Copyright (C) 2017-2018 thirty bees
*
* 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 Thirty Bees <[email protected]>
* @author PrestaShop SA <[email protected]>
* @copyright 2017-2018 thirty bees
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* PrestaShop is an internationally registered trademark & property of PrestaShop SA
*/
use AdvancedEUComplianceModule\AeucCMSRoleEmailEntity;
use AdvancedEUComplianceModule\AeucEmailEntity;
if (!defined('_TB_VERSION_')) {
exit;
}
require_once __DIR__.'/classes/AeucCMSRoleEmailEntity.php';
require_once __DIR__.'/classes/AeucEmailEntity.php';
/**
* Class Advancedeucompliance
*/
class Advancedeucompliance extends Module
{
const LEGAL_NO_ASSOC = 'NO_ASSOC';
const LEGAL_NOTICE = 'LEGAL_NOTICE';
const LEGAL_CONDITIONS = 'LEGAL_CONDITIONS';
const LEGAL_REVOCATION = 'LEGAL_REVOCATION';
const LEGAL_REVOCATION_FORM = 'LEGAL_REVOCATION_FORM';
const LEGAL_PRIVACY = 'LEGAL_PRIVACY';
const LEGAL_ENVIRONMENTAL = 'LEGAL_ENVIRONMENTAL';
const LEGAL_SHIP_PAY = 'LEGAL_SHIP_PAY';
const DEFAULT_PS_PRODUCT_WEIGHT_PRECISION = 2;
/**
* @var bool
*/
protected $configForm = false;
/**
* @var Core_Foundation_Database_EntityManager
*/
protected $entityManager;
/**
* @var Core_Foundation_FileSystem_FileSystem
*/
protected $filesystem;
/**
* @var Core_Business_Email_EmailLister
*/
protected $emails;
/**
* @var array
*/
protected $errors = [];
/**
* @var array
*/
protected $missingTemplates = [];
/**
* Advancedeucompliance constructor.
*
* @param Core_Foundation_Database_EntityManager $entityManager
* @param Core_Foundation_FileSystem_FileSystem $fs
* @param Core_Business_Email_EmailLister $email
*
* @throws PrestaShopException
*/
public function __construct(
Core_Foundation_Database_EntityManager $entityManager,
Core_Foundation_FileSystem_FileSystem $fs,
Core_Business_Email_EmailLister $email
) {
$this->name = 'advancedeucompliance';
$this->tab = 'administration';
$this->version = '3.2.1';
$this->author = 'thirty bees';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
/* Register dependencies to module */
$this->entityManager = $entityManager;
$this->filesystem = $fs;
$this->emails = $email;
$this->displayName = $this->l('Advanced EU Compliance');
$this->description = $this->l('This module helps European merchants comply with applicable e-commerce laws.');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
}
/**
* Install this module
*
* @return bool Indicates whether this module has been successfully installed
*
* @throws Core_Foundation_FileSystem_Exception
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function install()
{
$return = parent::install() &&
$this->loadTables() &&
$this->installHooks() &&
$this->registerModulesBackwardCompatHook() &&
$this->registerHook('header') &&
$this->registerHook('displayProductPriceBlock') &&
$this->registerHook('overrideTOSDisplay') &&
$this->registerHook('actionEmailAddAfterContent') &&
$this->registerHook('advancedPaymentOptions') &&
$this->registerHook('displayAfterShoppingCartBlock') &&
$this->registerHook('displayBeforeShoppingCartBlock') &&
$this->registerHook('displayCartTotalPriceLabel') &&
$this->createConfig();
$this->emptyTemplatesCache();
return (bool) $return;
}
/**
* Load database tables
*
* @return bool
*
* @throws Core_Foundation_FileSystem_Exception
* @throws PrestaShopException
*/
public function loadTables()
{
$state = true;
// Create module's table
AeucCMSRoleEmailEntity::createDatabase();
AeucEmailEntity::createDatabase();
// Fill in CMS ROLE
$rolesArray = $this->getCMSRoles();
$roles = array_keys($rolesArray);
$cmsRoleRepository = $this->getCMSRoleRepository();
foreach ($roles as $role) {
if (!$cmsRoleRepository->findOneByName($role)) {
/** @var CMSRole $cmsRole */
$cmsRole = $cmsRoleRepository->getNewEntity();
$cmsRole->id_cms = 0; // No assoc at this time
$cmsRole->name = $role;
$state &= (bool) $cmsRole->save();
}
}
$defaultPathEmail = _PS_MAIL_DIR_.'en'.DIRECTORY_SEPARATOR;
// Fill-in aeuc_mail table
foreach ($this->emails->getAvailableMails($defaultPathEmail) as $mail) {
$newEmail = new AeucEmailEntity();
$newEmail->filename = (string) $mail;
$newEmail->display_name = $this->emails->getCleanedMailName($mail);
$newEmail->save();
unset($newEmail);
}
return $state;
}
/**
* Install general hooks
*
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function installHooks()
{
$hooks = [
'displayBeforeShoppingCartBlock' => [
'name' => 'display before Shopping cart block',
'description' => 'Display content after Shopping Cart',
],
'displayAfterShoppingCartBlock' => [
'name' => 'display after Shopping cart block',
'description' => 'Display content after Shopping Cart',
],
'displayPaymentEu' => [
'name' => 'Display EU payment options (helper)',
'description' => 'Hook to display payment options',
],
];
$return = true;
foreach ($hooks as $hookName => $hook) {
if (Hook::getIdByName($hookName)) {
continue;
}
$newHook = new Hook();
$newHook->name = $hookName;
$newHook->title = $hookName;
$newHook->description = $hook['description'];
$newHook->position = true;
$newHook->live_edit = false;
if (!$newHook->add()) {
$return &= false;
$this->errors[] = $this->l('Could not install new hook').': '.$hookName;
}
}
return $return;
}
/**
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function registerModulesBackwardCompatHook()
{
$return = true;
$modulesToCheck = [
'bankwire',
'cheque',
'paypal',
'adyen',
'hipay',
'cashondelivery',
'sofortbanking',
'pigmbhpaymill',
'ogone',
'moneybookers',
'syspay',
'paylikepayment'
];
$displayPaymentEuHookId = (int) Hook::getIdByName('displayPaymentEu');
$alreadyHookedModulesIds = array_keys(Hook::getModulesFromHook($displayPaymentEuHookId));
foreach ($modulesToCheck as $moduleName) {
if (($module = Module::getInstanceByName($moduleName)) !== false &&
Module::isInstalled($moduleName) &&
$module->active &&
!in_array($module->id, $alreadyHookedModulesIds) &&
!$module->isRegisteredInHook('displayPaymentEu')
) {
$return &= $module->registerHook('displayPaymentEu');
}
}
return $return;
}
/**
* Create config
*
* @return bool
*
* @throws PrestaShopException
*/
public function createConfig()
{
$deliveryTimeAvailableValues = [];
$deliveryTimeOosValues = [];
$shoppingCartTextBefore = [];
$shoppingCartTextAfter = [];
$langsRepository = $this->entityManager->getRepository('Language');
$langs = $langsRepository->findAll();
foreach ($langs as $lang) {
$deliveryTimeAvailableValues[(int) $lang->id] = $this->l('Delivery: 1 to 3 weeks');
$deliveryTimeOosValues[(int) $lang->id] = $this->l('Delivery: 3 to 6 weeks');
$shoppingCartTextBefore[(int) $lang->id] = '';
$shoppingCartTextAfter[(int) $lang->id] = '';
}
/* Base settings */
$this->processAeucFeatTellAFriend(true);
$this->processAeucFeatReorder(true);
$this->processAeucFeatAdvPaymentApi(false);
$this->processAeucLabelRevocationTOS(false);
$this->processAeucLabelRevocationVP(false);
$this->processAeucLabelSpecificPrice(true);
$this->processAeucLabelTaxIncExc(true);
$this->processAeucLabelShippingIncExc(false);
$this->processAeucLabelWeight(true);
$this->processAeucLabelCombinationFrom(true);
$isThemeCompliant = $this->isThemeCompliant();
$psWeightPrecisionInstalled = Configuration::get('PS_PRODUCT_WEIGHT_PRECISION') ?
(int) Configuration::get('PS_PRODUCT_WEIGHT_PRECISION') :
Advancedeucompliance::DEFAULT_PS_PRODUCT_WEIGHT_PRECISION;
return Configuration::updateValue('AEUC_FEAT_TELL_A_FRIEND', false) &&
Configuration::updateValue('AEUC_FEAT_ADV_PAYMENT_API', false) &&
Configuration::updateValue('AEUC_LABEL_DELIVERY_TIME_AVAILABLE', $deliveryTimeAvailableValues) &&
Configuration::updateValue('AEUC_LABEL_DELIVERY_TIME_OOS', $deliveryTimeOosValues) &&
Configuration::updateValue('AEUC_LABEL_SPECIFIC_PRICE', true) &&
Configuration::updateValue('AEUC_LABEL_TAX_INC_EXC', true) &&
Configuration::updateValue('AEUC_LABEL_WEIGHT', true) &&
Configuration::updateValue('AEUC_LABEL_REVOCATION_TOS', false) &&
Configuration::updateValue('AEUC_LABEL_REVOCATION_VP', true) &&
Configuration::updateValue('AEUC_LABEL_SHIPPING_INC_EXC', false) &&
Configuration::updateValue('AEUC_LABEL_COMBINATION_FROM', true) &&
Configuration::updateValue('AEUC_SHOPPING_CART_TEXT_BEFORE', $shoppingCartTextBefore) &&
Configuration::updateValue('AEUC_SHOPPING_CART_TEXT_AFTER', $shoppingCartTextAfter) &&
Configuration::updateValue('AEUC_IS_THEME_COMPLIANT', (bool) $isThemeCompliant) &&
Configuration::updateValue('PS_PRODUCT_WEIGHT_PRECISION', (int) $psWeightPrecisionInstalled);
}
/**
* @return bool
*/
public function isThemeCompliant()
{
$return = true;
foreach ($this->getRequiredThemeTemplate() as $requiredTpl) {
if (!is_file(_PS_THEME_DIR_.$requiredTpl)) {
$this->missingTemplates[] = $requiredTpl;
$return = false;
}
}
return $return;
}
/**
* @return array
*/
public function getRequiredThemeTemplate()
{
return [
'order-address-advanced.tpl',
'order-carrier-advanced.tpl',
'order-carrier-opc-advanced.tpl',
'order-opc-advanced.tpl',
'order-opc-new-account-advanced.tpl',
'order-payment-advanced.tpl',
'shopping-cart-advanced.tpl',
];
}
/**
* Uninstall this module
*
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function uninstall()
{
return parent::uninstall() &&
$this->dropConfig() &&
$this->uninstallTables();
}
/**
* Drop config
*
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function dropConfig()
{
// Remove roles
$rolesArray = $this->getCMSRoles();
$roles = array_keys($rolesArray);
$cmsRoleRepository = $this->getCMSRoleRepository();
foreach ($roles as $role) {
$cmsRoleTmp = $cmsRoleRepository->findOneByName($role);
if ($cmsRoleTmp) {
$cmsRoleTmp->delete();
}
}
return Configuration::deleteByName('AEUC_FEAT_TELL_A_FRIEND') &&
Configuration::deleteByName('AEUC_FEAT_ADV_PAYMENT_API') &&
Configuration::deleteByName('AEUC_LABEL_DELIVERY_TIME_AVAILABLE') &&
Configuration::deleteByName('AEUC_LABEL_DELIVERY_TIME_OOS') &&
Configuration::deleteByName('AEUC_LABEL_SPECIFIC_PRICE') &&
Configuration::deleteByName('AEUC_LABEL_TAX_INC_EXC') &&
Configuration::deleteByName('AEUC_LABEL_WEIGHT') &&
Configuration::deleteByName('AEUC_LABEL_REVOCATION_TOS') &&
Configuration::deleteByName('AEUC_LABEL_REVOCATION_VP') &&
Configuration::deleteByName('AEUC_LABEL_SHIPPING_INC_EXC') &&
Configuration::deleteByName('AEUC_LABEL_COMBINATION_FROM') &&
Configuration::deleteByName('AEUC_SHOPPING_CART_TEXT_BEFORE') &&
Configuration::deleteByName('AEUC_SHOPPING_CART_TEXT_AFTER') &&
Configuration::deleteByName('AEUC_IS_THEME_COMPLIANT') &&
Configuration::updateValue('PS_ADVANCED_PAYMENT_API', false) &&
Configuration::updateValue('PS_ATCP_SHIPWRAP', false);
}
/**
* @return bool
*
* @throws PrestaShopException
*/
public function uninstallTables()
{
$state = true;
foreach ([AeucCMSRoleEmailEntity::$definition['table'], AeucEmailEntity::$definition['table']] as $name) {
$state = Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.bqSQL($name).'`') && $state;
}
return $state;
}
/**
* @param bool $forceAll
*
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function disable($forceAll = false)
{
$isAdvancedApiDisabled = (bool) Configuration::updateValue('PS_ADVANCED_PAYMENT_API', false);
$isAdvancedApiDisabled &= (bool) Configuration::updateValue('PS_ATCP_SHIPWRAP', false);
return parent::disable() && $isAdvancedApiDisabled;
}
/**
* @param array $param
*
* @return string
*
* @throws PrestaShopException
* @throws SmartyException
*/
public function hookDisplayCartTotalPriceLabel($param)
{
$smartyVars = [];
if (Configuration::get('AEUC_LABEL_TAX_INC_EXC')) {
$customerDefaultGroupId = (int) $this->context->customer->id_default_group;
$customerDefaultGroup = new Group($customerDefaultGroupId);
if ((bool) Configuration::get('PS_TAX') === true && $this->context->country->display_tax_label &&
!(Validate::isLoadedObject($customerDefaultGroup) && (bool) $customerDefaultGroup->price_display_method === true)
) {
$smartyVars['price']['tax_str_i18n'] = $this->l('Tax included');
} else {
$smartyVars['price']['tax_str_i18n'] = $this->l('Tax excluded');
}
}
if (isset($param['from'])) {
if ($param['from'] == 'shopping_cart') {
$smartyVars['css_class'] = 'aeuc_tax_label_shopping_cart';
}
if ($param['from'] == 'blockcart') {
$smartyVars['css_class'] = 'aeuc_tax_label_blockcart';
}
}
$this->context->smarty->assign(['smartyVars' => $smartyVars]);
return $this->display(__FILE__, 'displayCartTotalPriceLabel.tpl');
}
/**
* @param array $param
*
* @throws PrestaShopException
* @throws SmartyException
* @throws Core_Foundation_Database_Exception
*/
public function hookActionEmailAddAfterContent($param)
{
if (!isset($param['template']) || !isset($param['template_html']) || !isset($param['template_txt'])) {
return;
}
$tplName = (string) $param['template'];
$tplNameExploded = explode('.', $tplName);
if (is_array($tplNameExploded)) {
$tplName = (string) $tplNameExploded[0];
}
$idLang = (int) $param['id_lang'];
$mailId = AeucEmailEntity::getMailIdFromTplFilename($tplName);
if (!$mailId) {
return;
}
$cmsRoleIds = AeucCMSRoleEmailEntity::getCMSRoleIdsFromIdMail($mailId);
if (!$cmsRoleIds) {
return;
}
$tmpCmsRoleList = [];
foreach ($cmsRoleIds as $cmsRoleId) {
$tmpCmsRoleList[] = $cmsRoleId['id_cms_role'];
}
$cmsRoleRepository = $this->getCMSRoleRepository();
$cmsRoles = $cmsRoleRepository->findByIdCmsRole($tmpCmsRoleList);
if (!$cmsRoles) {
return;
}
$cmsRepo = $this->getCMSRepository();
$cmsContents = [];
foreach ($cmsRoles as $cmsRole) {
$cmsPage = $cmsRepo->i10nFindOneById((int) $cmsRole->id_cms, $idLang, $this->context->shop->id);
if (!isset($cmsPage->content)) {
continue;
}
$cmsContents[] = $cmsPage->content;
$param['template_txt'] .= strip_tags($cmsPage->content, true);
}
$this->context->smarty->assign(['cms_contents' => $cmsContents]);
$param['template_html'] .= $this->display(__FILE__, 'hook-email-wrapper.tpl');
}
/**
* @throws PrestaShopException
*/
public function hookHeader()
{
$cssRequired = [
'index',
'product',
'order',
'order-opc',
'category',
'products-comparison',
'manufacturer',
'supplier',
'prices-drop',
'best-sales',
'new-products'
];
$jsRequired = [
'index',
'product',
'category',
'products-comparison'
];
if (isset($this->context->controller->php_self) && in_array($this->context->controller->php_self, $cssRequired)) {
$this->context->controller->addCSS($this->_path.'views/css/aeuc_front.css', 'all');
}
if (isset($this->context->controller->php_self) && in_array($this->context->controller->php_self, $jsRequired)) {
$this->context->controller->addJS($this->_path.'views/js/fo_aeuc_tnc.js', true);
}
if (Configuration::get('AEUC_FEAT_ADV_PAYMENT_API') && isset($this->context->controller->php_self) && $this->context->controller->php_self == 'order') {
$this->context->controller->addJS(_THEME_JS_DIR_.'order-address.js');
}
}
/**
* @return string
*
* @throws Core_Foundation_Database_Exception
* @throws PrestaShopException
* @throws SmartyException
*/
public function hookOverrideTOSDisplay()
{
$hasTosOverrideOpt = (bool) Configuration::get('AEUC_LABEL_REVOCATION_TOS');
$cmsRepository = $this->getCMSRepository();
if (!$cmsRepository instanceof Core_Business_CMS_CMSRepository) {
return '';
}
// Check first if LEGAL_REVOCATION CMS Role is set
$cmsRoleRepository = $this->getCMSRoleRepository();
$cmsPageAssociated = $cmsRoleRepository->findOneByName(Advancedeucompliance::LEGAL_REVOCATION);
// Check if cart has virtual product
$hasVirtualProduct = Configuration::get('AEUC_LABEL_REVOCATION_VP') && $this->hasCartVirtualProduct($this->context->cart);
Media::addJsDef(
[
'aeuc_has_virtual_products' => (bool) $hasVirtualProduct,
'aeuc_virt_prod_err_str' => Tools::htmlentitiesUTF8(
$this->l('Please check "Revocation of virtual products" box first !')
),
]
);
if ($hasTosOverrideOpt || Configuration::get('AEUC_LABEL_REVOCATION_VP')) {
$this->context->controller->addJS($this->_path.'views/js/fo_aeuc_tnc.js', true);
}
$linkRevocations = '';
// Get IDs of CMS pages required
$cmsConditionsId = (int) Configuration::get('PS_CONDITIONS_CMS_ID');
$cmsRevocationId = (int) $cmsPageAssociated->id_cms;
// Get misc vars
$idLang = (int) $this->context->language->id;
$idShop = (int) $this->context->shop->id;
$isSslEnabled = (bool) Configuration::get('PS_SSL_ENABLED');
$checkedTos = (bool)$this->context->cart->checkedTos;
// Get CMS OBJs
$cmsConditions = $cmsRepository->i10nFindOneById($cmsConditionsId, $idLang, $idShop);
if (!Validate::isLoadedObject($cmsConditions)) {
return '';
}
$linkConditions = $this->context->link->getCMSLink($cmsConditions, $cmsConditions->link_rewrite, $isSslEnabled);
if (!strpos($linkConditions, '?')) {
$linkConditions .= '?content_only=1';
} else {
$linkConditions .= '&content_only=1';
}
if ($hasTosOverrideOpt === true) {
$cmsRevocations = $cmsRepository->i10nFindOneById($cmsRevocationId, $idLang, $idShop);
// Get links to revocation page
$linkRevocations = $this->context->link->getCMSLink($cmsRevocations, $cmsRevocations->link_rewrite, $isSslEnabled);
if (!strpos($linkRevocations, '?')) {
$linkRevocations .= '?content_only=1';
} else {
$linkRevocations .= '&content_only=1';
}
}
$this->context->smarty->assign(
[
'has_tos_override_opt' => $hasTosOverrideOpt,
'checkedTOS' => $checkedTos,
'link_conditions' => $linkConditions,
'link_revocations' => $linkRevocations,
'has_virtual_product' => $hasVirtualProduct,
]
);
return $this->display(__FILE__, 'hookOverrideTOSDisplay.tpl');
}
/**
* @return string
*
* @throws PrestaShopException
* @throws SmartyException
*/
public function hookDisplayBeforeShoppingCartBlock()
{
if ($this->context->controller instanceof OrderOpcController || property_exists($this->context->controller, 'step') && $this->context->controller->step == 3) {
$cartText = Configuration::get('AEUC_SHOPPING_CART_TEXT_BEFORE', $this->context->language->id);
if ($cartText) {
$this->context->smarty->assign('cart_text', $cartText);
return $this->display(__FILE__, 'displayShoppingCartBeforeBlock.tpl');
}
}
return '';
}
/**
* @param array $params
*
* @return string
* @throws PrestaShopException
* @throws SmartyException
*/
public function hookDisplayAfterShoppingCartBlock($params)
{
$cartText = Configuration::get('AEUC_SHOPPING_CART_TEXT_AFTER', Context::getContext()->language->id);
if ($cartText && isset($params['colspan_total'])) {
$this->context->smarty->assign(
[
'cart_text' => $cartText,
'colspan_total' => (int) $params['colspan_total'],
]
);
return $this->display(__FILE__, 'displayShoppingCartAfterBlock.tpl');
}
return '';
}
/**
* @param array $param
*
* @return string
*
* @throws Core_Foundation_Database_Exception
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws SmartyException
*/
public function hookDisplayProductPriceBlock($param)
{
if (!isset($param['product']) || !isset($param['type'])) {
return '';
}
$product = $param['product'];
if (is_array($product)) {
$productRepository = $this->entityManager->getRepository('Product');
$product = $productRepository->findOne((int) $product['id_product']);
}
if (!Validate::isLoadedObject($product)) {
return '';
}
$smartyVars = [];
/* Handle Product Combinations label */
if ($param['type'] == 'before_price' && (bool) Configuration::get('AEUC_LABEL_COMBINATION_FROM') === true) {
if ($product->hasAttributes()) {
$needDisplay = false;
$combinations = $product->getAttributeCombinations($this->context->language->id);
if ($combinations && is_array($combinations)) {
foreach ($combinations as $combination) {
if ((float) $combination['price'] > 0) {
$needDisplay = true;
break;
}
}
unset($combinations);
if ($needDisplay) {
$smartyVars['before_price'] = [];
$smartyVars['before_price']['from_str_i18n'] = $this->l('From');
return $this->dumpHookDisplayProductPriceBlock($smartyVars);
}
}
return '';
}
}
/* Handle Specific Price label*/
if ($param['type'] == 'old_price' && (bool) Configuration::get('AEUC_LABEL_SPECIFIC_PRICE') === true) {
$smartyVars['old_price'] = [];
$smartyVars['old_price']['before_str_i18n'] = $this->l('Before');
return $this->dumpHookDisplayProductPriceBlock($smartyVars);
}
/* Handle taxes Inc./Exc. and Shipping Inc./Exc.*/
if ($param['type'] == 'price') {
$smartyVars['price'] = [];
$needShippingLabel = true;
if (Configuration::get('AEUC_LABEL_TAX_INC_EXC')) {
$customerDefaultGroupId = (int) $this->context->customer->id_default_group;
$customerDefaultGroup = new Group($customerDefaultGroupId);
if ((bool) Configuration::get('PS_TAX') === true && $this->context->country->display_tax_label &&
!(Validate::isLoadedObject($customerDefaultGroup) && (bool) $customerDefaultGroup->price_display_method === true)
) {
$smartyVars['price']['tax_str_i18n'] = $this->l('Tax included');
} else {
$smartyVars['price']['tax_str_i18n'] = $this->l('Tax excluded');
}
if (isset($param['from']) && $param['from'] == 'blockcart') {
$smartyVars['price']['css_class'] = 'aeuc_tax_label_blockcart';
$needShippingLabel = false;
}
}
if ((bool) Configuration::get('AEUC_LABEL_SHIPPING_INC_EXC') === true && $needShippingLabel === true) {
if (!$product->is_virtual) {
$cmsRoleRepository = $this->getCMSRoleRepository();
$cmsRepository = $this->getCMSRepository();
$cmsPageAssociated = $cmsRoleRepository->findOneByName(Advancedeucompliance::LEGAL_SHIP_PAY);
if (isset($cmsPageAssociated->id_cms) && $cmsPageAssociated->id_cms != 0) {
$cmsShipPayId = (int) $cmsPageAssociated->id_cms;
$cmsRevocations = $cmsRepository->i10nFindOneById(
$cmsShipPayId,
$this->context->language->id,
$this->context->shop->id
);
$isSslEnabled = (bool) Configuration::get('PS_SSL_ENABLED');
$linkShipPay = $this->context->link->getCMSLink($cmsRevocations, $cmsRevocations->link_rewrite, $isSslEnabled);
if (!strpos($linkShipPay, '?')) {
$linkShipPay .= '?content_only=1';
} else {
$linkShipPay .= '&content_only=1';
}
$smartyVars['ship'] = [];
$smartyVars['ship']['link_ship_pay'] = $linkShipPay;
$smartyVars['ship']['ship_str_i18n'] = $this->l('Shipping excluded');
}
}
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars);
}
/* Handles product's weight */
if ($param['type'] == 'weight' && (bool) Configuration::get('PS_DISPLAY_PRODUCT_WEIGHT') === true &&
isset($param['hook_origin']) && $param['hook_origin'] == 'product_sheet'
) {
if ((float) $product->weight) {
$smartyVars['weight'] = [];
$roundedWeight = round((float) $product->weight, Configuration::get('PS_PRODUCT_WEIGHT_PRECISION'));
$smartyVars['weight']['rounded_weight_str_i18n'] =
$roundedWeight.' '.Configuration::get('PS_WEIGHT_UNIT');
return $this->dumpHookDisplayProductPriceBlock($smartyVars);
}
}
/* Handle Estimated delivery time label */
if ($param['type'] == 'after_price' && !$product->is_virtual) {
$contextIdLang = $this->context->language->id;
$isProductAvailable = StockAvailable::getQuantityAvailableByProduct($product->id) >= 1;
$smartyVars['after_price'] = [];
if ($isProductAvailable) {
$contextualizedContent =
Configuration::get('AEUC_LABEL_DELIVERY_TIME_AVAILABLE', (int) $contextIdLang);
$smartyVars['after_price']['delivery_str_i18n'] = $contextualizedContent;
} else {
$contextualizedContent = Configuration::get('AEUC_LABEL_DELIVERY_TIME_OOS', (int) $contextIdLang);
$smartyVars['after_price']['delivery_str_i18n'] = $contextualizedContent;
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars);
}
return '';
}
/**
* Load the configuration form
*
* @return string
*
* @throws Core_Foundation_Database_Exception
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws SmartyException
*/
public function getContent()
{
$themeWarning = null;
$this->refreshThemeStatus();
$successBand = $this->_postProcess();
if ((bool) Configuration::get('AEUC_IS_THEME_COMPLIANT') === false) {
$missing = '<ul>';
foreach ($this->missingTemplates as $missingTpl) {
$missing .= '<li>'.$missingTpl.' '.$this->l('missing').'</li>';
}
$missing .= '</ul><br/>';
$discardWarningLink = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&discard_tpl_warn=1'.'&token='.Tools::getAdminTokenLite('AdminModules');
$missing .= '<a href="'.$discardWarningLink.'" type="button">'.$this->l('Hide this, I know what I am doing.').'</a>';
$themeWarning = $this->displayWarning($this->l('It seems that your current theme is not compatible with this module, some mandatory templates are missing. It is possible some options may not work as expected.').$missing);
}
$this->context->smarty->assign('module_dir', $this->_path);
$this->context->smarty->assign('errors', $this->errors);
$this->context->controller->addCSS($this->_path.'views/css/configure.css', 'all');
// Render all required form for each 'part'
$formLabelsManager = $this->renderFormLabelsManager();
$formFeaturesManager = $this->renderFormFeaturesManager();
$formLegalContentManager = $this->renderFormLegalContentManager();
$formEmailAttachmentsManager = $this->renderFormEmailAttachmentsManager();
return $themeWarning.$successBand.$formLabelsManager.$formFeaturesManager.$formLegalContentManager.$formEmailAttachmentsManager;
}
/**
* @return array|null
*
* @throws PrestaShopException
*/
public function hookAdvancedPaymentOptions()
{
$legacyOptions = Hook::exec('displayPaymentEU', [], null, true);
$newOptions = [];
Media::addJsDef(
[
'aeuc_tos_err_str' => Tools::htmlentitiesUTF8($this->l('You must agree to our Terms of Service before going any further!')),
]
);
Media::addJsDef(
[
'aeuc_submit_err_str' => Tools::htmlentitiesUTF8($this->l('Something went wrong. If the problem persists, please contact us.')),
]
);
Media::addJsDef(
[
'aeuc_no_pay_err_str' => Tools::htmlentitiesUTF8($this->l('Select a payment option first.')),
]
);
Media::addJsDef(
[
'aeuc_virt_prod_err_str' => Tools::htmlentitiesUTF8($this->l('Please check "Revocation of virtual products" box first !')),
]
);
if ($legacyOptions) {
foreach ($legacyOptions as $moduleName => $legacyOption) {
if (!$legacyOption) {
continue;
}
foreach (Core_Business_Payment_PaymentOption::convertLegacyOption($legacyOption) as $option) {
/** @var Core_Business_Payment_PaymentOption $option */
$option->setModuleName($moduleName);
$toBeCleaned = $option->getForm();
if ($toBeCleaned) {
$cleaned = str_replace('@hiddenSubmit', '', $toBeCleaned);
$option->setForm($cleaned);
}
$newOptions[] = $option;
}
}
return $newOptions;
}
return null;
}
/**
* @param Cart $cart
*
* @return bool
*
* @throws PrestaShopException
*/
protected function hasCartVirtualProduct(Cart $cart)
{
$products = $cart->getProducts();
if (!count($products)) {
return false;
}
foreach ($products as $product) {
if ($product['is_virtual']) {
return true;
}
}
return false;
}
/**
* @param bool $isOptionActive
*
* @throws PrestaShopException
*/
protected function processAeucLabelRevocationTOS($isOptionActive)