|
|||
|
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 |
|
|||
|
Zitat:
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) |
|
|||
|
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 |
|
|||
|
Zitat:
2. require('includes/application_top.php'); Und zwar das application_top.php im Adminbereich (admin/includes/application_top.php). Gru? Hen |
|
|||
|
Code:
1054 - Unknown column 'einfuegen_produkt' in 'field list' select einfuegen_produkt from admin_access where customers_id = '1' [XT SQL Error] 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));
}
Gru? Hen |
|
||||
|
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'];
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'; Ich entschuldige mich f?r meine Blindheit, m?chte Euch auch nicht weiter damit nerven, bitte lediglich um den finalen Hinweis. Puh, earchy |
|
|||
|
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 |
![]() |
| Lesezeichen |
| Stichworte |
| artikel, direkt, schreiben |
| Themen-Optionen | |
| Ansicht | |
|
|