osCommerce France : Accueil Forum Portail osCommerce France Réponses aux questions Foire aux contributions

Bienvenue invité ( Connexion | Inscription )

> Adaptation Excel Import, besoin d'aide svp !
Pipo
posté 25 Sep 2004, 11:10
Message #1


Ceinture verte OSC
Icône de groupe

Groupe : Membres
Messages : 545
Inscrit : 22-February 04
Lieu : Var 83
Membre no 2021



Bonjour,
je suis en train d'essayer d'adapter la contrib excel/import a mes besoins mais j'ai deux petits problemes que j'arrive pas a solutionner :

1-j'ai rajouté un champs pour pouvoir mettre mes keywords (de la contrib header tags). Quand c'est un nouveau produit, aucun probleme, toutes les infos sont enregistrées dans la base, par contre c'est au niveau de la mise a jour que ca marche pas ! Les keywords ne sont pas mise a jour si je les change, ni si je les supprime.

2-encore un pb avec les keyword ! lorsque je saisie mes mot clés sous excel, je les separent avec des virgules mais dans l'admin ils sont séparés par des points !
Voici le code :
CODE

<?php

function print_el( $item2 ) {
  echo " | " . substr($item2, 0, 10);
};

function print_el1( $item2 ) {
  echo sprintf("| %'.4s ", substr($item2, 0, 80));
#  echo " | " . substr($item2, 0, 80);
};


function write_tree ( $parent, $space, $lang ){
   $result = tep_db_query('SELECT categories.categories_id, categories_description.categories_name FROM categories,categories_description WHERE ((categories.categories_id = categories_description.categories_id) AND (language_id = '. $lang .') AND (parent_id = "'. $parent . '")) ORDER BY categories_name');
   while($row = tep_db_fetch_array($result)) {
   echo $space;
   array_walk($row, 'print_el1');
   echo "<br>";
   write_tree($row['categories_id'], $space . "----", $lang);
   };
};

function update_tree ( $parent,  $lang ){
   global $rootval;
   $result = tep_db_query('SELECT categories.parent_id, categories.categories_root, categories.categories_id, categories_description.categories_name FROM categories,categories_description WHERE ((categories.categories_id = categories_description.categories_id) AND (language_id = '. $lang .') AND (parent_id = "'. $parent . '")) ORDER BY categories_name');
   while($row = tep_db_fetch_array($result)) {
   if ($row['parent_id'] == 0) {
    $rootval = $row['categories_id'];
    };
   $result_upd = tep_db_query('UPDATE categories SET categories_root='. $rootval . ' WHERE categories_id=' . $row['categories_id']);
   update_tree($row['categories_id'], $lang);
   };
};

