/
customer_edit.php
74 lines (55 loc) · 1.61 KB
/
customer_edit.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
<?php
/**
* Copyright (c) 2010-2011 Laposa Ltd (http://laposa.co.uk)
* Licensed under the New BSD License. See the file LICENSE.txt for details.
*
*/
class Onxshop_Controller_Component_Client_Customer_Edit extends Onxshop_Controller {
/**
* main action
*/
public function mainAction() {
/**
* check input
*/
if ($_SESSION['client']['customer']['id'] == 0 && !Onxshop_Bo_Authentication::getInstance()->isAuthenticated()) {
msg('controllers/client/customer_detail: You must logged in.', 'error');
onxshopGoTo("/");
} else {
if (is_numeric($this->GET['customer_id']) && constant('ONXSHOP_IN_BACKOFFICE')) $customer_id = $this->GET['customer_id'];
else $customer_id = $_SESSION['client']['customer']['id'];
}
if (!is_numeric($customer_id)) return false;
/**
* initialize
*/
require_once('models/client/client_customer.php');
$this->Customer = new client_customer();
$this->Customer->setCacheable(false);
/**
* save
*/
if (is_array($_POST['client']['customer'])) {
$data_to_save = $_POST['client']['customer'];
$data_to_save['id'] = $customer_id;
$this->saveDetail($data_to_save);
}
/**
* get customer detail
*/
$customer_detail = $this->Customer->getDetail($customer_id);
if (is_array($customer_detail)) {
$this->tpl->assign('ITEM', $customer_detail);
} else {
msg('controllers/client/customer_detail: cannot get detail', 'error');
}
return true;
}
/**
* save
*/
public function saveDetail($data) {
if ($this->Customer->updateCustomer($data)) msg('saved');
else msg('failed', 'error');
}
}