[eluser]Louis![/eluser]
The code is :
Code:
<? function addNdd(){
$ndd = $this->input->post('ndd');
$extension = $this->input->post('extension');
$etat = $this->input->post('etat');
$this->load->library('cart');
$cart =& Cart::getInstance();
$type = ($etat==1) ? "commande":"transfert";
$o = FabriqueItem::create('ndd',array('ndd'=>$ndd.'.'.$extension,'tps'=>12,'type'=>$type));
$prix = $this->devise->getAmount($this->mdl_domaine->getPrix($extension));
$result = ($cart->addArticle($o));
if($result){
$xml = '<racine><resultat reponse="addNdd" ndd="'.$ndd.'.'.$extension.'" prix="'.$prix.'">true</resultat><description>'.$o->getNdd()." ".$o->getType()." - ".$this->devise->getPrice($o->getPrix()).' - '.$o->getTps().' mois</description></racine>';
} else
$xml = '<resultat reponse="addNdd">false</resultat>';
$data['xml'] = utf8_encode($xml);
log_message('debug', $xml);
$this->load->view('ajax/display',$data);
}?>
The code which create the object :
Code:
class ItemNdd extends Item {
var $ndd='';
var $type='';
function ItemNdd($ndd,$tps,$type){
parent::Item($tps);
$this->ndd = $ndd;
$this->type = $type; // achat ou transfert
$this->prix = $this->CI->mdl_domaine->getPrix($this->CI->mdl_domaine->getExtension($this->ndd));
}
function getNdd(){
return $this->ndd;
}
function equals($object){
if(!($object instanceof ItemNdd)) return false;
if($this->ndd==$object->ndd) return true;
return false;
}
function toString(){
return "<br>Nom de domaine : ".$this->ndd.
"<br> Durée : ".$this->getTps()." mois <br>Prix :".$this->prix;
}
function save($id_commande){
$data = array(
'id_item'=>'',
'id_commande'=>$id_commande,
'type'=>'ndd',
'titre'=>$this->type.' nom de domaine : '.$this->ndd,
'nbre_mois'=>parent::getTps(),
'prix'=>$this->CI->devise->getAmount($this->prix),
'date'=>date('Y-m-d H:i:s'));
$this->CI->db->insert('items',$data);
}
The library Cart what i use has developed by me.