Example #1
0
function port($type = 0, $_pays = false, $_cpostal = "")
{
    if ($_SESSION['navig']->commande->transport == "" && !$type) {
        return -1;
    }
    if ($_SESSION['navig']->adresse != 0) {
        $chadr = 1;
    } else {
        $chadr = 0;
    }
    $modules = new Modules();
    if (!$type) {
        $modules->charger_id($_SESSION['navig']->commande->transport);
    } else {
        $modules->charger_id($type);
    }
    if ($modules->type != Modules::TRANSPORT || !$modules->actif) {
        return -1;
    }
    $p = new Pays();
    if ($chadr) {
        $adr = new adresse();
        $adr->charger($_SESSION['navig']->adresse);
        $p->charger($adr->pays);
        $cpostal = $adr->cpostal;
    } else {
        $p->charger($_SESSION['navig']->client->pays);
        $cpostal = $_SESSION['navig']->client->cpostal;
    }
    // Prise en compte des infos passée, si aucune des infos précédentes n'est pertinente.
    if (empty($p->id) && $_pays) {
        $p->charger($_pays);
    }
    if (empty($cpostal) && $_cpostal != "") {
        $cpostal = $_cpostal;
    }
    $zone = new Zone();
    $zone->charger($p->zone);
    try {
        $port = ActionsModules::instance()->instancier($modules->nom);
        $port->nbart = $_SESSION['navig']->panier->nbart();
        $port->poids = $_SESSION['navig']->panier->poids();
        $port->total = $_SESSION['navig']->panier->total();
        $port->zone = $p->zone;
        $port->pays = $p->id;
        $port->unitetr = $zone->unite;
        $port->cpostal = $cpostal;
        $frais = $port->calcule();
        ActionsModules::instance()->appel_module("port", $frais);
        return $frais;
    } catch (exception $e) {
        return -1;
    }
}