#1 (permalink)  
Alt 27.08.2005, 21:46
 
Registriert seit: 15.05.2005
Beiträge: 3
Standard

Moin Moin alle zusammen !

Ich hab das forum schon einige male durchsucht, jedoch leider nichts gefunden, darum frage ich hier nun mal kurz nach vielleicht kann mir jemand helfen.

Ich m?chte gerne per script Artikel direkt in die SQL DB schreiben.

Welche Tabellen mu? ich mindestens beschreiben damit der Artikel im Shop auftaucht ?

Ich hoffe das mit einer von Euch Spezi?s helfen kann.


VIelen dank im vorraus
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #2 (permalink)  
Alt 27.08.2005, 22:01
Erfahrener Benutzer
 
Registriert seit: 08.03.2005
Ort: Mußtopp
Beiträge: 638
Standard

Zitat:
Originally posted by mac20@Aug 27 2005, 09:46 PM
Ich m?chte gerne per script Artikel direkt in die SQL DB schreiben.

Welche Tabellen mu? ich mindestens beschreiben damit der Artikel im Shop auftaucht ?
TABLE_PRODUCTS
TABLE_PRODUCTS_TO_CATEGORIES
TABLE_PRODUCTS_DESCRIPTION
ggf. TABLE_CUSTOMERS_STATUS

Hatte auch ein Importproblem und habe mir eine Importroutine zusammengeschustert. Dem existierenden Code entnommen. Nat?rlich alles ohne Gew?hr. Jedenfalls bei mir scheints zu funktionieren.



Code:
/* ----------------------------------------------------------------------------------------------------
 funktion einfuegen_produkt Neuen Artikel in DB einfuegen
 Parameter:        $daten - Assoziatives Array
                  $daten['artnr']
                  $daten['artname']
                  $daten['artpreis']
                  $daten['artbeschr']
                  $daten['artgewicht']
                  $daten['artimage']  - Dateiname Produktillustration
 Return:              immer TRUE
                  (unfertig: eigentlich TRUE wenn alles geklappt hat, anonsten FALSE)
 Bemerkung:            Die Bilddatei $daten['artimage'] muss im Ordner f?r Originalbilder
                  (Define: DIR_FS_CATALOG_ORIGINAL_IMAGES) vorliegen
                  Schreibt nur deutschsprachige Artikelbeschreibungen ( $language_id=2 ) in DB
  ---------------------------------------------------------------------------------------------------- */
