Romain54 Posted February 5, 2013 Share Posted February 5, 2013 Bonjour, Voila j'ai créer un module pour importer le catalogue d'un de mes fournisseur, tout fonctionne correctement les catégories et les sous-catégories s'ajoute parfaitement, le manufacturer s'ajoute correctement, et les produit s'ajouter aussi dans la table du module, seul probléme ces que quand les produits s'ajoute il s'ajoute tous avec comme product id "0" et ne s'ajoute pas dans la table ps_product donc forcement n'apparaise pas sur mon front office. Voicie le code : public function getMakantData( $filename, $jcateg = FALSE ) { $i = 0; if( $jcateg == FALSE ) { if (($handle = fopen($filename, "r")) !== FALSE) { while(( $tmp = fgetcsv($handle, 0, ";" )) !== FALSE ) { if( $i > 0 ) { $num = count($tmp); $row++; $data = array(); $cat = explode("->", utf8_encode($tmp[2])); $data['reference'] = $tmp[0]; $data['actif'] = $tmp[21]; $tmp2 = split(' ', utf8_encode($tmp[3]) ); $data['titre'] = utf8_encode($tmp[3]); $titre_prod = utf8_encode($tmp[3]); $data['famille'] = $cat[1]; $data['marque'] = utf8_encode($tmp[33]); $data['reference_fabricant'] = utf8_encode($tmp[31]); $data['ean13'] = $tmp[20]; $data['stock'] = $tmp[29]; $data['date_dispo'] = ''; $data['poids'] = $tmp[30]; $data['volume'] = 0; $data['url_photo'] = $tmp[8]; $data['prix_public'] = ''; $data['prix_revendeur'] = $tmp[7]; $data['prix_transport'] = 0; $data['prix_promo'] = 0; $data['promo'] = 0; $data['eco_participation'] = 0; $data['description'] = utf8_encode($tmp[4]); $data['parent_cat'] = $cat[0]; if( (float) $data['prix_revendeur'] == 0 ) $data['actif'] = 0; $carac_tmp = preg_split( '/\- Couleur \-|\- Taille \-|\- Tailles \-|\- Pointures \-|\- Formes \-|\- Bonnets \-/', $data['titre'] ); if( count( $carac_tmp ) <= 1 ) { if( strlen( trim( $data['reference'] ) ) == 0 || $data['reference'] == ' ' ) $data['reference'] = 'produit-'.$row; echo "Produit à la ligne $row: reference : ".$data['reference']."<br \>"; echo $data['titre'] ."<br \>"; $reference_produit = $data['reference']; } $this->insertProduct( $data ); } $i++; } } fclose($handle); $sql = Db::getInstance()->Execute('SELECT * FROM `'._DB_PREFIX_.'importfourn_product` WHERE fournisseur = \''.pSQL( $this->conf['supplier'] ).'\' '); while($aff = mysql_fetch_array($sql)) { $data = array(); $data['id'] = $aff['parent_cat']; $data['titre'] = $aff['parent_cat']; $data['pid'] = ''; $this->insertCategory( $data ); $data['id'] = $aff['famille']; $data['titre'] = $aff['famille']; $data['pid'] = $aff['parent_cat']; $this->insertCategory( $data ); $i++; } $this->_html .= '<br /><h1>'.$this->l('Categories are Updated').'</h1>'; } else { if (($handle = fopen($filename, "r")) !== FALSE) { while(( $tmp = fgetcsv($handle, 100000, ";" )) !== FALSE ) { if( $i > 0 ) { $data = array(); $cat = explode("->", utf8_encode($tmp[2])); $data['id'] = $cat[0]; $data['titre'] = $cat[0]; $data['pid'] = ''; $this->insertCategory( $data ); } $i++; } } $this->_html .= '<br /><h1>'.$this->l('Categories are Updated').'</h1>'; } } public function insertProduct( $data ) { if( strlen( $data['reference'] ) > 1 ) { $update_photo = 1; $updated = 1; $req_i = 'SELECT * FROM `'._DB_PREFIX_.'importfourn_product` WHERE fournisseur = \''.pSQL( $this->conf['supplier'] ).'\' AND reference= \''.pSQL( $data['reference'] ).'\' AND url_photo = \''.pSQL( $data['url_photo'] ).'\' '; $row = Db::getInstance()->getRow( $req_i ); if( count( $row ) > 0 && is_array($row ) ) $update_photo=0; $req_s = 'SELECT * FROM `'._DB_PREFIX_.'importfourn_product` WHERE fournisseur = \''.pSQL( $this->conf['supplier'] ).'\' AND reference= \''.pSQL( $data['reference'] ).'\''; $req_1 = 'INSERT INTO `'._DB_PREFIX_.'importfourn_product` ( fournisseur'; $req_2 =' VALUES (\''.pSQL( $this->conf['supplier'] ).'\' '; $req_3 =' ON DUPLICATE KEY UPDATE '; foreach( $data as $key => $val ) { $req_1 .= ', '.$key; $req_2 .= ', \''.pSQL( $val ).'\' '; $req_3 .= ' '.$key.' = \''.pSQL( $val ).'\', '; if( strcasecmp ( $val , $row[$key] ) !=0 ) $updated = 1; if( $key != 'date_update' && $key != 'url_photo' ) $req_s .= 'AND '.$key.' = \''.pSQL( $val ).'\' '; } $row2 = Db::getInstance()->getRow( $req_s ); if( count( $row2 ) > 0 && is_array($row2 ) ) $updated=0; $req = $req_1.', updated, updated_img ) '.$req_2.', \'1\' , \'1\' ) '.$req_3.' updated = updated+'.$updated.' , updated_img = updated_img+'.$update_photo; Db::getInstance()->execute( $req ); } } Merci d'avance pour votre aide car sa fait 5 jour que je bloque dessus sans comprendre d'ou provient le soucie. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now