function walk( $item1 ) {
  $item1 = str_replace('";',';',$item1);
  $item1 = str_replace(';"',';',$item1);
  $item1 = str_replace('""','"',$item1);
  $item1 = str_replace(',','.',$item1);
  $item1 = str_replace("\n",'',$item1);
  $item1 = str_replace('"','\"',$item1);
  $item1 = str_replace("'",'\"',$item1);
 
  $item1 = chop($item1);

  $items = explode(";", $item1);
 
  if (isset($items[0]) == false) {$items[0]='';};
  if (isset($items[1]) == false) {$items[1]='';};
  if (isset($items[2]) == false) {$items[2]='';};
  if (isset($items[3]) == false) {$items[3]='';};
  if (isset($items[4]) == false) {$items[4]='';};
  if (isset($items[5]) == false) {$items[5]='';};
  if (isset($items[6]) == false) {$items[6]='';};
  if (isset($items[7]) == false) {$items[7]='';};
  if (isset($items[8]) == false) {$items[8]='';};
  if (isset($items[9]) == false) {$items[9]='';};
  if (isset($items[10]) == false) {$items[10]='';};
  if (isset($items[11]) == false) {$items[11]='';};
  if (isset($items[12]) == false) {$items[12]='';};
  if (isset($items[13]) == false) {$items[13]='';};
  if (isset($items[14]) == false) {$items[14]='';};

  $v_products_image        = $items[0];
  $v_products_model        = $items[1];
  $v_categories_id         = $items[2];
  $v_products_name_u       = $items[3];
  $v_products_description_u= $items[4];
  $v_products_cost         = $items[5];
  $v_products_price        = $items[6];
  $v_products_weight       = $items[7];
  $v_date_avail            = $items[8];
  $v_category_root         = $items[9];
  $v_tax_class_id          = $items[10];
  $v_products_quantity     = $items[11];
  $v_products_garantie      = $items[12];
  $v_manufacturers_id      = $items[13];
  $v_products_head_keywords_tag      = $items[14];
 
#   $v_products_weight = doubleval ($v_products_weight);
  if ($v_tax_class_id == '') {$v_tax_class_id = 1;}
  if ($v_products_quantity == '') {$v_products_quantity = 1000;}
  if ($v_products_quantity == ' ') {$v_products_quantity = 1000;}
  if ($v_products_garantie == '') {$v_products_garantie = 1;}
  if ($v_products_cost == '') {$v_products_cost = 0;}
  //if ($v_products_head_keywords_tag == '') {$v_products_head_keywords_tag = $v_products_name_u;}
 
  $error = tep_db_query('SELECT * FROM categories WHERE categories_root="'.$v_category_root.'" AND categories_id="'.$v_categories_id.'"');
 
  if (($v_products_model != "") AND (tep_db_num_rows($error) != 0)) {
#   products_model exists!
   array_walk($items, 'print_el');
   
#   echo '"'.$v_products_quantity.'"';
#   1st. Find the prodID by category_root

   $result = tep_db_query('SELECT
                           products_to_categories.products_id,
                           products_to_categories.categories_id,
                           categories.categories_root,
                           categories.categories_id,
                           categories.categories_image,
                           products.*
                           FROM categories,products_to_categories,products
                           WHERE (
                           (products_to_categories.categories_id=categories.categories_id) AND
                           (products_to_categories.products_id=products.products_id) AND
                           (categories_root="'.$v_category_root.'") AND
                           (products.products_model="'.$v_products_model.'") AND
                           (products_to_categories.categories_id="'.$v_categories_id.'"))');
                           
#   in any case, I'll need to insert line in p_to_c
   if (tep_db_num_rows($result) == 0) {
#   echo "Zero records!";
#   But if product exist in other categories, we can add it in new too...
   $res1 = tep_db_query('SELECT
                           products_to_categories.products_id,
                           products_to_categories.categories_id,
                           categories.categories_root,
                           categories.categories_id,
                           categories.categories_image,
                           products.*
                           FROM categories,products_to_categories,products
                           WHERE (
                           (products_to_categories.categories_id=categories.categories_id) AND
                           (products_to_categories.products_id=products.products_id) AND
                           (categories_root="'.$v_category_root.'") AND
                           (products.products_model="'.$v_products_model.'")) LIMIT 1');
   if (tep_db_num_rows($res1) != 0) {
#    echo "Good! I found it!";
   $row =  tep_db_fetch_array($res1);
   $prod_id = $row['products_id'];
#    echo "It number is";
#    echo $prod_id;
   $res1 = tep_db_query('INSERT INTO products_to_categories (products_id, categories_id) VALUES ("' . $prod_id . '", "' . $v_categories_id . '")');
#   And restart Query
   $result = tep_db_query('SELECT
                           products_to_categories.products_id,
                           products_to_categories.categories_id,
                           categories.categories_root,
                           categories.categories_id,
                           categories.categories_image,
                           products.*
                           FROM categories,products_to_categories,products
                           WHERE (
                           (products_to_categories.categories_id=categories.categories_id) AND
                           (products_to_categories.products_id=products.products_id) AND
                           (categories_root="'.$v_category_root.'") AND
                           (products.products_model="'.$v_products_model.'") AND
                           (products_to_categories.categories_id="'.$v_categories_id.'"))');
   }
   }


#%  $result = tep_db_query("SELECT * FROM products WHERE (products_model = '". $v_products_model . "')");
   
   if (tep_db_num_rows($result) == 0)  {
#   insert into products
   echo " !Nouveau produit!";
   if ($v_date_avail == '') {
#    echo "1st";
   $query = 'INSERT INTO products (products_image, products_model, products_cost, products_price, products_status, products_date_added, products_date_available, products_tax_class_id, products_weight, products_quantity, products_garantie, manufacturers_id)
                           VALUES ("' . $v_products_image . '", "'
                                      . $v_products_model . '", "'
                                      . $v_products_cost . '", "'
                                      . $v_products_price . '", 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,"'
                                      . $v_tax_class_id . '", "'
                                      . $v_products_weight .'", "'
                                      . $v_products_quantity .'", "'
                                      . $v_products_garantie .'", "'
                                      . $v_manufacturers_id.'")';
#    echo $query;
   $result = tep_db_query($query);
   
   } else {
#    echo "2st";
   $query = 'INSERT INTO products (products_image, products_model, products_cost, products_price, products_status, products_date_added, products_date_available, products_tax_class_id, products_weight, products_quantity, products_garantie, manufacturers_id)
                           VALUES ("' . $v_products_image . '", "' . $v_products_model . '", "'. $v_products_cost .'","' . $v_products_price . ', "1", CURRENT_TIMESTAMP, "'.$v_date_avail.'", "'.$v_tax_class_id.'", "'.$v_products_weight.'", "'.$v_products_quantity.'", "'.$v_products_garantie.'", "'.$v_manufacturers_id.'")';
#    echo $query;
   $result = tep_db_query($query);
   };
   
#%  $result = tep_db_query("SELECT * FROM products WHERE ((products_image = '". $v_products_image . "') AND (products_model = '". $v_products_model . "') AND (products_price = '" . $v_products_price . "'))");

#   Get new, inserted product.
   $result = tep_db_query("SELECT MAX(Y.products_id) max FROM products Y");
   $row =  tep_db_fetch_array($result);
   $max_prod_id = $row['max'];

   $result = tep_db_query('SELECT * FROM products WHERE (products_id="'.$max_prod_id.'")');
   $row =  tep_db_fetch_array($result);
   $prod_id = $row['products_id'];
   
#   insert into products_to_categories
   $result = tep_db_query('INSERT INTO products_to_categories (products_id, categories_id) VALUES ("' . $prod_id . '", "' . $v_categories_id . '")');

#   insert into products_description
   if ($v_products_name_u != '') {
   $result = tep_db_query("INSERT INTO products_description (products_id, language_id, products_name, products_description, products_head_keywords_tag)
                           VALUES ('" . $prod_id . "', '4', '" . $v_products_name_u . "', '". $v_products_description_u . "', '".$v_products_head_keywords_tag. "')");}

   } else {
   echo "Produits mis à jour";
   $row =  tep_db_fetch_array($result);
   $prod_id = $row['products_id'];

   if ($v_date_avail == '') {
   $result = tep_db_query('UPDATE products SET products_price="'.$v_products_price.
                          '",products_cost="'.$v_products_cost.
                          '",products_image="'.$v_products_image.
                          '",products_weight="'.$v_products_weight.
                           '",products_garantie="'.$v_products_garantie.
                          '",manufacturers_id="'.$v_manufacturers_id.
                          '",products_tax_class_id="'.$v_tax_class_id.
                          '",products_date_available=CURRENT_TIMESTAMP,products_quantity="'.$v_products_quantity.
                          '" WHERE (products_id = "'. $prod_id . '")');
   } else {
   $query = 'UPDATE products SET products_price="'.$v_products_price.
            '" ,products_cost="'.$v_products_cost.
            '" ,products_image="'.$v_products_image.
            '" ,products_weight="'.$v_products_weight.
            '" ,products_tax_class_id="'.$v_tax_class_id.
            '" ,products_date_available="'.$v_date_avail.
            '" ,products_quantity="'.$v_products_quantity.
            '" ,products_garantie="'.$v_products_garantie.
            '" ,manufacturers_id="'.$v_manufacturers_id.
            '" WHERE (products_id = "'. $prod_id . '")';
   $result = tep_db_query($query);
   };
#   insert into products_description

   if ($v_products_name_u != '') {
   $result = tep_db_query('UPDATE products_description '.
                          'SET products_name="'.$v_products_name_u.'"'.
                          ', products_description="'.$v_products_description_u.'"AND "'.$v_products_head_keywords_tag.'" WHERE ((products_id='.$prod_id.') AND (language_id = 4))');}

#   insert into products_to_categories
   $result = tep_db_query('SELECT * FROM products_to_categories WHERE ((products_id="' . $prod_id . '") AND (categories_id="' . $v_categories_id . '"))');
   if (tep_db_num_rows($result) == 0)  {
   $result = tep_db_query('INSERT INTO products_to_categories (products_id, categories_id) VALUES ("' . $prod_id . '", "' . $v_categories_id . '")');
   echo ", but added to another category!";
   };
   };
   echo "<br>";
  } else {
  array_walk($items, 'print_el');
  echo "<p class=smallText>No products_model field in record or incorrect root for category. I cannot import this record! <br>";
  echo "<br>";
  };
};

if (is_uploaded_file($usrfl))
{
echo "<p class=smallText>";
echo "File uploaded. <br>";
echo "Temporary filename: " . $usrfl . "<br>";
echo "User filename: " . $usrfl_name . "<br>";
echo "Size: " . $usrfl_size . "<br>";

$readed = file($usrfl);
unset( $readed[0] );
array_walk($readed, 'walk');

echo "Les produits ont été ajouté au catalogue!</p>";
} else {
 if ($HTTP_GET_VARS['param'] == "fr") {
    write_tree(0,"",4);
#    $result = tep_db_query("SELECT categories_id,categories_name FROM categories_description WHERE (language_id = 4) ORDER BY categories_name");
#    while($row = tep_db_fetch_array($result)) {
#    array_walk($row, 'print_el1');
#    echo "<br>";    }
 };

// if ($HTTP_GET_VARS['param'] == "eng") {
 //  write_tree(0,"",1);
#    $result = tep_db_query("SELECT categories_id,categories_name FROM categories_description WHERE (language_id = 1) ORDER BY categories_name");
#    while($row = tep_db_fetch_array($result)) {
#    array_walk($row, 'print_el1');
#    echo "<br>";       }
// };
 $rootval = 0;
 update_tree(0,1);
 update_tree(0,4);
 echo "You can import file from Excel to MySQL. Save the Excel file as CSV (Comma Delimited - option when you save an excel file) and then upload.
 The file has to be CSV format.<br>";
 echo "Version 1.51 <br>";
 echo "<br>";
 echo 'Voir les codes categorie et les codes root : <a href="excel.php?param=fr">Francais</a> ';
};
?>


Merci de votre aide !
@+
Pipo


--------------------
MS2FR

user posted image
Go to the top of the page
 
 
Start new topic
Réponse(s) (1 - 7)
isnogood
posté 25 Sep 2004, 11:33
Message #2


Ceinture noire OSC
Icône de groupe

Groupe : Membres
Messages : 2045
Inscrit : 22-February 04
Membre no 2022





Pour ton second problème, c'est sûrement cette instruction qui se change la virgule :

CODE
$item1 = str_replace(',','.',$item1);



Par contre je trouve bizarre ce bon de code :

CODE
$result = tep_db_query('UPDATE products_description '.
                         'SET products_name="'.$v_products_name_u.'"'.
                         ', products_description="'.$v_products_description_u.'"AND "'.$v_products_head_keywords_tag.'" WHERE ((products_id='.$prod_id.') AND (language_id = 4))');}


Moi, j'aurais plutôt codé :

CODE
$result = tep_db_query('UPDATE products_description '.
                         'SET products_name="' . $v_products_name_u . '"' .
                         ', products_description="' . $v_products_description_u . '" .
                         ', products_head_keywords_tag="' . $v_products_head_keywords_tag . '" .
                         '" WHERE ((products_id=' . $prod_id . ') AND (language_id = 4)) ');}
Go to the top of the page
 
isnogood
posté 25 Sep 2004, 11:43
Message #3


Ceinture noire OSC
Icône de groupe

Groupe : Membres
Messages : 2045
Inscrit : 22-February 04
Membre no 2022





Il faudrait se la faire confirmer par les pros du référencement, mias je crois que tu peux séparer des mots-clés soit par des virgules soit par des blancs.

A confirmer cependant.
Go to the top of the page
 
Pipo
posté 25 Sep 2004, 11:46
Message #4


Ceinture verte OSC
Icône de groupe

Groupe : Membres
Messages : 545
Inscrit : 22-February 04
Lieu : Var 83
Membre no 2021



humm !
ca passe pas non plus, parse error !
CODE

Parse error: parse error, unexpected '=' in c:\web\easyphp1-7\www\projet\admin\excel.php on line 269



--------------------
MS2FR

user posted image
Go to the top of the page
 
isnogood
posté 25 Sep 2004, 11:48
Message #5


Ceinture noire OSC
Icône de groupe

Groupe : Membres
Messages : 2045
Inscrit : 22-February 04
Membre no 2022



CODE
$result = tep_db_query('UPDATE products_description '.
                        'SET products_name="' .
                        $v_products_name_u .
                        '"' .
                        ', products_description="' .
                        $v_products_description_u .
                        '" .
                        ', products_head_keywords_tag="' .
                        $v_products_head_keywords_tag .
                        '" WHERE ((products_id=' . $prod_id . ') AND (language_id = 4)) ');}
Go to the top of the page
 
Pipo
posté 25 Sep 2004, 12:12
Message #6


Ceinture verte OSC
Icône de groupe

Groupe : Membres
Messages : 545
Inscrit : 22-February 04
Lieu : Var 83
Membre no 2021



Désolé isnoggod mais ca passe toujours pas !
si ca peut t'aider voila le code d'origine :
CODE

   $result = tep_db_query('UPDATE products_description '.
                          'SET products_name="'.$v_products_name_u.'"'.
                          ', products_description="'.$v_products_description_u.'" WHERE ((products_id='.$prod_id.') AND (language_id = 4))');}

merci !


--------------------
MS2FR

user posted image
Go to the top of the page
 
Pipo
posté 25 Sep 2004, 12:20
Message #7


Ceinture verte OSC
Icône de groupe

Groupe : Membres
Messages : 545
Inscrit : 22-February 04
Lieu : Var 83
Membre no 2021



Je viens de tester autre chose qui a l'air de passer :
CODE

   if ($v_products_name_u != '') {
   $result = tep_db_query('UPDATE products_description '.
                          'SET products_name="'.$v_products_name_u.'"'.
                          ', products_description="'.$v_products_description_u.'" WHERE ((products_id='.$prod_id.') AND (language_id = 4))');}

   if ($v_products_name_u != '') {
   $result = tep_db_query('UPDATE products_description '.
                          'SET products_name="'.$v_products_name_u.'"'.
                          ', products_head_keywords_tag="'.$v_products_head_keywords_tag.'" WHERE ((products_id='.$prod_id.') AND (language_id = 4))');}

je sais pas si c'est dans les normes mais ca marche !
merci pour ton aide !
Par contre pour régler le second pb que dois je faire en fait ?


--------------------
MS2FR

user posted image
Go to the top of the page
 
Pipo
posté 25 Sep 2004, 12:26
Message #8


Ceinture verte OSC
Icône de groupe

Groupe : Membres
Messages : 545
Inscrit : 22-February 04
Lieu : Var 83
Membre no 2021



Ok c'est bon j'ai trouvé pour le second pb, j'ai juste commenté la ligne !
merci de ton aide !
@+
Pipo


--------------------
MS2FR

user posted image
Go to the top of the page
 

Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



RSS Version bas débit Nous sommes le : 29th March 2024 - 12:38
Ce site est déclaré auprès de la commision Nationale
de l'Informatique et des Libertés (déclaration n°: 1043896)