-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrackingpostcode.php
More file actions
54 lines (44 loc) · 1.46 KB
/
trackingpostcode.php
File metadata and controls
54 lines (44 loc) · 1.46 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
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class TrackingPostcode extends Module
{
public function __construct()
{
$this->name = 'trackingpostcode';
$this->tab = 'shipping_logistics';
$this->version = '1.0.0';
$this->author = 'Minicraft';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Tracking Number Postcode');
$this->description = $this->l('Afegeix automàticament el codi postal al número de seguiment');
}
public function install()
{
return parent::install() &&
$this->registerHook('actionObjectOrderCarrierUpdateAfter');
}
public function hookActionObjectOrderCarrierUpdateAfter($params)
{
$order_carrier = $params['object'];
if (!Validate::isLoadedObject($order_carrier) || empty($order_carrier->tracking_number)) {
return;
}
if (strpos($order_carrier->tracking_number, '/') !== false) {
return;
}
$order = new Order($order_carrier->id_order);
if (!Validate::isLoadedObject($order)) {
return;
}
$address = new Address($order->id_address_delivery);
if (!Validate::isLoadedObject($address)) {
return;
}
$order_carrier->tracking_number = $order_carrier->tracking_number . '/' . $address->postcode;
$order_carrier->update();
}
}