Merge branch 'ticket-ChangeDeliveryAddress' into develop
This commit is contained in:
commit
bdb50a3c16
@ -6,7 +6,7 @@ $ant_changeaddress = new Ant_Changeaddress();
|
||||
|
||||
if($cookie->isLogged() && Tools::getValue('id_order')) {
|
||||
if(Tools::getValue('getPR')
|
||||
&& ($mode = (float) Tools::getValue('mode'))
|
||||
&& ($mode = Tools::getValue('mode'))
|
||||
&& ($h_xcoords = (float) Tools::getValue('h_xcoords'))
|
||||
&& ($h_ycoords = (float) Tools::getValue('h_ycoords'))) {
|
||||
$pr_list = array();
|
||||
@ -18,7 +18,7 @@ if($cookie->isLogged() && Tools::getValue('id_order')) {
|
||||
AND `ycoords` <= '.(float) $h_ycoords.' + 0.02
|
||||
AND `xcoords` >= '.(float) $h_xcoords.' - 0.01
|
||||
AND `xcoords` <= '.(float) $h_xcoords.' + 0.01
|
||||
AND `type` = "'.$mode.'"
|
||||
AND (`type` = "'.$mode.'"'.($mode == "BPR"?' OR `type` = "CDI"':'').')
|
||||
')));
|
||||
}
|
||||
|
||||
|
@ -54,4 +54,82 @@ class Ant_Changeaddress extends Module
|
||||
}
|
||||
return $current_address;
|
||||
}
|
||||
|
||||
public $validation = array(
|
||||
'company' => '/[<>=#{}]*/',
|
||||
'firstname' => '/[0-9!<>,;?=+()@#"°{}_$%:]*/',
|
||||
'lastname' => '/[0-9!<>,;?=+()@#"°{}_$%:]*/',
|
||||
'address1' => '/[!<>?=+@{}_$%]*/',
|
||||
'address2' => '/[!<>?=+@{}_$%]*/',
|
||||
'postcode' => '/[^a-zA-Z 0-9-]/',
|
||||
'city' => '/[!<>;?=+@#"°{}_$%]*/',
|
||||
'phone' => '/[a-zA-Z^%$#@!-]/',
|
||||
'phone_mobile' => '/[a-zA-Z^%$#@!-]/'
|
||||
);
|
||||
|
||||
public function createAddress($id_customer, $country, $libelle, $address1, $address2, $postcode, $city, $telephone, $lastname, $firstname, $id_address_delivery = null)
|
||||
{
|
||||
if ($id_address_delivery) {
|
||||
$customer_address = new Address($id_address_delivery);
|
||||
} else {
|
||||
$customer_address = null;
|
||||
}
|
||||
|
||||
$address = new Address();
|
||||
$address_rules = Address::getValidationRules('Address');
|
||||
|
||||
$country = ($country && Tools::strlen($country) === 2) ?
|
||||
$country : Country::getIsoById($customer_address->id_country);
|
||||
$id_customer = $id_customer ? $id_customer : $customer_address->id_customer;
|
||||
|
||||
//$address->id_country = (int)Country::getByIso($this->country);
|
||||
$address->id_country = strtolower($country) == 'fr'? 8: (int)Country::getByIso($country);
|
||||
$address->id_customer = (int)$id_customer;
|
||||
$address->firstname = $firstname ? $firstname : $customer_address->firstname;
|
||||
$address->lastname = $lastname ? $lastname : $customer_address->lastname;
|
||||
$address->company = $libelle;
|
||||
$address->address1 = $address1 ? $address1 : $customer_address->address1;
|
||||
$address->address2 = $address2;
|
||||
$address->postcode = $postcode ? $postcode : $customer_address->postcode;
|
||||
$address->city = $city ? $city : $customer_address->city;
|
||||
$address->phone_mobile = $telephone ? $telephone : $customer_address->phone_mobile;
|
||||
$address->phone = $telephone ? $telephone : $customer_address->phone;
|
||||
|
||||
if (!$address->phone_mobile) {
|
||||
$address->phone_mobile = '0661123456';
|
||||
}
|
||||
|
||||
$address_fields = array(
|
||||
'company',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'address1',
|
||||
'address2',
|
||||
'postcode',
|
||||
'city',
|
||||
'phone',
|
||||
'phone_mobile'
|
||||
);
|
||||
|
||||
foreach ($address_fields as $field) {
|
||||
$address->{$field} = preg_replace($this->validation[$field], '', $address->{$field});
|
||||
|
||||
if (isset($address_rules['required'][$field]) && $address_rules['required'][$field]) {
|
||||
if (empty($address->{$field})) {
|
||||
$address->{$field} = '-';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($address_rules['size'][$field]) && $address_rules['size'][$field]) {
|
||||
$address->{$field} = Tools::substr($address->{$field}, 0, $address_rules['size'][$field]);
|
||||
}
|
||||
}
|
||||
|
||||
$address->alias = 'So Colissimo - '.date('d-m-Y');
|
||||
$address->active = 1;
|
||||
$address->deleted = 1;
|
||||
$address->add();
|
||||
return $address->id;
|
||||
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column .address_box{
|
||||
width: auto;
|
||||
max-width: 250px;
|
||||
max-width: 300px;
|
||||
margin: 0 auto;
|
||||
list-style: none;
|
||||
padding: 10px;
|
||||
@ -50,7 +50,48 @@
|
||||
#module-ant_changeaddress-change_address #center_column .address_box li:first-child{
|
||||
font-weight: bold;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column .dest-info{
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin-right: 30px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column .pr-info{
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
margin-right: 30px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column form .submit_buttons{
|
||||
margin: 20px auto;
|
||||
text-align: center;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #search{
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #map_canvas {
|
||||
width: 470px;
|
||||
height: 300px;
|
||||
display: inline-block;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #pr_list{
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #pr_list ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #pr_list ul li{
|
||||
text-align: left;
|
||||
padding: 10px;
|
||||
background: #F3F3F3;
|
||||
cursor: pointer;
|
||||
}
|
||||
#module-ant_changeaddress-change_address #center_column #pr_list ul li.selected,
|
||||
#module-ant_changeaddress-change_address #center_column #pr_list ul li:hover{
|
||||
background: #514c8c;
|
||||
color: #fff;
|
||||
}
|
@ -25,6 +25,58 @@ if ($cookie->isLogged()) {
|
||||
if((int)$order->id_customer != (int)$customer->id) {
|
||||
$errors[] = Tools::displayError('Invalid customer for this order');
|
||||
} else {
|
||||
if(Tools::isSubmit('submitChangeAddress')) {
|
||||
if(Tools::getValue('id_cart')) {
|
||||
$mode = Tools::getValue('delivery_mode','');
|
||||
if (empty($mode)) {
|
||||
$mode = "DOM";
|
||||
}
|
||||
Db::getInstance()->Execute('UPDATE ps_socolissimo_delivery_info SET
|
||||
delivery_mode = "'.pSQL($mode).'",
|
||||
prname = "'.pSQL(Tools::getValue('prname', '')).'",
|
||||
prfirstname = "'.pSQL(Tools::getValue('prfirstname', '')).'",
|
||||
cecompanyname = "'.pSQL(Tools::getValue('cecompanyname', '')).'",
|
||||
cename = "'.pSQL(Tools::getValue('cename', '')).'",
|
||||
cefirstname = "'.pSQL(Tools::getValue('cefirstname', '')).'",
|
||||
prcompladress = "'.pSQL(Tools::getValue('prcompladress', '')).'",
|
||||
pradress1 = "'.pSQL(Tools::getValue('pradress1', '')).'",
|
||||
pradress2 = "'.pSQL(Tools::getValue('pradress2', '')).'",
|
||||
pradress3 = "'.pSQL(Tools::getValue('pradress3', '')).'",
|
||||
pradress4 = "'.pSQL(Tools::getValue('pradress4', '')).'",
|
||||
przipcode = "'.pSQL(Tools::getValue('przipcode', '')).'",
|
||||
prtown = "'.pSQL(Tools::getValue('prtown', '')).'",
|
||||
cephonenumber = "'.pSQL(Tools::getValue('cephonenumber', '')).'",
|
||||
ceemail = "'.pSQL(Tools::getValue('ceemail', '')).'",
|
||||
cedeliveryinformation = "'.pSQL(Tools::getValue('cedeliveryinformation', '')).'",
|
||||
cedoorcode1 = "'.pSQL(Tools::getValue('cedoorcode1', '')).'",
|
||||
cedoorcode2 = "'.pSQL(Tools::getValue('cedoorcode2', '')).'",
|
||||
prid = "'.pSQL(Tools::getValue('prid', '')).'"
|
||||
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))));
|
||||
|
||||
if ($mode == "DOM" && Tools::getValue('id_address_delivery')) {
|
||||
$newAddressId = Tools::getValue('id_address_delivery');
|
||||
} else {
|
||||
$newAddressId = $ant_changeaddress->createAddress(
|
||||
(int)$customer->id,
|
||||
"FR",
|
||||
pSQL(Tools::getValue('prname', '')),
|
||||
pSQL(Tools::getValue('pradress3', '')),
|
||||
pSQL(Tools::getValue('pradress2', '')),
|
||||
pSQL(Tools::getValue('przipcode', '')),
|
||||
pSQL(Tools::getValue('prtown', '')),
|
||||
pSQL(Tools::getValue('cephonenumber', '')),
|
||||
pSQL(Tools::getValue('cename', '')),
|
||||
pSQL(Tools::getValue('cefirstname', ''))
|
||||
);
|
||||
}
|
||||
if($newAddressId) {
|
||||
$order->id_address_delivery = (int)$newAddressId;
|
||||
$order->update();
|
||||
}
|
||||
} else {
|
||||
$errors[] = Tools::displayError('Error occured');
|
||||
}
|
||||
}
|
||||
$address = Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
|
||||
@ -37,7 +89,7 @@ if ($cookie->isLogged()) {
|
||||
'2' => 'Livraison à domicile (DOM)',
|
||||
'3' => 'Livraison à domicile (DOM)',
|
||||
);
|
||||
} elseif($address['delivery_mode'] == "BPR") {
|
||||
} elseif($address['delivery_mode'] == "BPR" || $address['delivery_mode'] == "CDI") {
|
||||
$delivery_mode = "BPR";
|
||||
$mode = array(
|
||||
'2' => 'Livraison en Bureau de Poste (BPR)',
|
||||
@ -57,7 +109,6 @@ if ($cookie->isLogged()) {
|
||||
WHERE `id_pr` = '.pSQL($address['prid']).'
|
||||
');
|
||||
$c_address = htmlentities(preg_replace('/(, ){2,}/', ', ', preg_replace('/(, ){2,}/', ', ', implode(', ', array($address['pradress3'], $address['pradress4'], $address['pradress1'], $address['pradress2']))).', '.$address['przipcode'].' '.$address['prtown'].', FRANCE'));
|
||||
//echo '<pre>';var_dump($c_address);echo '</pre>';die();
|
||||
$smarty->assign(array(
|
||||
'c_address' => $c_address,
|
||||
//'pr_coords' => $pr_coords
|
||||
@ -86,53 +137,6 @@ if ($cookie->isLogged()) {
|
||||
$errors[] = Tools::displayError('Invalid order');
|
||||
}
|
||||
|
||||
if(isset($_POST['submitChangeAddress'])) {
|
||||
$mode = Tools::getValue('delivery_mode','');
|
||||
if (empty($mode)) {
|
||||
$mode = "DOM";
|
||||
}
|
||||
Db::getInstance()->Execute('UPDATE ps_socolissimo_delivery_info SET
|
||||
delivery_mode = "'.pSQL($mode).'",
|
||||
prname = "'.pSQL(Tools::getValue('prname', '')).'",
|
||||
prfirstname = "'.pSQL(Tools::getValue('prfirstname', '')).'",
|
||||
cecompanyname = "'.pSQL(Tools::getValue('cecompanyname', '')).'",
|
||||
cename = "'.pSQL(Tools::getValue('cename', '')).'",
|
||||
cefirstname = "'.pSQL(Tools::getValue('cefirstname', '')).'",
|
||||
prcompladress = "'.pSQL(Tools::getValue('prcompladress', '')).'",
|
||||
pradress1 = "'.pSQL(Tools::getValue('pradress1', '')).'",
|
||||
pradress2 = "'.pSQL(Tools::getValue('pradress2', '')).'",
|
||||
pradress3 = "'.pSQL(Tools::getValue('pradress3', '')).'",
|
||||
pradress4 = "'.pSQL(Tools::getValue('pradress4', '')).'",
|
||||
przipcode = "'.pSQL(Tools::getValue('przipcode', '')).'",
|
||||
prtown = "'.pSQL(Tools::getValue('prtown', '')).'",
|
||||
cephonenumber = "'.pSQL(Tools::getValue('cephonenumber', '')).'",
|
||||
ceemail = "'.pSQL(Tools::getValue('ceemail', '')).'",
|
||||
cedeliveryinformation = "'.pSQL(Tools::getValue('cedeliveryinformation', '')).'",
|
||||
cedoorcode1 = "'.pSQL(Tools::getValue('cedoorcode1', '')).'",
|
||||
cedoorcode2 = "'.pSQL(Tools::getValue('cedoorcode2', '')).'",
|
||||
prid = "'.pSQL(Tools::getValue('prid', '')).'"
|
||||
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))));
|
||||
|
||||
$order = Db::getInstance()->getRow('
|
||||
SELECT date_add,id_order
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE id_cart = '.pSQL(intval(Tools::getValue('id_cart'))).'
|
||||
');
|
||||
|
||||
mail('marion@antadis.com', '[BBB] Modif transporteur FRONT',
|
||||
'ID Customer : ' . $address['id_customer'].
|
||||
' , ID Order : ' . $order['id_order'].
|
||||
' , Date Order : ' . $order['date_add'].
|
||||
' , Date now : ' . date("Y-m-d H:i:s").
|
||||
' , ID cart : ' . Tools::getValue('id_cart').
|
||||
' , Mode en date : '.$address['delivery_mode'].' -- remplacé par : ' .Tools::getValue('delivery_mode', '').
|
||||
' , Address1 en date : '.$address['pradress1'].' -- remplacé par : ' .Tools::getValue('pradress1', '').
|
||||
' , Address2 en date : '.$address['pradress2'].' -- remplacé par : ' .Tools::getValue('pradress2', '').
|
||||
' , Address3 en date : '.$address['pradress3'].' -- remplacé par : ' .Tools::getValue('pradress3', '').
|
||||
' , Address4 en date : '.$address['pradress4'].' -- remplacé par : ' .Tools::getValue('pradress4', '')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$smarty->assign(array(
|
||||
|
@ -3,20 +3,20 @@
|
||||
{include file="$tpl_dir./breadcrumb.tpl"}
|
||||
{include file="$tpl_dir./errors.tpl"}
|
||||
|
||||
<h1>{l s='Change your delivery address for this order'}</h1>
|
||||
<h1>{l s='Change your delivery address for this order' mod='ant_changeaddress'}</h1>
|
||||
{if $current_address}
|
||||
<form action="{$request_uri|escape:'htmlall':'UTF-8'}" class="std" method="post">
|
||||
<fieldset>
|
||||
<h3>{$mode[$cookie->id_lang]}</h3>
|
||||
<p class="info">{l s='For reasons of tarification, you cannot change the delivery mode'}</p>
|
||||
<p class="info">{l s='For reasons of tarification, you cannot change the delivery mode' mod='ant_changeaddress'}</p>
|
||||
|
||||
{if $delivery_mode == "DOM"}
|
||||
|
||||
<p class="address_delivery select">
|
||||
<label for="id_address_delivery">{l s='Choose a delivery address:'}</label>
|
||||
<label for="id_address_delivery">{l s='Choose a delivery address:' mod='ant_changeaddress'}</label>
|
||||
<select name="id_address_delivery" id="id_address_delivery" class="address_select">
|
||||
{foreach from=$addresses key=k item=address}
|
||||
<option value="{$address.id_address|intval}" {if $address.id_address == $order_cart->id_address_delivery}selected="selected"{/if}>{$address.alias|escape:'htmlall':'UTF-8'}</option>
|
||||
<option value="{$address.id_address|intval}" {if $address.id_address == $order->id_address_delivery}selected="selected"{/if}>{$address.alias|escape:'htmlall':'UTF-8'}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</p>
|
||||
@ -29,138 +29,429 @@
|
||||
</ul>
|
||||
|
||||
{elseif $delivery_mode == "BPR" || $delivery_mode == "A2P"}
|
||||
<ul class="address_box" >
|
||||
{if !empty($current_address)}
|
||||
{foreach from=$current_address name=address item=line}
|
||||
<li>{$line}</li>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</ul>
|
||||
{* <p>
|
||||
<label>{l s='Name'}</label>
|
||||
<input autocomplete="off" type="text" name="prname" value="{addslashes($address['prname'])}" />
|
||||
<div class='dest-info'>
|
||||
<p>
|
||||
<label>{l s='Nom destinataire' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="cename" value="{addslashes($address['cename'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Prénom destinataire' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="cefirstname" value="{addslashes($address['cefirstname'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Email' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="ceemail" value="{addslashes($address['ceemail'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Entreprise' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="cecompanyname" value="{addslashes($address['cecompanyname'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Téléphone' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="cephonenumber" value="{addslashes($address['cephonenumber'])}" />
|
||||
</p>
|
||||
</div>
|
||||
<div class="pr-info">
|
||||
<ul class="address_box" >
|
||||
{if !empty($current_address)}
|
||||
{foreach from=$current_address name=address item=line}
|
||||
<li>{$line}</li>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</ul>
|
||||
</div>
|
||||
<p class="hidden">
|
||||
<input autocomplete="off" type="hidden" name="prname" value="{addslashes($address['prname'])}" />
|
||||
<input autocomplete="off" type="hidden" name="pradress1" value="{addslashes($address['pradress1'])}" />
|
||||
<input autocomplete="off" type="hidden" name="pradress2" value="{addslashes($address['pradress2'])}" />
|
||||
<input autocomplete="off" type="hidden" name="pradress3" value="{addslashes($address['pradress3'])}" />
|
||||
<input autocomplete="off" type="hidden" name="pradress4" value="{addslashes($address['pradress4'])}" />
|
||||
<input autocomplete="off" type="hidden" name="przipcode" value="{addslashes($address['przipcode'])}" />
|
||||
<input autocomplete="off" type="hidden" name="prtown" value="{addslashes($address['prtown'])}" />
|
||||
<input autocomplete="off" type="hidden" name="prid" value="{addslashes($address['prid'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Firstname'}</label>
|
||||
<input autocomplete="off" type="text" name="prfirstname" value="{addslashes($address['prfirstname'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Phone'}</label>
|
||||
<input autocomplete="off" type="text" name="cephonenumber" value="{addslashes($address['cephonenumber'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Email'}</label>
|
||||
<input autocomplete="off" type="text" name="ceemail" value="{addslashes($address['ceemail'])}" />
|
||||
</p>
|
||||
<p>
|
||||
<label>{l s='Company'}</label>
|
||||
<input autocomplete="off" type="text" name="cecompanyname" value="{addslashes($address['cecompanyname'])}" />
|
||||
</p> *}
|
||||
<div id="map_canvas"></div><div id="pr_list"><ul></ul></div>
|
||||
|
||||
{/if}
|
||||
|
||||
<p class="submit_buttons">
|
||||
{if $delivery_mode == "DOM"}
|
||||
<a href="{$link->getPageLink('address.php', true)}" title="{l s='Add'}" class="button_large">{l s='Add a new address'}</a>
|
||||
<a href="{$link->getPageLink('address.php', true)}" title="{l s='Add' mod='ant_changeaddress'}" class="button_large">{l s='Add a new address' mod='ant_changeaddress'}</a>
|
||||
{/if}
|
||||
<input type="submit" name="submitChandAddress" class="button_large" value="{l s='Update'}">
|
||||
<input type="submit" name="submitChangeAddress" class="button_large" value="{l s='Update Delivery address' mod='ant_changeaddress'}">
|
||||
<input autocomplete="off" type="hidden" name="delivery_mode" value="{$delivery_mode}">
|
||||
<input autocomplete="off" type="hidden" name="id_cart" value="{$order_cart->id}">
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
{if $delivery_mode == "BPR" || $delivery_mode == "A2P"}
|
||||
<form action="" id="search_pr">
|
||||
<p>
|
||||
<label>{l s='Search address' mod='ant_changeaddress'}</label>
|
||||
<input autocomplete="off" type="text" name="search" id="search" value="{addslashes($c_address)}" />
|
||||
<button id="button-search" class="button_large" onclick="return false;">{l s='search'}</button>
|
||||
</p>
|
||||
<div id="map_canvas"></div><div id="pr_list"><ul></ul></div>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
|
||||
|
||||
<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>
|
||||
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery-1.4.4.min.js"></script>
|
||||
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery.ui.map.js"></script>
|
||||
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/jquery.ui.map.services.js"></script>
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
$("#id_address_delivery").change(function(){
|
||||
var id_address = $("#id_address_delivery").val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id_order : {/literal}{$order->id}{literal},
|
||||
getAD : 1,
|
||||
id_address : id_address,
|
||||
token : static_token
|
||||
},
|
||||
success: function(jsonData) {
|
||||
$("ul.address_box").empty();
|
||||
$("ul.address_box").html(jsonData);
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to get update address \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
|
||||
});
|
||||
});
|
||||
function updateForm(delivery_mode, name, address1, address2, address3, address4, postcode, city, prid) {
|
||||
$("input[name=prname]").val("");
|
||||
$("input[name=prfirstname]").val("");
|
||||
$("input[name=pradress1]").val("");
|
||||
$("input[name=pradress2]").val("");
|
||||
$("input[name=pradress3]").val("");
|
||||
$("input[name=pradress4]").val("");
|
||||
$("input[name=przipcode]").val("");
|
||||
$("input[name=prtown]").val("");
|
||||
$("input[name=prid]").val("");
|
||||
$("input[name=prcompladress]").val("");
|
||||
$("input[name=cedoorcode1]").val("");
|
||||
$("input[name=cedoorcode2]").val("");
|
||||
|
||||
$("input[name=prname]").val(name);
|
||||
$("input[name=pradress1]").val(address3);
|
||||
$("input[name=pradress2]").val(address4);
|
||||
$("input[name=pradress3]").val(address1);
|
||||
$("input[name=pradress4]").val(address2);
|
||||
$("input[name=przipcode]").val(postcode);
|
||||
$("input[name=prtown]").val(city);
|
||||
$("input[name=prid]").val(prid);
|
||||
|
||||
data = [name,address1,address2,address3,address4,postcode,city];
|
||||
updateBoxAddress(data);
|
||||
}
|
||||
|
||||
function updateBoxAddress(data){
|
||||
$("ul.address_box").empty();
|
||||
html = "<li>"+$("input[name=cename]").val()+" "+$("input[name=cefirstname]").val()+"</li>";
|
||||
for(var i=0; i < data.length; i++){
|
||||
if(data[i] != ""){
|
||||
html += "<li>"+data[i]+"</li>";
|
||||
}
|
||||
}
|
||||
html += "<li>"+$("input[name=cephonenumber]").val()+"</li>";
|
||||
$("ul.address_box").append(html);
|
||||
}
|
||||
markers = [];
|
||||
delivery_modes = {};
|
||||
delivery_modes['{/literal}{$delivery_mode}{literal}'] = "{/literal}{$mode[$cookie->id_lang]}{literal}";
|
||||
|
||||
$("#map_canvas").gmap({/literal}{if $pr_coords}{literal}'{ "center": "{/literal}{$pr_coords['xcoords']}{literal},{/literal}{$pr_coords['ycoords']}{literal}"}'{/literal}{/if}{literal}).bind("init", function(ev, map) {
|
||||
$("#map_canvas").gmap("search", {"address": "{/literal}{$c_address}{literal}"}, function(results, status) {
|
||||
if ( status === "OK" ) {
|
||||
var lat = null;
|
||||
var lng = null;
|
||||
$.deparam = jq_deparam = function( params, coerce ) {
|
||||
var obj = {},
|
||||
coerce_types = { "true": !0, "false": !1, "null": null };
|
||||
|
||||
if(results[0].geometry.location.H) {
|
||||
lat = results[0].geometry.location.H;
|
||||
lng = results[0].geometry.location.L;
|
||||
} else if(results[0].geometry.location.G) {
|
||||
lat = results[0].geometry.location.G;
|
||||
lng = results[0].geometry.location.K;
|
||||
} else {
|
||||
var loc = results[0].geometry.location.toString().replace("(", "").replace(")", "").replace(" ", "").split(",");
|
||||
lat = loc[0];
|
||||
lng = loc[1];
|
||||
}
|
||||
// Iterate over all name=value pairs.
|
||||
$.each( params.replace( /\+/g, " " ).split( "&" ), function(j,v){
|
||||
var param = v.split( "=" ),
|
||||
key = decodeURIComponent( param[0] ),
|
||||
val,
|
||||
cur = obj,
|
||||
i = 0,
|
||||
|
||||
$("#map_canvas").gmap("addMarker", {"icon": "http://static.privatesportshop.com/img/admin/marker_home.png", "idpr": "pr_home", "position": lat + "," + lng, "bounds": true}).click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": "Adresse actuelle"}, this);
|
||||
});
|
||||
// If key is more complex than "foo", like "a[]" or "a[b][c]", split it
|
||||
// into its component parts.
|
||||
keys = key.split( "][" ),
|
||||
keys_last = keys.length - 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id_order : {/literal}{$order->id}{literal},
|
||||
id_cart : {/literal}{$order_cart->id}{literal},
|
||||
getPR : 1,
|
||||
h_xcoords : lat,
|
||||
h_ycoords : lng,
|
||||
mode : "{/literal}{$delivery_mode}{literal}",
|
||||
token : static_token
|
||||
},
|
||||
success: function(data) {
|
||||
if(data) {
|
||||
for(var i=0; i < data.length; i++) {
|
||||
var prtext = [delivery_modes[data[i].type], data[i].name, data[i].address1, data[i].address2, data[i].address3, data[i].address4, data[i].postcode + " " + data[i].city].filter(function(x) { return x != ""; }).join("<br />");
|
||||
var prtext_action = "<br /><a class=\"maplink\" onclick=\"$(\'#pr_list li[data-index=" + i + "]\').trigger(\'click\'); return false;\">Sélectionner</a>";
|
||||
// If the first keys part contains [ and the last ends with ], then []
|
||||
// are correctly balanced.
|
||||
if ( /\[/.test( keys[0] ) && /\]$/.test( keys[ keys_last ] ) ) {
|
||||
// Remove the trailing ] from the last keys part.
|
||||
keys[ keys_last ] = keys[ keys_last ].replace( /\]$/, "" );
|
||||
|
||||
markers.push($("#map_canvas").gmap("addMarker", { "id": "pr_" + data[i].id_pr, "position": data[i].xcoords + "," + data[i].ycoords, "bounds": true, "content": prtext + prtext_action }));
|
||||
markers[markers.length - 1].click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": $(this).attr("content")}, this);
|
||||
});
|
||||
// Split first keys part into two parts on the [ and add them back onto
|
||||
// the beginning of the keys array.
|
||||
keys = keys.shift().split("[").concat( keys );
|
||||
|
||||
var litem = $("<li />").attr("data-index", i).attr("data-content", $.param(data[i])).html(prtext).click(function() {
|
||||
var data = $.deparam($(this).attr("data-content"));
|
||||
$.each(markers, function(id, el) {
|
||||
if(el[0].id == "pr_" + data.id_pr) {
|
||||
google.maps.event.trigger(el[0], "click");
|
||||
}
|
||||
keys_last = keys.length - 1;
|
||||
} else {
|
||||
// Basic "foo" style key.
|
||||
keys_last = 0;
|
||||
}
|
||||
|
||||
// Are we dealing with a name=value pair, or just a name?
|
||||
if ( param.length === 2 ) {
|
||||
val = decodeURIComponent( param[1] );
|
||||
|
||||
// Coerce values.
|
||||
if ( coerce ) {
|
||||
val = val && !isNaN(val) ? +val // number
|
||||
: val === "undefined" ? undefined // undefined
|
||||
: coerce_types[val] !== undefined ? coerce_types[val] // true, false, null
|
||||
: val; // string
|
||||
}
|
||||
|
||||
if ( keys_last ) {
|
||||
// Complex key, build deep object structure based on a few rules:
|
||||
// * The "cur" pointer starts at the object top-level.
|
||||
// * [] = array push (n is set to array length), [n] = array if n is
|
||||
// numeric, otherwise object.
|
||||
// * If at the last keys part, set the value.
|
||||
// * For each keys part, if the current level is undefined create an
|
||||
// object or array based on the type of the next keys part.
|
||||
// * Move the "cur" pointer to the next level.
|
||||
// * Rinse & repeat.
|
||||
for ( ; i <= keys_last; i++ ) {
|
||||
key = keys[i] === "" ? cur.length : keys[i];
|
||||
cur = cur[key] = i < keys_last
|
||||
? cur[key] || ( keys[i+1] && isNaN( keys[i+1] ) ? {} : [] )
|
||||
: val;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Simple key, even simpler rules, since only scalars and shallow
|
||||
// arrays are allowed.
|
||||
|
||||
if ( $.isArray( obj[key] ) ) {
|
||||
// val is already an array, so push on the next value.
|
||||
obj[key].push( val );
|
||||
|
||||
} else if ( obj[key] !== undefined ) {
|
||||
// val isn"t an array, but since a second value has been specified,
|
||||
// convert val into an array.
|
||||
obj[key] = [ obj[key], val ];
|
||||
|
||||
} else {
|
||||
// val is a scalar.
|
||||
obj[key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( key ) {
|
||||
// No value was defined, so set something meaningful.
|
||||
obj[key] = coerce
|
||||
? undefined
|
||||
: "";
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
// Method: jQuery.deparam.querystring
|
||||
//
|
||||
// Parse the query string from a URL or the current window.location,
|
||||
// deserializing it into an object, optionally coercing numbers, booleans,
|
||||
// null and undefined values.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// > jQuery.deparam.querystring( [ url ] [, coerce ] );
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// url - (String) An optional params string or URL containing query string
|
||||
// params to be parsed. If url is omitted, the current window.location
|
||||
// is used.
|
||||
// coerce - (Boolean) If true, coerces any numbers or true, false, null, and
|
||||
// undefined to their actual value. Defaults to false if omitted.
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// (Object) An object representing the deserialized params string.
|
||||
|
||||
// Method: jQuery.deparam.fragment
|
||||
//
|
||||
// Parse the fragment (hash) from a URL or the current window.location,
|
||||
// deserializing it into an object, optionally coercing numbers, booleans,
|
||||
// null and undefined values.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// > jQuery.deparam.fragment( [ url ] [, coerce ] );
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// url - (String) An optional params string or URL containing fragment (hash)
|
||||
// params to be parsed. If url is omitted, the current window.location
|
||||
// is used.
|
||||
// coerce - (Boolean) If true, coerces any numbers or true, false, null, and
|
||||
// undefined to their actual value. Defaults to false if omitted.
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
// (Object) An object representing the deserialized params string.
|
||||
|
||||
function jq_deparam_sub( is_fragment, url_or_params, coerce ) {
|
||||
if ( url_or_params === undefined || typeof url_or_params === "boolean" ) {
|
||||
// url_or_params not specified.
|
||||
coerce = url_or_params;
|
||||
url_or_params = jq_param[ is_fragment ? str_fragment : str_querystring ]();
|
||||
} else {
|
||||
url_or_params = is_string( url_or_params )
|
||||
? url_or_params.replace( is_fragment ? re_trim_fragment : re_trim_querystring, "" )
|
||||
: url_or_params;
|
||||
}
|
||||
|
||||
return jq_deparam( url_or_params, coerce );
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#id_address_delivery").change(function(){
|
||||
var id_address = $("#id_address_delivery").val();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id_order : {/literal}{$order->id}{literal},
|
||||
getAD : 1,
|
||||
id_address : id_address,
|
||||
token : static_token
|
||||
},
|
||||
success: function(jsonData) {
|
||||
$("ul.address_box").empty();
|
||||
$("ul.address_box").html(jsonData);
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to get update address \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
|
||||
});
|
||||
});
|
||||
|
||||
$("form input[type='text']").change(function(){
|
||||
data = [$("input[name=prname]").val(),$("input[name=pradress1]").val(),$("input[name=pradress2]").val(),$("input[name=pradress3]").val(),$("input[name=pradress4]").val(),$("input[name=przipcode]").val(),$("input[name=prtown]").val()];
|
||||
updateBoxAddress(data);
|
||||
});
|
||||
|
||||
$("#map_canvas").gmap({/literal}{if $pr_coords}{literal}'{ "center": "{/literal}{$pr_coords['xcoords']}{literal},{/literal}{$pr_coords['ycoords']}{literal}"}'{/literal}{/if}{literal}).bind("init", function(ev, map) {
|
||||
$("#map_canvas").gmap("search", {"address": "{/literal}{$c_address}{literal}"}, function(results, status) {
|
||||
if ( status === "OK" ) {
|
||||
var lat = null;
|
||||
var lng = null;
|
||||
|
||||
if(results[0].geometry.location.H) {
|
||||
lat = results[0].geometry.location.H;
|
||||
lng = results[0].geometry.location.L;
|
||||
} else if(results[0].geometry.location.G) {
|
||||
lat = results[0].geometry.location.G;
|
||||
lng = results[0].geometry.location.K;
|
||||
} else {
|
||||
var loc = results[0].geometry.location.toString().replace("(", "").replace(")", "").replace(" ", "").split(",");
|
||||
lat = loc[0];
|
||||
lng = loc[1];
|
||||
}
|
||||
|
||||
$("#map_canvas").gmap("addMarker", {"icon": "http://static.privatesportshop.com/img/admin/marker_home.png", "idpr": "pr_home", "position": lat + "," + lng, "bounds": true}).click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": "Adresse actuelle"}, this);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id_order : {/literal}{$order->id}{literal},
|
||||
id_cart : {/literal}{$order_cart->id}{literal},
|
||||
getPR : 1,
|
||||
h_xcoords : lat,
|
||||
h_ycoords : lng,
|
||||
mode : "{/literal}{$delivery_mode}{literal}",
|
||||
token : static_token
|
||||
},
|
||||
success: function(data) {
|
||||
if(data) {
|
||||
for(var i=0; i < data.length; i++) {
|
||||
var prtext = [delivery_modes[data[i].type], data[i].name, data[i].address1, data[i].address2, data[i].address3, data[i].address4, data[i].postcode + " " + data[i].city].filter(function(x) { return x != ""; }).join("<br />");
|
||||
var prtext_action = "<br /><a class=\"maplink\" onclick=\"$(\'#pr_list li[data-index=" + i + "]\').trigger(\'click\'); return false;\">Sélectionner</a>";
|
||||
|
||||
markers.push($("#map_canvas").gmap("addMarker", { "id": "pr_" + data[i].id_pr, "position": data[i].xcoords + "," + data[i].ycoords, "bounds": true, "content": prtext + prtext_action }));
|
||||
markers[markers.length - 1].click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": $(this).attr("content")}, this);
|
||||
});
|
||||
$("#map_canvas").gmap("option", "center", markers[parseInt($(this).attr("data-index"))][0].getPosition());
|
||||
updateForm(data.type, data.name, data.address1, data.address2, data.address3, data.address4, data.postcode, data.city, data.id_pr);
|
||||
});
|
||||
|
||||
$("#pr_list ul").append(litem);
|
||||
var litem = $("<li />").attr("data-index", i).attr("data-content", $.param(data[i])).html(prtext).click(function() {
|
||||
$("#pr_list ul li").removeClass('selected');
|
||||
$(this).addClass('selected');
|
||||
var data = $.deparam($(this).attr("data-content"));
|
||||
$.each(markers, function(id, el) {
|
||||
if(el[0].id == "pr_" + data.id_pr) {
|
||||
google.maps.event.trigger(el[0], "click");
|
||||
}
|
||||
});
|
||||
$("#map_canvas").gmap("option", "center", markers[parseInt($(this).attr("data-index"))][0].getPosition());
|
||||
updateForm(data.type, data.name, data.address1, data.address2, data.address3, data.address4, data.postcode, data.city, data.id_pr);
|
||||
});
|
||||
$("#pr_list ul").append(litem);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("input#search").change(function(){
|
||||
address = $(this).val();
|
||||
$("#pr_list ul").empty();
|
||||
$("#map_canvas").gmap("search", {"address": address}, function(results, status) {
|
||||
if ( status === "OK" ) {
|
||||
var lat = null;
|
||||
var lng = null;
|
||||
|
||||
if(results[0].geometry.location.H) {
|
||||
lat = results[0].geometry.location.H;
|
||||
lng = results[0].geometry.location.L;
|
||||
} else if(results[0].geometry.location.G) {
|
||||
lat = results[0].geometry.location.G;
|
||||
lng = results[0].geometry.location.K;
|
||||
} else {
|
||||
var loc = results[0].geometry.location.toString().replace("(", "").replace(")", "").replace(" ", "").split(",");
|
||||
lat = loc[0];
|
||||
lng = loc[1];
|
||||
}
|
||||
|
||||
$("#map_canvas").gmap("addMarker", {"icon": "http://static.privatesportshop.com/img/admin/marker_home.png", "idpr": "pr_home", "position": lat + "," + lng, "bounds": true}).click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": "Adresse actuelle"}, this);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '{/literal}{$base_dir_ssl}{literal}modules/ant_changeaddress/ajax.php',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
id_order : {/literal}{$order->id}{literal},
|
||||
id_cart : {/literal}{$order_cart->id}{literal},
|
||||
getPR : 1,
|
||||
h_xcoords : lat,
|
||||
h_ycoords : lng,
|
||||
mode : "{/literal}{$delivery_mode}{literal}",
|
||||
token : static_token
|
||||
},
|
||||
success: function(data) {
|
||||
if(data) {
|
||||
for(var i=0; i < data.length; i++) {
|
||||
var prtext = [delivery_modes[data[i].type], data[i].name, data[i].address1, data[i].address2, data[i].address3, data[i].address4, data[i].postcode + " " + data[i].city].filter(function(x) { return x != ""; }).join("<br />");
|
||||
var prtext_action = "<br /><a class=\"maplink\" onclick=\"$(\'#pr_list li[data-index=" + i + "]\').trigger(\'click\'); return false;\">Sélectionner</a>";
|
||||
|
||||
markers.push($("#map_canvas").gmap("addMarker", { "id": "pr_" + data[i].id_pr, "position": data[i].xcoords + "," + data[i].ycoords, "bounds": true, "content": prtext + prtext_action }));
|
||||
markers[markers.length - 1].click(function() {
|
||||
$("#map_canvas").gmap("openInfoWindow", {"content": $(this).attr("content")}, this);
|
||||
});
|
||||
|
||||
var litem = $("<li />").attr("data-index", i).attr("data-content", $.param(data[i])).html(prtext).click(function() {
|
||||
var data = $.deparam($(this).attr("data-content"));
|
||||
$("#pr_list ul li").removeClass('selected');
|
||||
$(this).addClass('selected');
|
||||
$.each(markers, function(id, el) {
|
||||
if(el[0].id == "pr_" + data.id_pr) {
|
||||
google.maps.event.trigger(el[0], "click");
|
||||
}
|
||||
});
|
||||
$("#map_canvas").gmap("option", "center", markers[parseInt($(this).attr("data-index"))][0].getPosition());
|
||||
updateForm(data.type, data.name, data.address1, data.address2, data.address3, data.address4, data.postcode, data.city, data.id_pr);
|
||||
});
|
||||
$("#pr_list ul").append(litem);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
{/literal}
|
||||
|
Loading…
Reference in New Issue
Block a user