-
Notifications
You must be signed in to change notification settings - Fork 0
/
phdiscountbybankwire.php
201 lines (169 loc) · 6.9 KB
/
phdiscountbybankwire.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
<?php
/**
* 2007-2016 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com 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 <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Discount by Bank Wire payment module by Krystian Podemski from PrestaHome.
*
* @author Krystian Podemski <krystian@prestahome.com>
* @copyright Copyright (c) 2016 Krystian Podemski - www.PrestaHome.com / www.Podemski.info
* @license You only can use module, nothing more!
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once dirname(__FILE__).'/vendor/autoload.php';
class PhDiscountByBankwire extends Module implements PrestaHomeConfiguratorInterface
{
use PrestaHomeHelpers, PrestaHomeConfiguratorBase;
public function __construct()
{
$this->name = 'phdiscountbybankwire';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'PrestaHome';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Discount by bankwire');
$this->description = $this->l('You can setup discount available only within a payment by bankwire');
$this->setOptionsPrefix('phdiscountbybankwire');
}
public function setOptionsPrefix($custom = false)
{
$this->options_prefix = Tools::strtoupper(($custom ? $custom : $this->name)).'_';
return $this;
}
public function install()
{
$hooks = array(
'displayBeforeShoppingCartBlock',
'displayPaymentTop',
);
$this->renderConfigurationForm();
$this->batchUpdateConfigs();
if (file_exists(_PS_MODULE_DIR_.$this->name.'/init/my-install.php')) {
require_once _PS_MODULE_DIR_.$this->name.'/init/my-install.php';
}
PhDiscountByBankwire::recurseCopy(dirname(__FILE__).'/override/modules/', _PS_OVERRIDE_DIR_.'modules/');
if (!parent::install() || !$this->registerHook($hooks)) {
return false;
}
return true;
}
public function uninstall()
{
$this->renderConfigurationForm();
$this->deleteConfigs();
if (file_exists(_PS_MODULE_DIR_.$this->name.'/init/my-uninstall.php')) {
require_once _PS_MODULE_DIR_.$this->name.'/init/my-uninstall.php';
}
return parent::uninstall();
}
public function getContent()
{
$this->renderConfigurationForm();
$this->_html = '<h2>'.$this->displayName.'</h2>';
if (Tools::isSubmit('save'.$this->name)) {
$this->renderConfigurationForm();
$this->batchUpdateConfigs();
$this->_clearCache('*');
$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully.'));
}
return $this->_html.$this->renderForm();
}
public function renderConfigurationForm()
{
if ($this->fields_form) {
return;
}
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Voucher code from "Cart Rules" page:'),
'name' => $this->options_prefix.'CODE',
'desc' => $this->l('Fill with a code of the generated voucher from the "Cart Rules" page, module will get information about discount based on this code.'),
'default' => '',
'validate' => 'isCleanHtml',
),
array(
'type' => 'textarea',
'autoload_rte' => true,
'lang' => true,
'label' => $this->l('Message for customers:'),
'name' => $this->options_prefix.'MSG_SHOPPING_CART',
'desc' => $this->l('Displayed at the top of the shopping cart (displayBeforeShoppingCartBlock)'),
'default' => '<div class="alert alert-info">Get 2% discount by paying within a bankwire!</div>',
'validate' => 'isCleanHtml',
),
array(
'type' => 'textarea',
'autoload_rte' => true,
'lang' => true,
'label' => $this->l('Message for customers:'),
'name' => $this->options_prefix.'MSG_PAYMENTS_PAGE',
'desc' => $this->l('Displayed at the top of the payments page (displayPaymentTop)'),
'default' => '<div class="alert alert-info">Get 2% discount by paying within a bankwire!</div>',
'validate' => 'isCleanHtml',
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default', ),
),
);
$this->fields_form[] = $fields_form;
}
public function hookDisplayBeforeShoppingCartBlock($params)
{
$this->smarty->assign('message', Configuration::get($this->options_prefix.'MSG_SHOPPING_CART', $this->context->language->id));
return $this->display(__FILE__, 'message.tpl');
}
public function hookDisplayPaymentTop($params)
{
$this->smarty->assign('message', Configuration::get($this->options_prefix.'MSG_PAYMENTS_PAGE', $this->context->language->id));
return $this->display(__FILE__, 'message.tpl');
}
public static function recurseCopy($src, $dst)
{
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src.'/'.$file)) {
PhDiscountByBankwire::recurseCopy($src.'/'.$file, $dst.'/'.$file);
} else {
copy($src.'/'.$file, $dst.'/'.$file);
}
}
}
closedir($dir);
}
}