function einfuegen_produkt($daten) {
 $artnr    = strtoupper($daten['artnr']);
 $artname   = $daten['artname'];
 $artpreis  = strtoval($daten['artpreis']);
 $artbeschr  = $daten['artbeschr'];
 $artgewicht = strtoval($daten['artgewicht']);
 $artimage  = $daten['artimage'];

 $language_id = 2;

 $products_tax_class_id     = 0;
 $products_status        = 1;
 $info_template         = "default";
 $options_template       = "default";
 $fsk18             = 0;

 $current_category_id      = 0;

 $products_model    = $artnr;
 $products_price    = $artpreis;
 $products_weight   = $artgewicht;
 $products_image_name = $artimage;

 $products_name        = $artname;
 $products_description     = str_replace(',', ',
', $artbeschr);
 $products_short_description  = $artbeschr;
 $products_url         = '';
 $products_meta_title     = '';
 $products_meta_description  = '';
 $products_meta_keywords    = '';

 // Pruefen ob Artikelnummer bereits vorhanden
 $query = "select count(products_model)";             // zaehlen wie Artnr oft schon in DB
 $query.= " FROM ".TABLE_PRODUCTS;
 $query.= " WHERE products_model='$artnr'";
 $result = xtc_db_query($query);
 $result_arr = xtc_db_fetch_array($result);
 if( $result_arr['count(products_model)']>0 ) {             // wenn Artnr schon vorhanden
  echo "Fehler, Artnr. schon vohanden
\n";
  return FALSE;
 }


 if (PRICE_IS_BRUTTO=='true') {
  $products_price = ($products_price/(xtc_get_tax_rate($products_tax_class_id)+100)*100);
 }


 $products_id = xtc_db_prepare_input($_GET['pID']);
 $products_date_available = xtc_db_prepare_input($_POST['products_date_available']);

 $products_date_available = (date('Y-m-d') < $products_date_available) ? $products_date_available : 'null';

     // set allowed c.groups
 $group_ids='';
 $customers_statuses_array=xtc_get_customers_statuses();
 $sql_data_array = array(
             'products_quantity' => '',
             'products_model' => xtc_db_prepare_input($products_model),
             'products_price' => xtc_db_prepare_input($products_price),
             'products_sort' => '',
             'group_ids'=>$group_ids,
             'products_shippingtime' => '',
             'products_discount_allowed' => '',
             'products_date_available' => $products_date_available,
             'products_weight' => xtc_db_prepare_input($products_weight),
             'products_status' => xtc_db_prepare_input(products_status),
             'products_tax_class_id' => xtc_db_prepare_input($products_tax_class_id),
             'product_template' => xtc_db_prepare_input($info_template),
             'options_template' => xtc_db_prepare_input($options_template),
             'manufacturers_id' => '',
             'products_fsk18' => xtc_db_prepare_input($fsk18)
             );


 if( $products_image_name<>"" ) {
  $sql_data_array['products_image'] = xtc_db_prepare_input($products_image_name);

  require(DIR_WS_INCLUDES . 'product_thumbnail_images.php');
  require(DIR_WS_INCLUDES . 'product_info_images.php');
  require(DIR_WS_INCLUDES . 'product_popup_images.php');
 } else {
  $products_image_name = 'none';
 }

 if (isset($_POST['products_image']) && xtc_not_null($_POST['products_image']) && ($_POST['products_image'] != 'none')) {
  $sql_data_array['products_image'] = xtc_db_prepare_input($products_image_name);
 }

 $insert_sql_data = array('products_date_added' => 'now()');
 $sql_data_array = xtc_array_merge($sql_data_array, $insert_sql_data);
 xtc_db_perform(TABLE_PRODUCTS, $sql_data_array);           // Eintrag in Produkttabelle
 $products_id = xtc_db_insert_id();                  // ID ermitteln aus dem letzten Eintrag
                                    // Das neue Produkt in die Kategoriezuordnung eintragen
 xtc_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . $products_id . "', '" . $current_category_id . "')");

 $languages = xtc_get_languages();
 // Here we go, lets write Group prices into db
 // start
 $i = 0;
 $group_query = xtc_db_query("SELECT customers_status_id FROM " . TABLE_CUSTOMERS_STATUS . " WHERE language_id = '" . (int)$_SESSION['languages_id'] . "' AND customers_status_id != '0'");
 while ($group_values = xtc_db_fetch_array($group_query)) {
  // load data into array
  $i++;
  $group_data[$i] = array('STATUS_ID' => $group_values['customers_status_id']);
 }
 for ($col = 0, $n = sizeof($group_data); $col < $n+1; $col++) {
  if ($group_data[$col]['STATUS_ID'] != '') {
   $personal_price = xtc_db_prepare_input($_POST['products_price_' . $group_data[$col]['STATUS_ID']]);
   if ($personal_price == '' or $personal_price=='0.0000') {
    $personal_price = '0.00';
   } else {
    if (PRICE_IS_BRUTTO=='true') {
     $personal_price= ($personal_price/(xtc_get_tax_rate($_POST['products_tax_class_id']) +100)*100);
    }
    $personal_price=xtc_round($personal_price,PRICE_PRECISION);
   }

   xtc_db_query("UPDATE personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . " SET personal_offer = '" . $personal_price . "' WHERE products_id = '" . $products_id . "' AND quantity = '1'");
  }
 }
 // end
 // ok, lets check write new staffelpreis into db (if there is one)
 $i = 0;
 $group_query = xtc_db_query("SELECT customers_status_id FROM " . TABLE_CUSTOMERS_STATUS . " WHERE language_id = '" . (int)$_SESSION['languages_id'] . "' AND customers_status_id != '0'");
 while ($group_values = xtc_db_fetch_array($group_query)) {
  // load data into array
  $i++;
  $group_data[$i]=array('STATUS_ID' => $group_values['customers_status_id']);
 }
 for ($col = 0, $n = sizeof($group_data); $col < $n+1; $col++) {
  if ($group_data[$col]['STATUS_ID'] != '') {
   $quantity = xtc_db_prepare_input($_POST['products_quantity_staffel_' . $group_data[$col]['STATUS_ID']]);
   $staffelpreis = xtc_db_prepare_input($_POST['products_price_staffel_' . $group_data[$col]['STATUS_ID']]);
   if (PRICE_IS_BRUTTO=='true'){
    $staffelpreis= ($staffelpreis/(xtc_get_tax_rate($_POST['products_tax_class_id']) +100)*100);
   }
   $staffelpreis=xtc_round($staffelpreis,PRICE_PRECISION);

   if ($staffelpreis!='' && $quantity!='') {

    // ok, lets check entered data to get rid of user faults
    if ($quantity<=1)
     $quantity=2;
    $check_query=xtc_db_query("SELECT
                    quantity FROM
                    personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . "
                    WHERE products_id='". $products_id."'
                    and quantity='".$quantity."'");
      // dont insert if same qty!
    if (xtc_db_num_rows($check_query)<1) {
     xtc_db_query("INSERT INTO personal_offers_by_customers_status_" . $group_data[$col]['STATUS_ID'] . " (price_id, products_id, quantity, personal_offer) VALUES ('', '" . $products_id . "', '" . $quantity . "', '" . $staffelpreis . "')");
    }
   }
  }
 }
 $sql_data_array = array('products_name' => xtc_db_prepare_input($products_name),
             'products_description' => xtc_db_prepare_input($products_description),
             'products_short_description' => xtc_db_prepare_input($products_short_description),
             'products_url' => xtc_db_prepare_input($products_url),
             'products_meta_title' => xtc_db_prepare_input($products_meta_title),
             'products_meta_description' => xtc_db_prepare_input($products_meta_description),
             'products_meta_keywords' => xtc_db_prepare_input($products_meta_keywords) );

 $insert_sql_data = array('products_id' => $products_id,
              'language_id' => $language_id);
 $sql_data_array = xtc_array_merge($sql_data_array, $insert_sql_data);

 xtc_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);

 return true;
}

Geändert von hubbabubba (16.08.2008 um 09:40 Uhr)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #3 (permalink)  
Alt 28.08.2005, 18:56
 
Registriert seit: 15.05.2005
Beiträge: 3
Standard

Vielen Dank, das war genau das was ich gesucht habe. Manchmal braucht man nur einen kleine Sto? in die richtige Richtung
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #4 (permalink)  
Alt 06.09.2005, 14:05
dhh dhh ist offline
xt:C Sponsor
 
Registriert seit: 27.06.2005
Beiträge: 17
Standard

Hey,
scheint genau das zu sein was ich suche, darf ich das (nach einigen Erg?nzungen & Anpassungen) ebenfalls verwenden? Wie hattest du / habt ihr das eingebunden, muss ja f?r die Queries erstmal integriert sein?
Danke schonmal,
freundlichen Gru?,
Daniel Hirtzbruch
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #5 (permalink)  
Alt 06.09.2005, 21:29
Erfahrener Benutzer
 
Registriert seit: 08.03.2005
Ort: Mußtopp
Beiträge: 638
Standard

Zitat:
Originally posted by dhh@Sep 6 2005, 02:05 PM
darf ich das (nach einigen Erg?nzungen & Anpassungen) ebenfalls verwenden? Wie hattest du / habt ihr das eingebunden, muss ja f?r die Queries erstmal integriert sein?
1. Nat?rlich
2. require('includes/application_top.php');
Und zwar das application_top.php im Adminbereich (admin/includes/application_top.php).

Gru?
Hen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #6 (permalink)  
Alt 11.09.2005, 14:54
Benutzerbild von earchy  
Registriert seit: 01.02.2005
Beiträge: 21
Standard

Hallo erstamal.

Also auch ich brauche sowas, von daher erstmal danke f?r die Vorarbeit.

Ich habe mir ein Formular gestrickt, das die Parameter per "post" an die produkt_einfuegen.php ?bergibt. Doch dann kommt diese Meldung:

Code:
1054 - Unknown column 'einfuegen_produkt' in 'field list'
select einfuegen_produkt from admin_access where customers_id = '1'
[XT SQL Error]
und schon bin ich auf Glatteis.
K?nnte mich bitte jemand in die richtig Richtung schubsen!?

Danke
earchy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #7 (permalink)  
Alt 11.09.2005, 19:55
Erfahrener Benutzer
 
Registriert seit: 08.03.2005
Ort: Mußtopp
Beiträge: 638
Standard

Code:
1054 - Unknown column 'einfuegen_produkt' in 'field list'
select einfuegen_produkt from admin_access where customers_id = '1'
[XT SQL Error]
[/quote]

XTC hat ein sehr differenziertes System Zugriffe zu Administrationsfunktionen zu regeln. Gespeichert in der Tabelle "admin_access".

Du l?sst ein php-script im admin-Ordner laufen ("einfuegen_produkt.php") es gibt aber keine Entsprechung in der zugeh?rigen Datenbanktabelle. Durch die Einbindung von admin/includes/application_top.php wird auch diese Zugriffsabfrage aufgerufen.

Es gibt 2 M?glichkeiten der Abhilfe.
1. Du erweiterst die Tabelle admin_access manuell
2. Du knipst dies Zugriffskontrolle im Adminbereich aus.

1.)
F?ge der Tabelle admin_access noch eine Spalte hinzu namens "einfuegen_produkt".
Und in der Zeile worin customers_id = 1 steht setzt du auch 1 in der neuen Spalte "einfuegen_produkt".

