Repository navigation
Expand file tree
/
Copy pathsendynl.php
More file actions
272 lines (224 loc) · 8.41 KB
/
Copy pathsendynl.php
File metadata and controls
272 lines (224 loc) · 8.41 KB
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
<?php
/**
* This file is part of the Sendy PrestaShop module - https://sendy.nl
*
* @author Sendy B.V.
* @copyright Sendy B.V.
* @license https://github.com/sendynl/prestashop-module/blob/master/LICENSE MIT
*
* @see https://github.com/sendynl/prestashop-module
*/
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Prestashop\ModuleLibMboInstaller\DependencyBuilder;
use Sendy\PrestaShop\Action\CreateShipmentFromOrder;
use Sendy\PrestaShop\Factory\ApiConnectionFactory;
use Sendy\PrestaShop\Hook;
use Sendy\PrestaShop\Installer;
use Sendy\PrestaShop\Legacy\DummyUrlGenerator;
use Sendy\PrestaShop\Repository\ConfigurationRepository;
use Sendy\PrestaShop\Repository\ShopConfigurationRepository;
use Sendy\PrestaShop\Service\PrestashopModuleTracking;
if (!defined('_PS_VERSION_')) {
exit;
}
class Sendynl extends CarrierModule
{
public const EDIT_SHIPMENT_URL = 'https://app.sendy.nl/shipment/%s/edit';
public const VIEW_PACKAGE_URL = 'https://app.sendy.nl/packages/%s';
protected bool $config_form = false;
public function __construct()
{
$this->name = 'sendynl';
$this->tab = 'shipping_logistics';
$this->version = '3.1.0';
$this->author = 'Sendy B.V.';
$this->need_instance = 1;
$this->module_key = 'c4f781164993281f1b2e1e3147b96348';
/*
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->trans('Sendy', [], 'Modules.Sendynl.Admin');
$this->description = $this->trans('A PrestaShop module that connects your store to the Sendy platform', [], 'Modules.Sendynl.Admin');
$this->ps_versions_compliancy = ['min' => '1.7.8', 'max' => _PS_VERSION_];
$this->tabs = [
[
'name' => 'Sendy',
'class_name' => 'AdminSendynlSettings',
'visible' => true,
'parent_class_name' => 'AdminParentShipping',
],
];
}
/**
* Don't forget to create update methods if needed:
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
*/
public function install(): bool
{
if (!extension_loaded('curl')) {
$this->_errors[] = $this->trans('You have to enable the cURL extension on your server to install this module', [], 'Modules.Sendynl.Admin');
return false;
}
if (Module::isInstalled('sendy')) {
$this->_errors[] = $this->trans('Please uninstall the old "sendy" module before installing this module', [], 'Modules.Sendynl.Admin');
return false;
}
include dirname(__FILE__) . '/sql/install.php';
return parent::install()
&& Installer\ConfigurationDefaults::install()
&& Installer\SystemUser::install()
&& Installer\Hooks::install($this)
&& $this->trackModuleEvent('Module Installed');
}
public function uninstall(): bool
{
include dirname(__FILE__) . '/sql/uninstall.php';
return parent::uninstall()
&& Installer\SystemUser::uninstall()
&& $this->trackModuleEvent('Module Uninstalled');
}
public function enable($force_all = false)
{
return parent::enable($force_all)
&& $this->trackModuleEvent('Module Enabled');
}
public function disable($force_all = false)
{
return parent::disable($force_all)
&& $this->trackModuleEvent('Module Disabled');
}
/** @return array<mixed> */
public function runUpgradeModule(): array
{
$result = parent::runUpgradeModule();
$this->trackModuleEvent('Module Upgraded');
return $result;
}
/**
* Load the configuration form
*
* @return void|string
*
* @throws Exception
*/
public function getContent()
{
$mboInstaller = new DependencyBuilder($this);
if (!$mboInstaller->areDependenciesMet()) {
$this->smarty->assign('dependencies', $mboInstaller->handleDependencies());
return $this->display(__FILE__, 'views/templates/admin/dependency_builder.tpl');
}
Tools::redirectAdmin($this->context->link->getAdminLink('SettingsController', true, ['route' => 'sendynl_settings']));
}
/**
* @param mixed $params
* @param mixed $shipping_cost
*
* @return float
*/
public function getOrderShippingCost($params, $shipping_cost): float
{
return (float) $shipping_cost;
}
/**
* @param mixed $params
*/
public function getOrderShippingCostExternal($params): bool
{
return false;
}
public function isUsingNewTranslationSystem(): bool
{
return true;
}
/**
* @param array<string, string> $properties
*/
public function trackModuleEvent(string $eventName, array $properties = []): bool
{
PrestashopModuleTracking::track(
$this,
$eventName,
$properties
);
return true;
}
public function hookActionAdminControllerSetMedia(): void
{
try {
$this->get(Hook\Admin\ActionAdminControllerSetMedia::class)($this);
} catch (Exception $e) {
PrestaShopLogger::addLog(
'Sendy - ActionAdminControllerSetMedia - Error: ' . $e->getMessage(),
PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR
);
}
}
public function hookActionFrontControllerSetMedia(): void
{
(new Hook\Front\ActionFrontControllerSetMedia())($this);
}
public function hookActionOrderStatusPostUpdate($params): void
{
$configurationRepository = new ConfigurationRepository(new PrestaShop\PrestaShop\Adapter\Configuration());
$shopConfigurationRepository = new ShopConfigurationRepository(new PrestaShop\PrestaShop\Adapter\Configuration(), new PrestaShop\PrestaShop\Adapter\Shop\Context());
$apiConnectionFactory = new ApiConnectionFactory($configurationRepository, new DummyUrlGenerator());
$createShipmentFromOrder = new CreateShipmentFromOrder($apiConnectionFactory, $shopConfigurationRepository);
(new Hook\ActionOrderStatusPostUpdate($createShipmentFromOrder, $shopConfigurationRepository))($params);
}
public function hookActionValidateStepComplete($params): void
{
(new Hook\Front\ActionValidateStepComplete())($params);
}
public function hookDisplayCarrierExtraContent($params): string
{
return (new Hook\Front\DisplayCarrierExtraContent())($params);
}
public function hookActionOrderGridDefinitionModifier(array $params): void
{
$this->get(Hook\Admin\ActionOrderGridDefinitionModifier::class)($params);
}
public function hookActionOrderGridQueryBuilderModifier(array $params): void
{
(new Hook\Admin\ActionOrderGridQueryBuilderModifier())($params);
}
public function hookDisplayAdminOrderSide($params): string
{
return $this->get(Hook\Admin\DisplayAdminOrderSide::class)($params);
}
public function hookDisplayAdminEndContent($params): string
{
return $this->get(Hook\Admin\DisplayAdminEndContent::class)($params);
}
public function hookActionCarrierFormBuilderModifier(array $params): void
{
$this->get(Hook\Admin\ActionCarrierFormBuilderModifier::class)($params);
}
public function hookActionAfterUpdateCarrierFormHandler(array $params): void
{
$this->get(Hook\Admin\ActionAfterUpdateCarrierFormHandler::class)($params);
}
public function hookActionAfterCreateCarrierFormHandler(array $params): void
{
$this->get(Hook\Admin\ActionAfterCreateCarrierFormHandler::class)($params);
}
public function hookActionCarrierFormDataProviderData(array $params): void
{
$this->get(Hook\Admin\ActionCarrierFormDataProviderData::class)($params);
}
public function hookActionObjectCarrierAddAfter(array $params): void
{
$this->get(Hook\Admin\ActionObjectCarrierAddAfter::class)($params);
}
public function hookActionObjectCarrierUpdateAfter(array $params): void
{
$this->get(Hook\Admin\ActionObjectCarrierUpdateAfter::class)($params);
}
public function hookActionObjectCarrierDeleteAfter(array $params): void
{
$this->get(Hook\Admin\ActionObjectCarrierDeleteAfter::class)($params);
}
}