-
Notifications
You must be signed in to change notification settings - Fork 0
/
academyerpintegration.php
140 lines (120 loc) · 3.84 KB
/
academyerpintegration.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
<?php
/**
* NOTICE OF LICENSE
*
* @author INVERTUS, UAB www.invertus.eu <[email protected]>
* @copyright Copyright (c) permanent, INVERTUS, UAB
* @license MIT
* @see /LICENSE
*
* International Registered Trademark & Property of INVERTUS, UAB
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use Invertus\AcademyERPIntegration\Config\TabConfig;
use Invertus\AcademyERPIntegration\Install\Installer;
use Invertus\AcademyERPIntegration\Install\Uninstaller;
use Invertus\AcademyERPIntegration\Config\Config;
class AcademyERPIntegration extends CarrierModule
{
public function __construct()
{
$this->tab = 'other_modules';
$this->name = 'academyerpintegration';
$this->version = '1.0.0';
$this->author = 'Invertus';
parent::__construct();
$this->autoLoad();
$this->displayName = $this->l('Shipment PDF label Module');
$this->description = $this->l('Save shipments to the database, then generate a PDF file of a given shipment');
$this->need_instance = 1;
}
public function getOrderShippingCost($cart, $shippingCost)
{
// Implement Logic
}
public function getOrderShippingCostExternal($cart)
{
return $this->getOrderShippingCost($cart, 0);
}
/**
* {@inheritdoc}
*/
public function getTabs(): array
{
$tabConfig = new TabConfig();
return $tabConfig->getTabs();
}
/**
* {@inheritdoc}
*/
public function getContent(): void
{
$redirectLink = $this->context->link->getAdminLink(Config::SETTINGS_CONTROLLER);
Tools::redirectAdmin($redirectLink);
}
/**
* {@inheritdoc}
*/
public function install(): bool
{
/** Symfony container not used intentionally */
$installer = new Installer($this);
return parent::install() && $installer->init();
}
/**
* {@inheritdoc}
*/
public function uninstall(): bool
{
/** Symfony container not used intentionally */
$unInstaller = new Uninstaller($this);
return parent::uninstall() && $unInstaller->init();
}
public function hookActionDispatcherBefore(): void
{
$this->autoLoad();
}
/**
* Autoload's project files from /src directory
*/
private function autoLoad(): void
{
$autoLoadPath = $this->getLocalPath() . 'vendor/autoload.php';
require_once $autoLoadPath;
}
public function hookDisplayAdminOrderMain(array $params)
{
$order = new Order($params['id_order']);
$carrier = Carrier::getCarrierByReference($order->getIdOrderCarrier());
if(!($carrier instanceof Carrier)){
return '';
}
$externalModuleName = $carrier->external_module_name;
if(is_string($externalModuleName) && $externalModuleName == $this->name){
$twig = $this->getContainer()->get('twig');
$address = new Address($order->id_address_delivery);
$bearerToken = Configuration::get('ERP_API_KEY');
$twig = $this->getContainer()->get('twig');
return $twig->render('@Modules/academyerpintegration/views/Admin/ModuleTable.html.twig',
['bearerToken' => $bearerToken,
'company' => $address->company,
'firstName' => $address->firstname,
'lastName' => $address->lastname,
'city' => $address->city,
'country' => $address->country,
'address1' => $address->address1,
'address2' => $address->address2,
'postcode' => $address->postcode,
'phone' => $address->phone,
'phoneMobile' => $address->phone_mobile,]);
}
}
public function hookActionAdminControllerSetMedia(array $params)
{
$this->context->controller->addJS(
$this->getPathUri() . 'views/js/Shipping.js'
);
}
}