· 6 years ago · Jul 22, 2019, 08:52 AM
1<?php defined('_PS_VERSION_') or exit;
2
3
4class Inpli_Ip extends Module {
5
6 public function __construct() {
7 $this->name = 'inpli_ip';
8 $this->tab = 'other';
9 $this->version = '1.0.0';
10 $this->author = 'tobieniepodam@gmail.com';
11 $this->need_instance = 0;
12
13 parent::__construct();
14
15 $this->displayName = 'Inpli IP';
16 $this->description = 'IP customer store.';
17 //$this->confirmUninstall = 'Are You sure you want to uninstall?';
18 //$this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_);
19 }
20
21 public function install() {
22 if (!parent::install()
23 || !$this->registerHook('actionOrderStatusUpdate')
24 || !$this->install_db()
25 ) {
26 return false;
27 }
28
29 return true;
30 }
31
32 private function install_db() {
33 $sql = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'inpli_ip` ('
34 . ' `id_order` INT(10) NOT NULL PRIMARY KEY,'
35 . ' `ip` VARCHAR(15) NOT NULL)'
36 . ' ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;';
37 return Db::getInstance()->execute($sql);
38 }
39
40 public function uninstall() {
41 if (!parent::uninstall()
42 || !$this->uninstall_db()
43 ) {
44 return false;
45 }
46
47 return true;
48 }
49
50 private function uninstall_db() {
51 $sql = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'inpli_ip`;';
52 return Db::getInstance()->execute($sql);
53 }
54
55 public function hookActionOrderStatusUpdate($data) {
56 if(Tools::getValue('controller') != 'validation') {
57 return;
58 }
59 Db::getInstance()->insert('inpli_ip', [
60 'id_order' => (int)$data['newOrderStatus']->id,
61 'ip' => $_SERVER['REMOTE_ADDR'],
62 ]);
63 }
64}