| Link | laposte |
| Author | Dominique Guardiola Falco |
| Category | Custom Tag |
| Version | 8.5.x |
| License | Public Domain |
| Posted | 18 Feb 2008 |
| Updated | 23 Apr 2010 |
| More by this author... | |
This ctag will be only useful for french e-commerce sites.
It simply grabs shipping costs from several applications from La Poste website and gives you the shipping cost for a parcel sent from France based upon weight and others options.
At the moment it handles the following services :
Ce ctag vous permet de calculer automatiquement le coût d'un envoi Colissimo à partie de la France métropolitaine, en fonction de son poids, de sa destination et de quelques options. Pour une liste des codes pays, inspirez vous du menu déroulant de cette page.
Demo en ligne ici : Tarif-Colis.info
It uses js_flattenparams to allow you to create params for the custom type as an array, see usage.
//Its a custom type : you need to create a type,
//then use the ->price method to get the price
//nlle calédonie, tarif économique
var('moncolis') = laposte(-weight='3.23',-cc='NC',-eco);
$monenvoi->price;
//france recommandé R2
var('monenvoi') = laposte(-weight='3.23',-cc='F',-rec='R2');
$monenvoi->price;
//using js_flattenparams facility
var('colis') = array( -weight = client_param('poids'),
-cc = client_param('pays'));
client_param('eco') == 'yes'? $ colis->(insert:-eco='');
laposte($colis)->price;
Country codes used are standard, except 'F' for France.
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_type(
'laposte',
-description='Tarifs d\'expédition de la poste'
);
// flatten arrays passed as params
local: 'flattenedparams' = js_flattenparams: params;
// replace the current params with the flattened params
params = #flattenedparams -> params;
// autocreate locals from params
locals = #flattenedparams -> locals;
local(
'cookiejar' = map,
'debug' = string,
'price' = decimal,
);
define_tag(
'oncreate',
-req='weight',
-req='cc',
-optional='rec',
-optional='eco',
-optional='cr'
);
local('jsessionid') = string;
local('category') = string;
local('om') = array('GP','GF','MQ','YT','NC','PF','RE','PM','WF');
local('rf') = #om;
#rf->(insert:'F');
select(true);
case(#cc == 'F');
#category = string('8N'); //Colissimo normal
case(#om >> #cc);
#category = string('8Y'); //Colissimo OM
case;
#category = string('CC'); // Colissimo international
/select;
//si -eco et international, c'est un international economique
local_defined('eco') && #category == 'CC' ? local('category') = string('CE');
//si -eco et OM, c'est un Colissimo OM economique
local_defined('eco') && #om >> #cc ? local('category') = string('XE');
//recommandé France
local_defined('rec') && #cc == 'F' ? local('category') = string('8U');
//recommandé Outre-Mer
local_defined('rec') && #om >> #cc ? local('category') = string('8Z');
fail_if(local_defined('rec')&&(#rf!>>#cc), -1, 'Erreur : Pas de recommande pour l\'international');
local('pp') = array(
'forward' = 'success',
'codeOffre' = #category,
'codePaysDestination' = #cc,
'poids' = #weight,
'page' = 'tarificationParticulier'
);
local_defined('rec')? #pp->(insert: 'choixTauxOptionObligatoire' = #rec);
///// fin config
protect;
local('page') = include_url(
'http://www.coliposte.fr/cotation/gp/tarificationParticulier.do',
-getparams = array('codeOffre'=#category),
-SendMIMEHeaders=(array:'User-Agent'='Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'),
-retrievemimeheaders='hdr',
-timeout=15
);
/protect;
local('debug_cookie_sent') = ((self->cookiejar)->values->join:'
find('Set-Cookie'), local('i'));
#i->value >> 'JSESSIONID'? #jsessionid = #i->value;
/iterate;
#jsessionid->(Replace: 'JSESSIONID=','');
#jsessionid->(Replace: 'path=/','');
//global routine for getting and updating cookiemap, should be ctagged or something
iterate($hdr->find('Set-Cookie'), local('i'));
local('debug_cookie_rcvd') += (#i->value)+'
';
//we are given an array of cookies statements
local('ivalue') = (#i->value)->(split:';');
// this way for each of each cookie statement , we get an array like this:
// array ((NAME=VALUE),(Domain=.example.com),(/Path=/),(Expires:....))
local('valuename') = ((#ivalue->Get:1)->(split:'='))->First;
(self->cookiejar)->(insert: #valuename = #i->value);
//we update the cookiejar map, and the key is the value of the cookie
//limitations is that we don't care about domains so this is only for a single-domain transaction
/iterate;
self->debug += '1. Calling first page to get a cookie
'
'
Cookie sent :
'#debug_cookie_sent'
'
'Cookie received :
'#debug_cookie_rcvd'
'
'Cookie stored :
'((self->cookiejar)->values->join:'
')'
'
//'HTML :
'#page'
'
;
////////////step (2)
protect;
local('page2') = include_url('http://www.coliposte.fr/cotation/gp/tarificationParticulier.do;jsessionid='+#jsessionid,
-postparams = #pp,
-SendMIMEHeaders=(array:'User-Agent'='Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11', 'Cookie'=((self->cookiejar)->values->join:';')),
-retrievemimeheaders='hdr',
-timeout=15
);
/protect;
local('debug_cookie_sent') = ((self->cookiejar)->values->join:'
');
iterate($hdr->find('Set-Cookie'), local('i'));
local('debug_cookie_rcvd') += (#i->value)+'
';
local('ivalue') = (#i->value)->(split:';');
local('valuename') = ((#ivalue->Get:1)->(split:'='))->First;
(self->cookiejar)->(insert: #valuename = #i->value);
/iterate;
#page2->(replace:'\r\n', '');
#page2->(replace:'\t', '');
#page2->(replace:' ', '');
local('data') = #page2->(ExportString: 'iso-8859-1');
local('computed_price')=(String_FindRegExp: #data, -Find='resest:(.*?)€*', -IgnoreCase);
self->debug += '
2. POST results
'
'POST params passed : '#pp'
'
'Cookie sent :
'#debug_cookie_sent'
'
'Cookie received :
'#debug_cookie_rcvd'
'
'Cookie stored :
'((self->cookiejar)->values->join:'
')'
'
//'HTML :
'encode_html(#data)'
'
'Prix :
'#computed_price'
'
;
local('final_price') = decimal(#computed_price->Get:2);
decimal(#final_price);
local_defined('cr')? #final_price = (#final_price + 11.72);
self->price = #final_price;
/define_tag;
/define_type;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft