This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathps_legalcompliance.php
1693 lines (1477 loc) · 83.2 KB
/
ps_legalcompliance.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-2017 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}
/* Namespaces used in this module */
use PrestaShop\PrestaShop\Core\Foundation\Database\EntityManager;
use PrestaShop\PrestaShop\Core\Foundation\Filesystem\FileSystem;
use PrestaShop\PrestaShop\Core\Email\EmailLister;
use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions;
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
/* Include required entities */
include_once __DIR__.'/entities/AeucCMSRoleEmailEntity.php';
include_once __DIR__.'/entities/AeucEmailEntity.php';
class Ps_LegalCompliance extends Module
{
/* Class members */
protected $config_form = false;
protected $entity_manager;
protected $filesystem;
protected $emails;
protected $_errors = array();
protected $_warnings = array();
/* Constants used for LEGAL/CMS Management */
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';
public function __construct(EntityManager $entity_manager,
FileSystem $fs,
EmailLister $email)
{
$this->name = 'ps_legalcompliance';
$this->tab = 'administration';
$this->version = '3.0.2';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
/* Register dependencies to module */
$this->entity_manager = $entity_manager;
$this->filesystem = $fs;
$this->emails = $email;
$this->displayName = $this->trans('Legal Compliance', array(), 'Modules.Legalcompliance.Admin');
$this->description = $this->trans('Keep on growing your business serenely, sell all over Europe while complying with the applicable e-commerce laws.', array(), 'Modules.Legalcompliance.Admin');
$this->confirmUninstall = $this->trans('Are you sure you want to uninstall this module?', array(), 'Modules.Legalcompliance.Admin');
$this->ps_versions_compliancy = array('min' => '1.7.3.0', 'max' => _PS_VERSION_);
/* Init errors var */
$this->_errors = array();
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update.
*/
public function install()
{
$return = parent::install() &&
$this->loadTables() &&
$this->installHooks() &&
$this->registerModulesBackwardCompatHook() &&
$this->registerHook('header') &&
$this->registerHook('displayProductPriceBlock') &&
$this->registerHook('displayCheckoutSubtotalDetails') &&
$this->registerHook('displayFooter') &&
$this->registerHook('displayFooterAfter') &&
$this->registerHook('actionEmailAddAfterContent') &&
$this->registerHook('advancedPaymentOptions') &&
$this->registerHook('displayCartTotalPriceLabel') &&
$this->registerHook('displayCMSPrintButton') &&
$this->registerHook('displayCMSDisputeInformation') &&
$this->registerHook('termsAndConditions') &&
$this->registerHook('displayOverrideTemplate') &&
$this->registerHook('displayCheckoutSummaryTop') &&
$this->registerHook('sendMailAlterTemplateVars') &&
$this->registerHook('displayReassurance') &&
$this->createConfig() &&
$this->generateAndLinkCMSPages() &&
$this->removeCMSPagesIfNeeded() &&
$this->setLegalContentToOrderMails() &&
$this->hideWirePaymentInviteAtOrderConfirmation();
$this->emptyTemplatesCache();
return (bool) $return;
}
public function hideWirePaymentInviteAtOrderConfirmation()
{
return $this->updateWirePaymentInviteDisplayAtOrderConfirmation(false);
}
public function updateWirePaymentInviteDisplayAtOrderConfirmation($display)
{
$wirePaymentModule = Module::getInstanceByName('ps_wirepayment');
if (defined(get_class($wirePaymentModule) . '::FLAG_DISPLAY_PAYMENT_INVITE')) {
$flagName = constant(get_class($wirePaymentModule) . '::FLAG_DISPLAY_PAYMENT_INVITE');
Configuration::updateValue($flagName, $display);
return true;
}
return false;
}
public function showWirePaymentInviteAtOrderConfirmation()
{
return $this->updateWirePaymentInviteDisplayAtOrderConfirmation(true);
}
public function uninstall()
{
return parent::uninstall() &&
$this->dropConfig() &&
$this->showWirePaymentInviteAtOrderConfirmation() &&
$this->unloadTables();
}
public function disable($force_all = false)
{
$is_adv_api_disabled = (bool) Configuration::updateValue('PS_ATCP_SHIPWRAP', false);
return parent::disable() && $is_adv_api_disabled;
}
public function registerModulesBackwardCompatHook()
{
$return = true;
$module_to_check = array(
'bankwire', 'cheque', 'paypal',
'adyen', 'hipay', 'cashondelivery', 'sofortbanking',
'pigmbhpaymill', 'ogone', 'moneybookers',
'syspay',
);
$display_payment_eu_hook_id = (int) Hook::getIdByName('displayPaymentEu');
$already_hooked_modules_ids = array_keys(Hook::getModulesFromHook($display_payment_eu_hook_id));
foreach ($module_to_check as $module_name) {
if (($module = Module::getInstanceByName($module_name)) !== false &&
Module::isInstalled($module_name) &&
$module->active &&
!in_array($module->id, $already_hooked_modules_ids) &&
!$module->isRegisteredInHook('displayPaymentEu')) {
$return &= $module->registerHook('displayPaymentEu');
}
}
return $return;
}
public function installHooks()
{
$hooks = array(
'displayPaymentEu' => array(
'name' => 'Display EU payment options (helper)',
'description' => 'Hook to display payment options',
),
);
$return = true;
foreach ($hooks as $hook_name => $hook) {
if (Hook::getIdByName($hook_name)) {
continue;
}
$new_hook = new Hook();
$new_hook->name = $hook_name;
$new_hook->title = $hook_name;
$new_hook->description = $hook['description'];
$new_hook->position = true;
if (!$new_hook->add()) {
$return &= false;
$this->_errors[] = $this->trans('Could not install new hook', array(), 'Modules.Legalcompliance.Admin').': '.$hook_name;
}
}
return $return;
}
public function createConfig()
{
$custom_cart_text_values = array();
$langs_repository = $this->entity_manager->getRepository('Language');
$langs = $langs_repository->findAll();
foreach ($langs as $lang) {
$custom_cart_text_values[(int) $lang->id] = $this->trans('The order will only be confirmed when you click on the button \'Order with an obligation to pay\' at the end of the checkout!', array(), 'Modules.Legalcompliance.Shop', $lang->locale);
}
/* Base settings */
$this->processAeucFeatReorder(true);
$this->processAeucLabelRevocationTOS(false);
$this->processAeucLabelRevocationVP(false);
$this->processAeucLabelSpecificPrice(true);
$this->processAeucLabelUnitPrice(true);
$this->processAeucLabelTaxIncExc(true);
$this->processAeucLabelShippingIncExc(false);
$this->processAeucLabelCombinationFrom(true);
return Configuration::updateValue('AEUC_LABEL_CUSTOM_CART_TEXT', $custom_cart_text_values) &&
Configuration::updateValue('AEUC_LABEL_DELIVERY_ADDITIONAL', false) &&
Configuration::updateValue('AEUC_LABEL_SPECIFIC_PRICE', false) &&
Configuration::updateValue('AEUC_LABEL_UNIT_PRICE', true) &&
Configuration::updateValue('AEUC_LABEL_TAX_INC_EXC', 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('PS_TAX_DISPLAY', true) &&
Configuration::updateValue('PS_FINAL_SUMMARY_ENABLED', true);
}
public function generateAndLinkCMSPages()
{
$cms_pages = array(
self::LEGAL_NOTICE => array('meta_title' => $this->trans('Legal notice', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'legal-notice',
'content' => $this->trans('Please add your legal information to this site.', array(), 'Modules.Legalcompliance.Admin'), ),
self::LEGAL_CONDITIONS => array('meta_title' => $this->trans('Terms of Service (ToS)', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'terms-of-service-tos',
'content' => $this->trans('Please add your Terms of Service (ToS) to this site.', array(), 'Modules.Legalcompliance.Admin'), ),
self::LEGAL_REVOCATION => array('meta_title' => $this->trans('Revocation terms', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'revocation-terms',
'content' => $this->trans('Please add your Revocation terms to this site.', array(), 'Modules.Legalcompliance.Admin'), ),
self::LEGAL_PRIVACY => array('meta_title' => $this->trans('Privacy', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'privacy',
'content' => $this->trans('Please insert here your content about privacy. If you have activated Social Media modules, please provide a notice about third-party access to data.', array(), 'Modules.Legalcompliance.Admin'), ),
self::LEGAL_SHIP_PAY => array('meta_title' => $this->trans('Shipping and payment', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'shipping-and-payment',
'content' => $this->trans('Please add your Shipping and payment information to this site.', array(), 'Modules.Legalcompliance.Admin'), ),
self::LEGAL_ENVIRONMENTAL => array('meta_title' => $this->trans('Environmental notice', array(), 'Modules.Legalcompliance.Admin'),
'link_rewrite' => 'environmental-notice',
'content' => $this->trans('Please add your Environmental information to this site.', array(), 'Modules.Legalcompliance.Admin'), ),
);
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$langs_repository = $this->entity_manager->getRepository('Language');
$langs = $langs_repository->findAll();
foreach ($cms_pages as $cms_page_role => $cms_page) {
$cms_role = $cms_role_repository->findOneByName($cms_page_role);
if ((int) $cms_role->id_cms == 0) {
$cms = new CMS();
$cms->id_cms_category = 1;
foreach ($langs as $lang) {
$cms->meta_title[(int) $lang->id] = $cms_page['meta_title'];
$cms->link_rewrite[(int) $lang->id] = 'aeu-legal-'.$cms_page['link_rewrite'];
$cms->content[(int) $lang->id] = $cms_page['content'];
}
$cms->active = 1;
$cms->add();
$cms_role->id_cms = (int) $cms->id;
$cms_role->update();
}
}
return true;
}
public function removeCMSPagesIfNeeded()
{
if (Module::isInstalled('ps_linklist')) {
$cms_repository = $this->entity_manager->getRepository('CMS');
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_page_conditions_associated = $cms_role_repository->findOneByName(self::LEGAL_CONDITIONS);
$sql = 'SELECT id_link_block, content
FROM '._DB_PREFIX_.'link_block';
$link_blocks = Db::getInstance()->executeS($sql);
foreach ($link_blocks as $link_block) {
$conditions_found = false;
$content = json_decode($link_block['content'], true);
if (isset($content['cms']) && is_array($content['cms'])) {
foreach ($content['cms'] as $cms_key => $cms_id) {
if ((int) $cms_id == (int) $cms_page_conditions_associated->id_cms) {
unset($content['cms'][$cms_key]);
$conditions_found = true;
}
}
}
if ($conditions_found) {
$content['cms'] = array_values($content['cms']);
$content = json_encode($content);
Db::getInstance()->update('link_block', array('content' => pSQL($content)), '`id_link_block` = '.(int) $link_block['id_link_block']);
}
}
}
return true;
}
public function setLegalContentToOrderMails()
{
$cms_roles_aeuc = $this->getCMSRoles();
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_roles_associated = $cms_role_repository->getCMSRolesAssociated();
$role_ids_to_set = array();
$role_id_legal_notice = false;
$email_ids_to_set = array();
$account_email_ids_to_set = array();
$legal_options = array();
$cleaned_mails_names = array();
foreach ($cms_roles_associated as $role) {
if ($role->name == self::LEGAL_CONDITIONS || $role->name == self::LEGAL_REVOCATION || $role->name == self::LEGAL_NOTICE) {
$role_ids_to_set[] = $role->id;
}
if ($role->name == self::LEGAL_NOTICE) {
$role_id_legal_notice = $role->id;
}
}
$email_filenames = array(
'backoffice_order',
'credit_slip',
'order_canceled',
'order_changed',
'order_conf',
'order_customer_comment',
'order_merchant_comment',
'order_return_state',
'payment',
'refund',
);
foreach (AeucEmailEntity::getAll() as $email) {
if (in_array($email['filename'], $email_filenames)) {
$email_ids_to_set[] = $email['id_mail'];
}
}
$account_newsletter_mail_filenames = array(
'account',
'newsletter',
'password',
'password_query',
);
foreach (AeucEmailEntity::getAll() as $email) {
if (in_array($email['filename'], $account_newsletter_mail_filenames)) {
$account_email_ids_to_set[] = $email['id_mail'];
}
}
AeucCMSRoleEmailEntity::truncate();
foreach ($role_ids_to_set as $role_id) {
foreach ($email_ids_to_set as $email_id) {
$assoc_obj = new AeucCMSRoleEmailEntity();
$assoc_obj->id_mail = (int) $email_id;
$assoc_obj->id_cms_role = (int) $role_id;
$assoc_obj->save();
}
}
if ($role_id_legal_notice) {
foreach ($account_email_ids_to_set as $email_id) {
$assoc_obj = new AeucCMSRoleEmailEntity();
$assoc_obj->id_mail = (int) $email_id;
$assoc_obj->id_cms_role = (int) $role_id_legal_notice;
$assoc_obj->save();
}
}
return true;
}
public function unloadTables()
{
$state = true;
$sql = require __DIR__.'/install/sql_install.php';
foreach ($sql as $name => $v) {
$state &= Db::getInstance()->execute('DROP TABLE IF EXISTS '.$name);
}
return $state;
}
public function loadTables()
{
$state = true;
// Create module's table
$sql = require __DIR__.'/install/sql_install.php';
foreach ($sql as $s) {
$state &= Db::getInstance()->execute($s);
}
// Fillin CMS ROLE
$roles_array = $this->getCMSRoles();
$roles = array_keys($roles_array);
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
foreach ($roles as $role) {
if (!$cms_role_repository->findOneByName($role)) {
$cms_role = $cms_role_repository->getNewEntity();
$cms_role->id_cms = 0; // No assoc at this time
$cms_role->name = $role;
$state &= (bool) $cms_role->save();
}
}
$default_path_email = _PS_MAIL_DIR_.'en'.DIRECTORY_SEPARATOR;
// Fill-in aeuc_mail table
foreach ($this->emails->getAvailableMails($default_path_email) as $mail) {
$new_email = new AeucEmailEntity();
$new_email->filename = (string) $mail;
$new_email->display_name = $this->emails->getCleanedMailName($mail);
$new_email->save();
unset($new_email);
}
return $state;
}
public function dropConfig()
{
return Configuration::deleteByName('AEUC_LABEL_DELIVERY_ADDITIONAL') &&
Configuration::deleteByName('AEUC_LABEL_SPECIFIC_PRICE') &&
Configuration::deleteByName('AEUC_LABEL_UNIT_PRICE') &&
Configuration::deleteByName('AEUC_LABEL_TAX_INC_EXC') &&
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_LABEL_CUSTOM_CART_TEXT') &&
Configuration::updateValue('PS_ATCP_SHIPWRAP', false);
}
/*
This method checks if cart has virtual products
It's better to add this method (as hasVirtualProduct) and add 'protected static $_hasVirtualProduct = array(); property
in Cart class in next version of prestashop.
*/
private function hasCartVirtualProduct(Cart $cart)
{
$products = $cart->getProducts();
if (!count($products)) {
return false;
}
foreach ($products as $product) {
if ($product['is_virtual']) {
return true;
}
}
return false;
}
public function hookDisplayCartTotalPriceLabel($param)
{
$smartyVars = array();
if ((bool) Configuration::get('AEUC_LABEL_TAX_INC_EXC') === true) {
$customer_default_group_id = (int) $this->context->customer->id_default_group;
$customer_default_group = new Group($customer_default_group_id);
if ((bool) Configuration::get('PS_TAX') === true && $this->context->country->display_tax_label &&
!(Validate::isLoadedObject($customer_default_group) && (bool) $customer_default_group->price_display_method === true)) {
$smartyVars['price']['tax_str_i18n'] = $this->trans('Tax included', array(), 'Shop.Theme.Checkout');
} else {
$smartyVars['price']['tax_str_i18n'] = $this->trans('Tax excluded', array(), 'Shop.Theme.Checkout');
}
}
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(array('smartyVars' => $smartyVars));
return $this->display(__FILE__, 'displayCartTotalPriceLabel.tpl');
}
public function hookDisplayOverrideTemplate($param)
{
if (isset($this->context->controller->php_self) && !$this->context->controller->ajax && ($this->context->controller->php_self == 'order')) {
return $this->getTemplatePath('hookDisplayOverrideTemplateFooter.tpl');
}
}
public function hookDisplayCheckoutSummaryTop($param)
{
$cart_url = $this->context->link->getPageLink(
'cart',
null,
$this->context->language->id,
['action' => 'show']
);
$this->context->smarty->assign('link_shopping_cart', $cart_url);
return $this->display(__FILE__, 'hookDisplayCheckoutSummaryTop.tpl');
}
public function hookDisplayReassurance($param)
{
if (isset($this->context->controller->php_self) && (in_array($this->context->controller->php_self, array('order', 'cart')))) {
$custom_cart_text = Configuration::get('AEUC_LABEL_CUSTOM_CART_TEXT', (int) $this->context->language->id);
if (trim($custom_cart_text) == '') {
return false;
} else {
$this->context->smarty->assign('custom_cart_text', $custom_cart_text);
return $this->display(__FILE__, 'hookDisplayReassurance.tpl');
}
}
}
public function hookDisplayFooter($param)
{
$cms_roles_to_be_displayed = array(self::LEGAL_NOTICE,
self::LEGAL_CONDITIONS,
self::LEGAL_REVOCATION,
self::LEGAL_PRIVACY,
self::LEGAL_SHIP_PAY,
self::LEGAL_ENVIRONMENTAL, );
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_pages_associated = $cms_role_repository->findByName($cms_roles_to_be_displayed);
$is_ssl_enabled = (bool) Configuration::get('PS_SSL_ENABLED');
$cms_links = array();
foreach ($cms_pages_associated as $cms_page_associated) {
if ($cms_page_associated instanceof CMSRole && (int) $cms_page_associated->id_cms > 0) {
$cms = new CMS((int) $cms_page_associated->id_cms);
$cms_links[] = array('link' => $this->context->link->getCMSLink($cms->id, null, $is_ssl_enabled),
'id' => 'cms-page-'.$cms->id,
'title' => $cms->meta_title[$this->context->language->id],
'desc' => $cms->meta_description[$this->context->language->id],
);
}
}
$this->context->smarty->assign('cms_links', $cms_links);
return $this->display(__FILE__, 'hookDisplayFooter.tpl');
}
public function hookDisplayFooterAfter($param)
{
if (isset($this->context->controller->php_self)) {
if (in_array($this->context->controller->php_self, array('index', 'category', 'prices-drop', 'new-products', 'best-sales', 'search', 'product'))) {
$cms_repository = $this->entity_manager->getRepository('CMS');
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_page_shipping_pay = $cms_role_repository->findOneByName(self::LEGAL_SHIP_PAY);
$link_shipping = false;
if ((int) $cms_page_shipping_pay->id_cms > 0) {
$cms_shipping_pay = $cms_repository->i10nFindOneById((int) $cms_page_shipping_pay->id_cms,
(int) $this->context->language->id,
(int) $this->context->shop->id);
$link_shipping =
$this->context->link->getCMSLink($cms_shipping_pay, $cms_shipping_pay->link_rewrite, (bool) Configuration::get('PS_SSL_ENABLED'));
}
if ($this->context->controller->php_self == 'product') {
$delivery_addtional_info = Configuration::get('AEUC_LABEL_DELIVERY_ADDITIONAL', (int) $this->context->language->id);
if (trim($delivery_addtional_info) == '') {
return false;
}
$this->context->smarty->assign('link_shipping', $link_shipping);
$this->context->smarty->assign('delivery_additional_information', $delivery_addtional_info);
} else {
$customer_default_group_id = (int) $this->context->customer->id_default_group;
$customer_default_group = new Group($customer_default_group_id);
if ((bool) Configuration::get('PS_TAX') === true && $this->context->country->display_tax_label &&
!(Validate::isLoadedObject($customer_default_group) && (bool) $customer_default_group->price_display_method === true)) {
$tax_included = true;
} else {
$tax_included = false;
}
$this->context->smarty->assign('show_shipping', (bool) Configuration::get('AEUC_LABEL_SHIPPING_INC_EXC') === true);
$this->context->smarty->assign('link_shipping', $link_shipping);
$this->context->smarty->assign('tax_included', $tax_included);
}
return $this->display(__FILE__, 'hookDisplayFooterAfter.tpl');
}
}
}
/* This hook is present to maintain backward compatibility */
public function hookAdvancedPaymentOptions($param)
{
$legacyOptions = Hook::exec('displayPaymentEU', array(), null, true);
$newOptions = array();
Media::addJsDef(array('aeuc_tos_err_str' => Tools::htmlentitiesUTF8($this->trans('You must agree to our Terms of Service before going any further!', array(), 'Modules.Legalcompliance.Shop'))));
Media::addJsDef(array('aeuc_submit_err_str' => Tools::htmlentitiesUTF8($this->trans('Something went wrong. If the problem persists, please contact us.', array(), 'Modules.Legalcompliance.Shop'))));
Media::addJsDef(array('aeuc_no_pay_err_str' => Tools::htmlentitiesUTF8($this->trans('Select a payment option first.', array(), 'Modules.Legalcompliance.Shop'))));
Media::addJsDef(array('aeuc_virt_prod_err_str' => Tools::htmlentitiesUTF8($this->trans('Please check the "Revocation of virtual products" box first!', array(), 'Modules.Legalcompliance.Shop'))));
if ($legacyOptions) {
foreach ($legacyOptions as $module_name => $legacyOption) {
if (!$legacyOption) {
continue;
}
foreach (PaymentOption::convertLegacyOption($legacyOption) as $option) {
$option->setModuleName($module_name);
$to_be_cleaned = $option->getForm();
if ($to_be_cleaned) {
$cleaned = str_replace('@hiddenSubmit', '', $to_be_cleaned);
$option->setForm($cleaned);
}
$newOptions[] = $option;
}
}
}
return $newOptions;
}
public function hookActionEmailAddAfterContent($param)
{
if (!isset($param['template']) || !isset($param['template_html']) || !isset($param['template_txt'])) {
return;
}
$tpl_name = (string) $param['template'];
$tpl_name_exploded = explode('.', $tpl_name);
if (is_array($tpl_name_exploded)) {
$tpl_name = (string) $tpl_name_exploded[0];
}
$id_lang = (int) $param['id_lang'];
$mail_id = AeucEmailEntity::getMailIdFromTplFilename($tpl_name);
if (!isset($mail_id['id_mail'])) {
return;
}
$mail_id = (int) $mail_id['id_mail'];
$cms_role_ids = AeucCMSRoleEmailEntity::getCMSRoleIdsFromIdMail($mail_id);
if (!$cms_role_ids) {
return;
}
$tmp_cms_role_list = array();
foreach ($cms_role_ids as $cms_role_id) {
$tmp_cms_role_list[] = $cms_role_id['id_cms_role'];
}
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_roles = $cms_role_repository->findByIdCmsRole($tmp_cms_role_list);
if (!$cms_roles) {
return;
}
$cms_repo = $this->entity_manager->getRepository('CMS');
$cms_contents = array();
foreach ($cms_roles as $cms_role) {
$cms_page = $cms_repo->i10nFindOneById((int) $cms_role->id_cms, $id_lang, $this->context->shop->id);
if (!isset($cms_page->content)) {
continue;
}
$cms_contents[] = $cms_page->content;
$param['template_txt'] .= strip_tags($cms_page->content, true);
}
$this->context->smarty->assign(array('cms_contents' => $cms_contents));
$param['template_html'] .= $this->display(__FILE__, 'hook-email-wrapper.tpl');
}
public function hookSendMailAlterTemplateVars($param)
{
if (!isset($param['template']) && !isset($param['{carrier}'])) {
return;
}
$tpl_name = (string) $param['template'];
$tpl_name_exploded = explode('.', $tpl_name);
if (is_array($tpl_name_exploded)) {
$tpl_name = (string) $tpl_name_exploded[0];
}
if ('order_conf' !== $tpl_name) {
return;
}
$carrier = new Carrier((int) $param['cart']->id_carrier);
$param['template_vars']['{carrier}'] .= ' - '.$carrier->delay[(int) $param['cart']->id_lang];
}
public function hookHeader($param)
{
$this->context->controller->registerStylesheet('modules-aeuc_front', 'modules/'.$this->name.'/views/css/aeuc_front.css', ['media' => 'all', 'priority' => 150]);
if (isset($this->context->controller->php_self) && ($this->context->controller->php_self == 'cms')) {
if ($this->isPrintableCMSPage()) {
$this->context->controller->registerStylesheet('modules-aeuc_print', 'modules/'.$this->name.'/views/css/aeuc_print.css', ['media' => 'print', 'priority' => 150]);
}
}
if (Tools::getValue('direct_print') == '1') {
$this->context->controller->registerJavascript('modules-fo_aeuc_print', 'modules/'.$this->name.'/views/js/fo_aeuc_print.js', ['position' => 'bottom', 'priority' => 150]);
}
}
protected function isPrintableCMSPage()
{
$printable_cms_pages = array();
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
foreach (array(self::LEGAL_CONDITIONS, self::LEGAL_REVOCATION, self::LEGAL_SHIP_PAY, self::LEGAL_PRIVACY) as $cms_page_name) {
$cms_page_associated = $cms_role_repository->findOneByName($cms_page_name);
if ($cms_page_associated instanceof CMSRole && (int) $cms_page_associated->id_cms > 0) {
$printable_cms_pages[] = (int) $cms_page_associated->id_cms;
}
}
return in_array(Tools::getValue('id_cms'), $printable_cms_pages);
}
public function hookDisplayCMSDisputeInformation($params)
{
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_page_associated = $cms_role_repository->findOneByName(self::LEGAL_NOTICE);
if ($cms_page_associated instanceof CMSRole && (int) $cms_page_associated->id_cms > 0) {
if (Tools::getValue('id_cms') == $cms_page_associated->id_cms) {
return $this->display(__FILE__, 'hookDisplayCMSDisputeInformation.tpl');
}
}
}
public function hookTermsAndConditions($param)
{
$returned_terms_and_conditions = array();
$cms_repository = $this->entity_manager->getRepository('CMS');
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_page_conditions_associated = $cms_role_repository->findOneByName(self::LEGAL_CONDITIONS);
$cms_page_revocation_associated = $cms_role_repository->findOneByName(self::LEGAL_REVOCATION);
if (Configuration::get('PS_CONDITIONS') && (int) $cms_page_conditions_associated->id_cms > 0 && (int) $cms_page_revocation_associated->id_cms > 0) {
$cms_conditions = $cms_repository->i10nFindOneById((int) $cms_page_conditions_associated->id_cms,
(int) $this->context->language->id,
(int) $this->context->shop->id);
$link_conditions =
$this->context->link->getCMSLink($cms_conditions, $cms_conditions->link_rewrite, (bool) Configuration::get('PS_SSL_ENABLED'));
$cms_revocation = $cms_repository->i10nFindOneById((int) $cms_page_revocation_associated->id_cms,
(int) $this->context->language->id,
(int) $this->context->shop->id);
$link_revocation =
$this->context->link->getCMSLink($cms_revocation, $cms_revocation->link_rewrite, (bool) Configuration::get('PS_SSL_ENABLED'));
$termsAndConditions = new TermsAndConditions();
$termsAndConditions
->setText(
$this->trans('I agree to the [terms of service] and [revocation terms] and will adhere to them unconditionally.', [], 'Modules.Legalcompliance.Shop'),
$link_conditions,
$link_revocation
)
->setIdentifier('terms-and-conditions');
$returned_terms_and_conditions[] = $termsAndConditions;
}
if ((bool) Configuration::get('AEUC_LABEL_REVOCATION_VP') && $this->hasCartVirtualProduct($this->context->cart)) {
$termsAndConditions = new TermsAndConditions();
$termsAndConditions
->setText(
$this->trans(
'[1]For digital goods:[/1] I want immediate access to the digital content and I acknowledge that thereby I lose my right to cancel once the service has begun.[2][1]For services:[/1] I agree to the starting of the service and I acknowledge that I lose my right to cancel once the service has been fully performed.',
array(
'[1]' => '<strong>',
'[/1]' => '</strong>',
'[2]' => '<br>',
),
'Modules.Legalcompliance.Shop'
)
)
->setIdentifier('virtual-products');
$returned_terms_and_conditions[] = $termsAndConditions;
}
if (count($returned_terms_and_conditions) > 0) {
return $returned_terms_and_conditions;
} else {
return false;
}
}
public function hookDisplayCMSPrintButton($param)
{
if ($this->isPrintableCMSPage()) {
$this->context->smarty->assign('directPrint', Tools::getValue('content_only') != '1');
$cms_repository = $this->entity_manager->getRepository('CMS');
$cms_current = $cms_repository->i10nFindOneById((int) Tools::getValue('id_cms'),
(int) $this->context->language->id,
(int) $this->context->shop->id);
$cms_current_link =
$this->context->link->getCMSLink($cms_current, $cms_current->link_rewrite, (bool) Configuration::get('PS_SSL_ENABLED'));
if (!strpos($cms_current_link, '?')) {
$cms_current_link .= '?direct_print=1';
} else {
$cms_current_link .= '&direct_print=1';
}
$this->context->smarty->assign('print_link', $cms_current_link);
return $this->display(__FILE__, 'hookDisplayCMSPrintButton.tpl');
}
}
public function hookDisplayProductPriceBlock($param)
{
if (!isset($param['product']) || !isset($param['type'])) {
return;
}
$product = $param['product'];
$hook_type = $param['type'];
if (!$product instanceof Product) {
$product_repository = $this->entity_manager->getRepository('Product');
$product = $product_repository->findOne((int) $product['id_product']);
}
if (!Validate::isLoadedObject($product)) {
return;
}
$smartyVars = array();
/* Handle Product Combinations label */
if ($param['type'] == 'before_price' && (bool) Configuration::get('AEUC_LABEL_COMBINATION_FROM') === true) {
if ($product->hasAttributes()) {
$need_display = false;
$combinations = $product->getAttributeCombinations($this->context->language->id);
if ($combinations && is_array($combinations)) {
foreach ($combinations as $combination) {
if ((float) $combination['price'] != 0) {
$need_display = true;
break;
}
}
unset($combinations);
if ($need_display) {
$smartyVars['before_price'] = array();
$smartyVars['before_price']['from_str_i18n'] = $this->trans('From', array(), 'Modules.Legalcompliance.Shop');
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type);
}
}
return;
}
}
/* Handle Specific Price label*/
if ($param['type'] == 'old_price' && (bool) Configuration::get('AEUC_LABEL_SPECIFIC_PRICE') === true && 'catalog/_partials/miniatures/product.tpl' != $param['smarty']->template_resource) {
$smartyVars['old_price'] = array();
$smartyVars['old_price']['before_str_i18n'] = $this->trans('Our previous price', array(), 'Modules.Legalcompliance.Shop');
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type);
}
/* Handle Shipping Inc./Exc.*/
if ($param['type'] == 'price') {
$smartyVars['price'] = array();
$need_shipping_label = true;
if ((bool) Configuration::get('AEUC_LABEL_SHIPPING_INC_EXC') === true && $need_shipping_label === true) {
if (!$product->is_virtual) {
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_repository = $this->entity_manager->getRepository('CMS');
$cms_page_associated = $cms_role_repository->findOneByName(self::LEGAL_SHIP_PAY);
if (isset($cms_page_associated->id_cms) && $cms_page_associated->id_cms != 0) {
$cms_ship_pay_id = (int) $cms_page_associated->id_cms;
$cms_revocations = $cms_repository->i10nFindOneById($cms_ship_pay_id, $this->context->language->id,
$this->context->shop->id);
$is_ssl_enabled = (bool) Configuration::get('PS_SSL_ENABLED');
$link_ship_pay = $this->context->link->getCMSLink($cms_revocations, $cms_revocations->link_rewrite, $is_ssl_enabled);
$smartyVars['ship'] = array();
$smartyVars['ship']['link_ship_pay'] = $link_ship_pay;
$smartyVars['ship']['ship_str_i18n'] = $this->trans('Shipping excluded', array(), 'Modules.Legalcompliance.Shop');
}
}
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type);
}
/* Handle Delivery time label */
if ($param['type'] == 'after_price' && !$product->is_virtual) {
$context_id_lang = $this->context->language->id;
$smartyVars['after_price'] = array();
$delivery_addtional_info = Configuration::get('AEUC_LABEL_DELIVERY_ADDITIONAL', (int) $context_id_lang);
if (trim($delivery_addtional_info) !== '') {
if (array_key_exists('delivery_str_i18n', $smartyVars['after_price'])) {
$smartyVars['after_price']['delivery_str_i18n'] .= '*';
} else {
$smartyVars['after_price']['delivery_str_i18n'] = '*';
}
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type);
}
/* Handle Taxes Inc./Exc.*/
if ($param['type'] == 'list_taxes') {
$smartyVars['list_taxes'] = array();
if ((bool) Configuration::get('AEUC_LABEL_TAX_INC_EXC') === true) {
$customer_default_group_id = (int) $this->context->customer->id_default_group;
$customer_default_group = new Group($customer_default_group_id);
if ((bool) Configuration::get('PS_TAX') === true && $this->context->country->display_tax_label &&
!(Validate::isLoadedObject($customer_default_group) && (bool) $customer_default_group->price_display_method === true)) {
$smartyVars['list_taxes']['tax_str_i18n'] = $this->trans('Tax included', array(), 'Shop.Theme.Checkout');
} else {
$smartyVars['list_taxes']['tax_str_i18n'] = $this->trans('Tax excluded', array(), 'Shop.Theme.Checkout');
}
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type);
}
/* Handle Unit prices */
if ($param['type'] == 'unit_price') {
if ((!empty($product->unity) && $product->unit_price_ratio > 0.000000)) {
$smartyVars['unit_price'] = array();
if ((bool) Configuration::get('AEUC_LABEL_UNIT_PRICE') === true) {
if (!(isset($this->context->controller->php_self) && ($this->context->controller->php_self == 'product'))) {
$priceDisplay = Product::getTaxCalculationMethod((int) $this->context->cookie->id_customer);
if (!$priceDisplay || $priceDisplay == 2) {
$productPrice = $product->getPrice(true, null, 6);
} else {
$productPrice = $product->getPrice(false, null, 6);
}
$smartyVars['unit_price']['unit_price'] = $param['product']['unit_price_full'];
$smartyVars['unit_price']['unity'] = $product->unity;
}
}
return $this->dumpHookDisplayProductPriceBlock($smartyVars, $hook_type, $product->id);
}
}
}
public function hookDisplayCheckoutSubtotalDetails($param)
{
// Display "under conditions" when the shipping subtotal equals 0
if ('shipping' === $param['subtotal']['type'] && 0 === $param['subtotal']['amount']) {
$cms_role_repository = $this->entity_manager->getRepository('CMSRole');
$cms_page_shipping_and_payment = $cms_role_repository->findOneByName(self::LEGAL_SHIP_PAY);
$link = $this->context->link->getCMSLink((int) $cms_page_shipping_and_payment->id_cms);
$this->context->smarty->assign(array('link' => $link));
return $this->display(__FILE__, 'hookDisplayCartPriceBlock_shipping_details.tpl');