-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.php
146 lines (124 loc) · 4.79 KB
/
address.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
141
142
143
144
145
146
<?php
/* SSL Management */
$useSSL = true;
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
if (!$cookie->isLogged())
Tools::redirect('authentication.php');
//CSS ans JS file calls
$js_files = array(
_THEME_JS_DIR_.'tools/statesManagement.js'
);
if ($back = Tools::getValue('back'))
$smarty->assign('back', Tools::safeOutput($back));
$errors = array();
if ($id_address = intval(Tools::getValue('id_address')))
{
$address = new Address(intval($id_address));
if (Validate::isLoadedObject($address) AND Customer::customerHasAddress(intval($cookie->id_customer), intval($id_address)))
{
if (isset($_GET['delete']))
{
if ($cart->id_address_invoice == $address->id)
unset($cart->id_address_invoice);
if ($cart->id_address_delivery == $address->id)
unset($cart->id_address_delivery);
if ($address->delete())
Tools::redirect('addresses.php');
$errors[] = Tools::displayError('this address cannot be deleted');
}
$smarty->assign(array(
'address' => $address,
'id_address' => intval($id_address)
));
}
else
Tools::redirect('addresses.php');
}
if (Tools::isSubmit('submitAddress'))
{
$address = new Address();
$address->id_customer = intval($cookie->id_customer);
$errors = $address->validateControler();
if (Configuration::get('PS_TOKEN_ENABLE') == 1 &&
strcmp(Tools::getToken(false), Tools::getValue('token')) &&
$cookie->isLogged() === true)
$errors[] = Tools::displayError('invalid token');
if (!$country = new Country($address->id_country) OR !Validate::isLoadedObject($country))
die(Tools::displayError());
if (intval($country->contains_states) AND !intval($address->id_state))
$errors[] = Tools::displayError('this country require a state selection');
if (!sizeof($errors))
{
if (isset($id_address))
{
$country = new Country(intval($address->id_country));
if (Validate::isLoadedObject($country) AND !$country->contains_states)
$address->id_state = false;
$address_old = new Address(intval($id_address));
if (Validate::isLoadedObject($address_old) AND Customer::customerHasAddress(intval($cookie->id_customer), intval($address_old->id)))
{
if ($cart->id_address_invoice == $address_old->id)
unset($cart->id_address_invoice);
if ($cart->id_address_delivery == $address_old->id)
unset($cart->id_address_delivery);
if ($address_old->isUsed())
$address_old->delete();
else
{
$address->id = intval($address_old->id);
$address->date_add = $address_old->date_add;
}
}
}
if ($result = $address->save())
{
if ((bool)(Tools::getValue('select_address', false)) == true)
{
/* This new adress is for invoice_adress, select it */
$cart->id_address_invoice = intval($address->id);
$cart->update();
}
/* If saving success return the list */
Tools::redirect($back ? $back : 'addresses.php');
}else{
/** Or show the error message */
$errors[] = Tools::displayError('an error occurred while updating your address');
}
}
}
elseif (!$id_address)
{
$customer = new Customer(intval($cookie->id_customer));
if (Validate::isLoadedObject($customer))
{
$_POST['firstname'] = $customer->firstname;
$_POST['lastname'] = $customer->lastname;
}
}
if (isset($_POST['id_country']) AND !empty($_POST['id_country']) AND is_numeric($_POST['id_country']))
$selectedCountry = intval($_POST['id_country']);
elseif (isset($address) AND isset($address->id_country) AND !empty($address->id_country) AND is_numeric($address->id_country))
$selectedCountry = intval($address->id_country);
elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (!Validate::isLanguageIsoCode($array[0]) OR !($selectedCountry = Country::getByIso($array[0])))
$selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
}
else
$selectedCountry = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
$countries = Country::getCountries(intval($cookie->id_lang), true);
$countriesList = '';
foreach ($countries AS $country)
$countriesList .= '<option value="'.intval($country['id_country']).'" '.($country['id_country'] == $selectedCountry ? 'selected="selected"' : '').'>'.htmlentities($country['name'], ENT_COMPAT, 'UTF-8').'</option>';
include(dirname(__FILE__).'/header.php');
$smarty->assign('countries_list', $countriesList);
$smarty->assign('countries', $countries);
$smarty->assign('errors', $errors);
$smarty->assign('token', Tools::getToken(false));
$smarty->assign('select_address', intval(Tools::getValue('select_address')));
Tools::safePostVars();
$smarty->display(_PS_THEME_DIR_.'address.tpl');
include(dirname(__FILE__).'/footer.php');
?>