2.)
Suche in der Datei admin/includes/application_top.php folgende Zeilen (ca. Zeile 450..480)

Code:
 if (xtc_check_permission($pagename) == '0') {
  xtc_redirect(xtc_href_link(FILENAME_LOGIN));
 }
und kommentiere sie aus.


Gru?
Hen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #8 (permalink)  
Alt 12.09.2005, 07:49
Benutzerbild von earchy  
Registriert seit: 01.02.2005
Beiträge: 21
Standard

Vielen Dank!

Das hat den Erfolg gebracht, dass die Fehlermeldung in der Tat nun weg ist.
Der gesamte Prozess l?uft jetzt glatt und ohne Fehlermeldung durch.

Nur: In der DB wird trotzdem nichts eingetragen.

Ich habe Ma?nahme 1 und sp?ter zus?tzlich Ma?nahme 2 aktiviert.
Es wird nichts eingetragen in der DB.
Bei Kontrollausgaben habe ich gemerkt, dass die Variablen?bergabe aus dem HTML Formular nicht funktioniert.

Die Variablen waren in der Kontrollausgabe jeweils leer. Sehr seltsam.

Dann habe ich mich gefragt, was dieser Code eigentlich macht:

Code:
function einfuegen_produkt($daten) {
 $artnr    = strtoupper($daten['artnr']);
 $artname   = $daten['artname'];
 $artpreis  = strtoval($daten['artpreis']);
 $artbeschr  = $daten['artbeschr'];
 $artgewicht = strtoval($daten['artgewicht']);
 $artimage  = $daten['artimage'];
Ich bin jetzt nicht der riesen PHP Kenner, aber in Java w?re $daten etwas, was der Funktion ?bergeben wird. Aber genau das passiert ja nicht. Es werden die Variablen im Poststring einzeln angeliefert und nicht ein Datenarray das getrennt werden mu?.

Also habe ich vermutlich verpasst, woher $daten eigentlich kommen!?

Dann habe ich den Test gewagt und Variablen hart verdrahtet:

Code:
$artnr = '1234567';
$artname = 'TEST LALAL';
$artpreis = '9';
$artbeschr  = 'Laber Rababer';
$artgewicht = '1';
$artimage  = 'bildi.jpg';
Und als auch diese Daten in der DB Tabelle 'products' nicht eintrafen, wu?te ich, dass ich diesen Text hier zu schreiben haben w?rde.

Ich entschuldige mich f?r meine Blindheit, m?chte Euch auch nicht weiter damit nerven, bitte lediglich um den finalen Hinweis.

Puh,
earchy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
  #9 (permalink)  
Alt 12.09.2005, 09:37
Erfahrener Benutzer
 
Registriert seit: 08.03.2005
Ort: Mußtopp
Beiträge: 638
Standard

Den finalen Hinweis kann ich dir auch nicht geben. Deine "harte Verdrahtung" ist schon ok. Ich w?rde mich jetzt ans debuggen machen. Schwer zu sagen wo's hakt.

Kann sein, da? dort noch Bugs drin sind (habe eben beim ?berfliegen selbst einen entdeckt, nichts schlimmes).

Diese Routine habe ich f?r XTC Version 2 (!) zusammengebastelt. In meiner 2er Testumgebung funktioniert sie. Sag mir erstmal welche XTC Version du verwendest.

Gru?
Hen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Wong this Post!
Mit Zitat antworten
Antwort

Lesezeichen

Stichworte
artikel, direkt, schreiben

Themen-Optionen
Ansicht

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are aus
Pingbacks are aus
Refbacks are aus



Alle Zeitangaben in WEZ +1. Es ist jetzt 04:37 Uhr.

Copyright © 2011 xt:Commerce GmbH / xt:Commerce International Ltd. - All Rights Reserved

xt:Commerce is a SafeCharge brand