| Server IP : 85.158.181.41 / Your IP : 216.73.217.12 Web Server : Apache System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64 User : moncbefd ( 1024) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/moncbefd/www.moneta.at/export/ |
Upload File : |
<?php
/*****************************************************************************
* *
* Amicron-Faktura 12 Professional Schnittstelle fuer Gambio GX 3.x *
* *
* Beschreibung : Script zum Datenaustausch Amicron-Faktura 12 Professional *
* <--> ab Gambio GX3 *
* todo: - *
* *
*****************************************************************************/
$storedpost = $_POST;
$storedfiles = $_FILES;
$_POST = [];
set_include_path(get_include_path() . PATH_SEPARATOR . '..');
include_once('includes/application_top.php');
require_once(DIR_FS_INC . 'xtc_not_null.inc.php');
require_once(DIR_FS_INC . 'xtc_redirect.inc.php');
require_once(DIR_FS_INC . 'xtc_rand.inc.php');
require_once(DIR_FS_INC . 'xtc_get_tax_rate.inc.php');
require_once(DIR_FS_INC . 'xtc_set_time_limit.inc.php');
require_once(DIR_FS_CATALOG . 'system/core/logging/LogEvent.inc.php');
require_once(DIR_FS_CATALOG . 'system/core/logging/LogControl.inc.php');
require_once(DIR_FS_CATALOG . 'gm/classes/ErrorHandler.php');
require_once(DIR_FS_CATALOG . 'inc/xtc_cleanName.inc.php');
$_POST = $storedpost;
xtc_set_time_limit(0);
define('_VALID_XTC', true);
// falls die MWST vom shop vertauscht wird, hier false setzen.
define('SWITCH_MWST', true);
// Default UTF-8
define('XMLEncoding', 'utf-8');
// ACHTUNG: diese Zeilen werden benoetigt, nichts aendern!
$version_major = 13;
$version_minor = 9;
$datum = "Aug 2021";
if (isset($_GET['NoHeader']) && $_GET['NoHeader'] != "Y") {
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // immer geaendert
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0
if (isset($_GET['FullHeader']) && $_GET['FullHeader'] == "Y") {
header("Content-type: text/xml");
}
}
$action = (isset($_POST['action']) ? $_POST['action'] : $_GET['action']);
$user = xtc_db_prepare_input(isset($_POST['user']) ? $_POST['user'] : $_GET['user']);
$password = xtc_db_prepare_input(isset($_POST['password']) ? $_POST['password'] : $_GET['password']);
$clientdebug = isset($_GET['clientdebug']);
$verge41 =
version_compare(
gm_get_conf('INSTALLED_VERSION'),
'v4.1.0') >= 0;
if (CheckLogin($user, $password)) {
$defaults = getDefaults();
define('CHARSET', $defaults['charset']);
}
switch ($action) {
// Versionsausgabe
case 'read_version':
ReadVersion();
exit;
case 'read_languages':
if (CheckLogin($user, $password)) {
ReadLanguages();
}
exit;
case 'read_categories':
if (CheckLogin($user, $password)) {
ReadCategories();
}
exit;
case 'write_artikel':
if (CheckLogin($user, $password)) {
WriteArtikel();
}
exit;
case 'add_artikel_image':
if (CheckLogin($user, $password)) {
AddArtikelImage();
}
exit;
case 'write_categorie':
if (CheckLogin($user, $password)) {
WriteCategorie();
}
exit;
case 'read_artikel':
if (CheckLogin($user, $password)) {
ReadArtikel();
}
exit;
case 'read_hersteller':
if (CheckLogin($user, $password)) {
ReadHersteller();
}
exit;
case 'write_hersteller':
if (CheckLogin($user, $password)) {
WriteHersteller();
}
exit;
case 'delete_artikel':
if (CheckLogin($user, $password)) {
DeleteArtikel();
}
exit;
case 'order_update':
if (CheckLogin($user, $password)) {
OrderUpdate();
}
exit;
case 'read_shopdata':
if (CheckLogin($user, $password)) {
ReadShopData();
}
exit;
case 'orders_export':
if (CheckLogin($user, $password)) {
ReadAuftraege();
}
exit;
default:
ReadVersion();
exit;
}
function WriteArtikel() {
global $storedpost, $storedfiles, $client, $defaults;
$post = array();
$article = array();
$languages = getLanguages();
if (isset($_GET['MapFreifeld'])) {
$MapFreifeld = $_GET['MapFreifeld'];
}
$apidebug = isset($_GET['restapidebug']);
$apilog = array();
// $_POST Daten vorbereiten
// 18.04.2017 $_POST liefert nach Einbinden von application_top.php
// bei HTML teilweise Muell, daher vorher als storedpost zwischenspeichern
foreach ($storedpost as $key => $value) {
$post[$key] = xtc_db_prepare_input($value);
}
$aID = (int) $post['Artikel_ID'];
$cmd = "SELECT products_id, products_model FROM " . TABLE_PRODUCTS .
" WHERE products_model = '{$post['Artikel_Artikelnr']}'";
$query = xtc_db_query($cmd);
if ($product = xtc_db_fetch_array($query)) {
$exists = TRUE;
$mode = 'UPDATED';
$aID = (int) $product['products_id'];
}
else {
$exists = FALSE;
$mode = 'INSERTED';
}
if (isset($post['Artikel_Lieferstatustext'])) {
$cmd = "select shipping_status_id, language_id, shipping_status_name "
. "from " . TABLE_SHIPPING_STATUS .
" where language_id = '{$defaults['LangID']}' "
. "and shipping_status_name = '{$post['Artikel_Lieferstatustext']}'";
$shipping_time_query = xtc_db_query($cmd);
if ($shipping = xtc_db_fetch_array($shipping_time_query)) {
$shipping_statusID = $shipping['shipping_status_id'];
}
else {
$cmd = "select max(shipping_status_id) as _id from " . TABLE_SHIPPING_STATUS;
$query = xtc_db_query($cmd);
if ($shipping = xtc_db_fetch_array($query)) {
$shipping['_id'] = $shipping['_id'] + 1;
}
$insert_shipping_status = array(
'shipping_status_id' => $shipping['_id'],
'language_id' => $defaults['LangID'],
'shipping_status_name' => $post['Artikel_Lieferstatustext']
);
if (xtc_db_perform(TABLE_SHIPPING_STATUS, $insert_shipping_status))
$shipping_statusID = $shipping['_id'];
}
} else {
$shipping_statusID = $post['Artikel_Lieferstatus'];
}
// Artikel-Texte ermitteln
$Artikel_Texte = array();
$i = 1;
while (isset($post["Artikel_Bezeichnung{$i}"])) {
$Artikel_Texte[$i] = array('B' => $post["Artikel_Bezeichnung{$i}"],
'T' => $post["Artikel_Text{$i}"],
'S' => $post["Artikel_Kurztext{$i}"],
'L' => (integer) $post["Artikel_TextLanguage{$i}"],
'MT' => $post["Artikel_MetaTitle{$i}"],
'MD' => $post["Artikel_MetaDescription{$i}"],
'MK' => $post["Artikel_MetaKeywords{$i}"],
'URL' => $post["Artikel_URL{$i}"]
);
$i++;
}
// Artikel-Texte zuweisen. language-code,
foreach ($languages as $key => $value) {
foreach ($Artikel_Texte as $k => $AText) {
if ($value['id'] == $AText['L']) {
$name[$value['code']] = $AText['B'];
$description[$value['code']] = $AText['T'];
$shortDescription[$value['code']] = $AText['S'];
$keywords[$value['code']] = $AText['MK'];
$metaDescription[$value['code']] = $AText['MD'];
$metaTitle[$value['code']] = $AText['MT'];
$url[$value['code']] = $AText['URL'];
}
}
}
$metaKeywords = $keywords;
// Artikel-Kategorien ermitteln
$i = 1;
$categories = array();
while (isset($post["Artikel_KategorieID{$i}"])) {
$categories[] = array('categoryId' => $post["Artikel_KategorieID{$i}"]);
$i++;
}
// Artikel-Preise ermitteln
$Artikel_Preise = array();
$i = 1;
while (isset($post["Artikelpreise_Preis{$i}"])) {
$Artikel_Preise[$i] = array('P' => (float) ($post["Artikelpreise_Preis{$i}"]),
'G' => (integer) ($post["Artikelpreise_Gruppe{$i}"]),
'M' => (integer) ($post["Artikelpreise_Menge{$i}"])
);
$i++;
}
// Artikel-Daten zuweisen
$article = array('isActive' => (boolean) $post['Artikel_Status'],
'sortOrder' => 0,
'orderedCount' => 1,
'productModel' => $post['Artikel_Artikelnr'],
'ean' => $post['Artikel_EAN'],
'price' => (float) $post['Artikel_Preis'],
// 'discountAllowed' => '',
'quantity' => (float) $post['Artikel_Menge'],
'taxClassId' => (int) $post['Artikel_Steuersatz'],
'weight' => (float) $post['Artikel_Gewicht'],
// 'shippingCosts'=>0,
'shippingTimeId' => (int) $shipping_statusID,
'productTypeId' => 1,
'manufacturerId' => (int) $post['Hersteller_ID'],
// 'isFsk18'=> '',
'name' => $name,
'description' => $description,
'shortDescription' => $shortDescription,
'keywords' => $keywords,
'metaTitle' => $metaTitle,
'metaDescription' => $metaDescription,
'metaKeywords' => $metaKeywords,
'url' => $url,
'urlKeywords' => array('en' => '', 'de' => ''),
'checkoutInformation' => array('en' => '', 'de' => ''),
"viewedCount" => array("en" => 0, "de" => 0),
'settings' => array('detailsTemplate' => 'standard.html',
'optionsDetailsTemplate' => 'product_options_dropdown.html',
'optionsListingTemplate' => 'product_options_dropdown.html',
'showOnStartpage' => (boolean) $post['Artikel_Startseite'],
// 'showQuantityInfo' => false,
'showWeight' => false,
'showPriceOffer' => false,
'showAddedDateTime' => false,
'onSitemap' => true,
"priceStatus" => 0,
"graduatedQuantity" => 1,
"minOrder" => 1,
'sitemapPriority' => '0.5',
'sitemapChangeFrequency' => 'daily',
'propertiesDropdownMode' => 'dropdown_mode_1',
'showPropertiesPrice' => false,
'usePropertiesCombisQuantity' => false,
'usePropertiesCombisShippingTime' => false,
'usePropertiesCombisWeight' => false
),
'addonValues' => array('productsImageWidth' => '',
'productsImageHeight' => ''),
);
// Artikel Grund- und Masseinheit ermitteln, zuweisen, default-Sprache
if (isset($post['Artikel_Grundeinheit']) && isset($post['Artikel_Masseinheit'])) {
$vpe_name = ($post['Artikel_Grundeinheit']) . ' ' . ($post['Artikel_Masseinheit']);
$vpe_id = 0;
$cmd = "select products_vpe_id from " . TABLE_PRODUCTS_VPE .
" where products_vpe_name='{$vpe_name}' "
. "and language_id='{$defaults['LangID']}'";
$vpe_query = xtc_db_query($cmd);
if ($vpe = xtc_db_fetch_array($vpe_query)) {
$vpe_id = $vpe['products_vpe_id'];
}
else {
$cmd = "select max(products_vpe_id) vpemax from " . TABLE_PRODUCTS_VPE;
$vpemax_query = xtc_db_query($cmd);
$vpemax = xtc_db_fetch_array($vpemax_query);
$vpe_id = $vpemax['vpemax'] + 1;
$vpe_data = array('products_vpe_id' => $vpe_id,
'products_vpe_name' => $vpe_name,
'language_id' => $defaults['LangID']
);
xtc_db_perform(TABLE_PRODUCTS_VPE, $vpe_data);
}
$article['vpeId'] = $vpe_id;
$article['isVpeActive'] = true;
$article['vpeValue'] = $post['Artikel_VPEValue'];
}
if (!$post['SkipImages']) {
if ($exists && $post['ExportModus'] == 'Overwrite') {
$articleimage = $client->get("products/$aID");
$apilog[] = $client->handleError($apidebug, false, 'ReadImages');
if (isset($articleimage['images']) && !empty($articleimage['images'])) {
foreach ($articleimage['images'] as $image) {
$ab = $client->delete("product_images", array("filename" => $image['filename']));
$apilog[] = $client->handleError($apidebug, false, 'DeleteImage');
}
}
}
if (!$exists || $post['ExportModus'] == 'Overwrite') {
if (isset($post['Artikel_Bilddatei'])) {
$imagefilename = imageWrite($storedfiles['artikel_image']['tmp_name'], $post['Artikel_Bilddatei']);
$article['images'][0]['filename'] = $imagefilename;
$article['images'][0]['isPrimary'] = true;
$article['images'][0]['isVisible'] = true;
foreach ($languages as $key => $value) {
$article['images'][0]['imageAltText'][$value['code']] = $post['Artikel_Artikelnr'];
}
}
if (isset($post['Artikel_Bilddateien'])) {
for ($i = 0, $k = 1; $i < (integer) ($post['Artikel_Bilddateien']); $i++, $k++) {
$imagefilename = imageWrite($storedfiles["artikel_images$i"]['tmp_name'], $storedfiles["artikel_images$i"]['name']);
$article['images'][$k]['filename'] = $imagefilename;
$article['images'][$k]['isPrimary'] = false;
$article['images'][$k]['isVisible'] = true;
foreach ($languages as $key => $value) {
$article['images'][$k]['imageAltText'][$value['code']] = $post['Artikel_Artikelnr'];
}
}
}
if (!isset($article['images'])) {
$article['images'] = array();
}
}
}
if (!$exists || $post['ExportModus'] == 'Overwrite') {
if (!$exists) {
$article['settings']['showQuantityInfo'] = false;
// Artikel erstellen
$data = $client->post("products", $article);
$apilog[] = $client->handleError($apidebug, true, 'WriteNewArticle');
$aID = (int) $data['id'];
}
if ($exists) {
// Artikel updaten
$data = $client->put("products/{$aID}", $article);
$apilog[] = $client->handleError($apidebug, true, 'UpdateArticle');
}
// categorie Links loeschen
$client->delete("products/{$aID}/links");
$apilog[] = $client->handleError($apidebug, true, 'DeleteArticleCategoryLink');
// categories setzen
if (isset($categories) && !empty($categories)) {
foreach ($categories as $k => $category) {
$data = $client->post("products/{$aID}/links", $category);
$apilog[] = $client->handleError($apidebug, true, 'AppendArticleCategoriyLink');
}
}
// Zusatzfelder eintragen
if (isset($MapFreifeld)) {
$afi = array();
$db = StaticGXCoreLoader::getDatabaseQueryBuilder();
$cmd =
"select " .
"additional_field_id," .
"language_id," .
"name" .
" from " .
"additional_field_descriptions";
$fd_query = xtc_db_query($cmd);
while ($fd = xtc_db_fetch_array($fd_query)) {
if (isset($MapFreifeld[$fd['name']])) {
unset($afvi);
if (isset($afi[$fd['additional_field_id']])) {
$afvi = $afi[$fd['additional_field_id']];
}
else {
$cmd =
"select " .
"additional_field_value_id" .
" from " .
"additional_field_values" .
" where " .
"additional_field_id = '" . $fd['additional_field_id'] . "'" .
" and " .
"item_id = '{$aID}'";
$fv_query = xtc_db_query($cmd);
if ($fv = xtc_db_fetch_array($fv_query)) {
$afvi = $fv['additional_field_value_id'];
$afi[$fd['additional_field_id']] = $afvi;
}
}
if (isset($afvi)) {
xtc_db_query(
"delete from " .
"additional_field_value_descriptions" .
" where " .
"additional_field_value_id = '" . $afvi . "'" .
" and " .
"language_id = '" . $fd['language_id'] . "'"
);
}
else {
$db
->insert('additional_field_values',
array(
'additional_field_id' => $fd['additional_field_id'],
'item_id' => $aID));
$afvi = $db->insert_id();
$afi[$fd['additional_field_id']] = $afvi;
}
if (isset($post['Artikel_Freifeld' . (integer)($MapFreifeld[$fd['name']])])) {
$sql_data_array = array(
'additional_field_value_id' => $afvi,
'language_id' => $fd['language_id'],
'value' => $post['Artikel_Freifeld' . (integer)($MapFreifeld[$fd['name']])]
);
xtc_db_perform('additional_field_value_descriptions', $sql_data_array);
}
}
}
}
}
// Nur Artikel-Preis(e) setzen
if (!$exists || $post['ExportModus'] == 'Overwrite' || $post['ExportModus'] == 'PriceOnly' || $post['ExportModus'] == 'PriceAndQuantityOnly') {
// if (isset($Artikel_Preise) && !empty($Artikel_Preise)) {
$cmd = "select distinct(customers_status_id) from " . TABLE_CUSTOMERS_STATUS;
$query = xtc_db_query($cmd);
while ($cs = xtc_db_fetch_array($query)) {
xtc_db_query("delete from " . TABLE_PERSONAL_OFFERS_BY . $cs['customers_status_id'] . " where products_id = '{$aID}'");
}
if (isset($Artikel_Preise) && !empty($Artikel_Preise)) {
foreach ($Artikel_Preise as $APreis) {
$sql_data_array = array('products_id' => $aID,
'quantity' => $APreis['M'],
'personal_offer' => $APreis['P']
);
xtc_db_perform(TABLE_PERSONAL_OFFERS_BY . $APreis['G'], $sql_data_array);
}
}
$client->put("products/{$aID}", array('price' => (float) $post['Artikel_Preis']));
$apilog[] = $client->handleError($apidebug, true, 'UpdateArticlePrice');
}
// Nur Artikel-Menge setzen
if (!$exists || $post['ExportModus'] == 'Overwrite' || $post['ExportModus'] == 'QuantityOnly' || $post['ExportModus'] == 'PriceAndQuantityOnly') {
$client->put("products/{$aID}", array('quantity' => (float) $post['Artikel_Menge']));
$apilog[] = $client->handleError($apidebug, true, 'UpdateArticeQuantity');
}
WriteStatus(array(
'MESSAGE' => 'OK',
'MODE' => $mode,
'ID' => $aID,
'APILog' => $apilog));
}
function AddArtikelImage() {
global $storedpost, $storedfiles, $client;
$aID = (int) $storedpost['Artikel_ID'];
$isPrimary = (boolean) $storedpost['Artikel_HauptBild'];
$apidebug = isset($_GET['restapidebug']);
$apilog = array();
try {
$imagefilename = imageWrite($storedfiles['artikel_image']['tmp_name'], $storedpost['Artikel_Bilddatei']);
} catch (\Exception $e) {
WriteStatus(array(
'MESSAGE' => $e->getMessage(),
'APILog' => $apilog));
exit;
}
$languages = getLanguages();
$article = $client->get("products/$aID");
$apilog[] = $client->handleError($apidebug, true, 'AddArtikelImage_ReadArtikel');
$image = array(
'filename' => $imagefilename,
'isPrimary' => $isPrimary,
'isVisible' => true,
'imageAltText' => array());
foreach ($languages as $key => $value) {
$image['imageAltText'][$value['code']] = $storedpost['Artikel_Artikelnr'];
};
$article['images'][] = $image;
$client->put("products/{$aID}", $article);
$apilog[] = $client->handleError($apidebug, true, 'AddArtikelImage_WriteArtikel');
WriteStatus(array(
'MESSAGE' => 'OK',
'ID' => $aID,
'Filename' => $imagefilename,
'APILog' => $apilog));
}
function ReadVersion() {
global $datum, $defaults, $client, $version_major, $version_minor;
include_once '../release_info.php';
WriteStatus(array(
'SCRIPT_DEFAULTCHARSET' => $defaults['charset'],
'INFO' => "$datum ($version_major.$version_minor) - Gambio: $gx_version - PHP: " . PHP_VERSION));
}
function ReadLanguages() {
$languageitems = getLanguages();
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$nlanguages = AddChildNode($dom, 'LANGUAGES');
foreach ($languageitems as $languageitem) {
$nlanguages_data = AddChildNode($nlanguages, 'LANGUAGES_DATA');
foreach ($languageitem as $k => $v) {
AddChildNodeWithText($nlanguages_data, strtoupper($k), $v);
}
}
echo $dom->saveXML();
}
function ReadCategories() {
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$ncategories = AddChildNode($dom, 'CATEGORIES');
$cat_query = xtc_db_query(
"select " .
"categories_id, " .
"parent_id" .
" from " .
TABLE_CATEGORIES .
" order by " .
"parent_id, " .
"categories_id");
while ($cat = xtc_db_fetch_array($cat_query)) {
$ncategories_data = AddChildNode($ncategories, 'CATEGORIES_DATA');
AddChildNodeWithText($ncategories_data, 'ID', $cat['categories_id']);
AddChildNodeWithText($ncategories_data, 'PARENT_ID', $cat['parent_id']);
$nnames = AddChildNode($ncategories_data, 'NAMES');
$desc_query = xtc_db_query("select " .
"language_id, " .
"categories_name," .
"categories_meta_title," .
"categories_meta_description," .
"categories_meta_keywords" .
" from " .
TABLE_CATEGORIES_DESCRIPTION .
" where " .
"categories_id=" . $cat['categories_id']);
while ($desc = xtc_db_fetch_array($desc_query)) {
$nnameentry = AddChildNode($nnames, 'NAMEENTRY');
AddChildNodeWithText($nnameentry, 'LANGUAGEID', $desc['language_id']);
AddChildNodeWithText($nnameentry, 'NAME', $desc['categories_name']);
AddChildNodeWithText($nnameentry, 'METATITLE', $desc['categories_meta_title']);
AddChildNodeWithText($nnameentry, 'METADESCRIPTION', $desc['categories_meta_description']);
AddChildNodeWithText($nnameentry, 'METAKEYWORDS', $desc['categories_meta_keywords']);
}
}
echo $dom->saveXML();
}
function DeleteArtikel() {
global $client;
$aID = (integer) ($_POST['Artikel_ID']);
$article = $client->get("products/$aID");
foreach ($article['images'] as $image) {
$client->delete("product_images", array('filename' => $image['filename']));
}
$data = $client->delete("products/$aID");
$query = xtc_db_query(
"select " .
"distinct(customers_status_id)" .
" from " .
TABLE_CUSTOMERS_STATUS);
while ($cs = xtc_db_fetch_array($query)) {
xtc_db_query("delete from " . TABLE_PERSONAL_OFFERS_BY . $cs['customers_status_id'] . " where products_id = '{$aID}'");
}
WriteStatus(array(
'MESSAGE' => 'OK'));
}
function WriteCategorie() {
global $storedfiles, $client;
$languages = getLanguages();
// $_POST Daten vorbereiten
foreach ($_POST as $key => $value) {
$post[$key] = xtc_db_prepare_input($value);
}
$exists = FALSE;
$Kategorie_Names = array();
$i = 1;
while (isset($post["Kategorie_Name$i"])) {
$Kategorie_Names[$i] = array(
'N' => $post["Kategorie_Name$i"],
'L' => $post["Kategorie_NameLanguage$i"],
'MT' => $post["Kategorie_MetaTitle$i"],
'MD' => $post["Kategorie_MetaDescription$i"],
'MK' => $post["Kategorie_MetaKeywords$i"]
);
$i++;
}
$name = array();
$hTitle = array();
$mTitle = array();
$mDesc = array();
$mKeyw = array();
foreach ($languages as $key => $value) {
foreach ($Kategorie_Names as $k => $KName) {
if ($value['id'] == $KName['L']) {
$name[$value['code']] = $KName['N'];
$mTitle[$value['code']] = $KName['MT'];
$mDesc[$value['code']] = $KName['MD'];
$mKeyw[$value['code']] = $KName['MK'];
}
}
}
$hTitle = $name;
//$mTitle = $name;
//$mDesc = $name;
//$mKeyw = $name;
$cat_array = array("parentId" => $post['Kategorie_Vater_ID'],
"isActive" => true, "sortOrder" => 0,
"name" => $name, "headingTitle" => $hTitle,
"description" => array("en" => "", "de" => ""),
"metaTitle" => $mTitle,
"metaDescription" => $mDesc,
"metaKeywords" => $mKeyw,
"urlKeywords" => array("en" => "", "de" => ""),
"icon" => "item_ltr.gif",
"settings" => array("categoryListingTemplate" => "categorie_listing.html",
"productListingTemplate" => "product_listing_v1.html",
"sortColumn" => "p.products_price",
"sortDirection" => "ASC",
"onSitemap" => true,
"sitemapPriority" => "0.5",
"sitemapChangeFrequency" => "daily",
"showAttributes" => false,
"showGraduatedPrice" => false,
"showQuantity" => false,
"showQuantityInfo" => false,
"showSubCategories" => true,
"showSubCategoryImages" => true,
"showSubCategoryNames" => true,
"showSubCategoryProducts" => false,
"isViewModeTiled" => false,
"showCategoryFilter" => false,
"filterSelectionMode" => 0,
"filterValueDeactivation" => 0,
"groupPermissions" => array(
// array("id"=> "0","isPermitted"=> false),
// array("id"=> "1","isPermitted"=> false),
// array("id"=> "2","isPermitted"=> false),
// array("id"=> "3","isPermitted"=> false),
)
)
);
if (isset($post['Kategorie_Bildextension'])) {
$filename = $name['de'] . $post['Kategorie_Bildextension'];
$shopfilename = imageWrite($storedfiles['Kategorie_image']['tmp_name'], $filename, 'CategoryWrite');
$cat_array['image'] = $shopfilename;
$cat_array["imageAltText"] = $name;
}
$data = $client->post('categories', $cat_array);
WriteStatus(array(
'MESSAGE' => 'OK',
'ID' => $data['id']));
}
function ReadArtikel() {
global $defaults, $client;
$languages = getLanguages();
$WithImageURL = isset($_GET['WithImageURL']);
$BaseImageURL = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . DIR_WS_CATALOG . DIR_WS_ORIGINAL_IMAGES;
if (isset($_GET['MapFreifeld'])) {
$MapFreifeld = $_GET['MapFreifeld'];
}
$cmd = "select products_id from " . TABLE_PRODUCTS;
if (isset($_GET['AbDatum'])) {
$cmd .= " where products_last_modified >= '" . xtc_db_prepare_input($_GET['AbDatum']) . "'";
}
$HasLimit = false;
if (isset($_GET['LimitOffset']) && isset($_GET['LimitRowCount'])) {
$cmd .= " limit " . (int) $_GET['LimitOffset'] . ', ' .
(int) $_GET['LimitRowCount'];
$HasLimit = true;
}
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$nartikel = AddChildNode($dom, 'ARTIKEL');
if ($HasLimit) {
$nartikel->setAttribute('WithLimit', 'True');
}
$query = xtc_db_query($cmd);
while ($articles = xtc_db_fetch_array($query)) {
$article = $client->get("products/{$articles['products_id']}");
$aID = $article['id'];
$nartikel_data = AddChildNode($nartikel, 'ARTIKEL_DATA');
AddChildNodeWithText($nartikel_data, 'ID', $aID);
AddChildNodeWithText($nartikel_data, 'ARTIKELNR', $article['productModel']);
$ntexte = AddChildNode($nartikel_data, 'TEXTE');
foreach ($languages as $key => $language) {
foreach ($article['name'] as $key => $value) {
if ($language['code'] == $key) {
$ntext = AddChildNode($ntexte, 'TEXT');
AddChildNodeWithText($ntext, 'LANGUAGEID', $language['id']);
AddChildNodeWithText($ntext, 'NAME', $article['name'][$language['code']]);
AddChildNodeWithText($ntext, 'DESCRIPTION', $article['description'][$language['code']]);
AddChildNodeWithText($ntext, 'SHORTDESCRIPTION', $article['shortDescription'][$language['code']]);
AddChildNodeWithText($ntext, 'METATITLE', $article['metaTitle'][$language['code']]);
AddChildNodeWithText($ntext, 'METADESCRIPTION', $article['metaTitle'][$language['code']]);
AddChildNodeWithText($ntext, 'METAKEYWORDS', $article['metaTitle'][$language['code']]);
AddChildNodeWithText($ntext, 'URL', $article['metaTitle'][$language['code']]);
}
}
}
$nkategorien = AddChildNode($nartikel_data, 'KATEGORIEN');
$cats = $client->get("products/$aID/links");
if (count($cats) > 0) {
foreach ($cats as $cat) {
AddChildNodeWithText($nkategorien, 'KATEGORIE', $cat);
}
}
AddChildNodeWithText($nartikel_data, 'GEWICHT', $article['weight']);
AddChildNodeWithText($nartikel_data, 'EAN', $article['ean']);
AddChildNodeWithText($nartikel_data, 'MENGE', $article['quantity']);
AddChildNodeWithText($nartikel_data, 'STATUS', $article['isActive']);
AddChildNodeWithText($nartikel_data, 'STEUERSATZ', $article['taxClassId']);
AddChildNodeWithText($nartikel_data, 'HERSTELLER_ID', $article['manufacturerId']);
AddChildNodeWithText($nartikel_data, 'STARTSEITE', $article['settings']['showOnStartpage']);
AddChildNodeWithText($nartikel_data, 'LIEFERSTATUS', $article['shippingTimeId']);
$cmd = "select shipping_status_name from " . TABLE_SHIPPING_STATUS .
" where shipping_status_id ='{$article['shippingTimeId']}' "
. "AND language_id = '{$defaults['LangID']} ' ";
$shipping_time_query = xtc_db_query($cmd);
$shipping_time = xtc_db_fetch_array($shipping_time_query);
AddChildNodeWithText($nartikel_data, 'LIEFERSTATUSTEXT', $shipping_time['shipping_status_name']);
if ((boolean) $article['isVpeActive']) {
$cmd = "select products_vpe_name from " . TABLE_PRODUCTS_VPE . " where products_vpe_id='{$article['vpeID']}'";
$vpe_query = xtc_db_query($cmd);
if ($vpe = xtc_db_fetch_array($vpe_query)) {
AddChildNodeWithText($nartikel_data, 'VPEName', $vpe['products_vpe_name']);
}
AddChildNodeWithText($nartikel_data, 'VPEValue', $article['vpeValue']);
}
AddChildNodeWithText($nartikel_data, 'PREIS', $article['price']);
$npreise = AddChildNode($nartikel_data, 'PREISE');
$cmd = "select distinct(customers_status_id) from " . TABLE_CUSTOMERS_STATUS;
$cs_query = xtc_db_query($cmd);
while ($cs = xtc_db_fetch_array($cs_query)) {
$cmd = "select quantity, personal_offer from " . TABLE_PERSONAL_OFFERS_BY . $cs['customers_status_id'] .
" where products_id='{$aID}' ";
$preise_query = xtc_db_query($cmd);
while ($preise = xtc_db_fetch_array($preise_query)) {
$npreis = AddChildNode($npreise, 'PREIS');
AddChildNodeWithText($npreis, 'GRUPPE', $cs['customers_status_id']);
AddChildNodeWithText($npreis, 'MENGE', $preise['quantity']);
AddChildNodeWithText($npreis, 'PREIS', $preise['personal_offer']);
}
}
// Zusatzfelder auslesen
if (isset($MapFreifeld)) {
$ffused = array();
foreach ($MapFreifeld as $key => $value) {
$cmd =
"select " .
"value" .
" from " .
"additional_field_values" .
" inner join " .
"additional_field_value_descriptions" .
" on " .
"additional_field_value_descriptions.additional_field_value_id = additional_field_values.additional_field_value_id" .
" inner join " .
"additional_field_descriptions" .
" on " .
"additional_field_descriptions.additional_field_id = additional_field_values.additional_field_id" .
" and " .
"additional_field_descriptions.language_id = additional_field_value_descriptions.language_id" .
" where " .
"item_id = '{$aID}'" .
" and " .
"name = '" . xtc_db_prepare_input($key) . "'";
$afv_query = xtc_db_query($cmd);
if ($afv = xtc_db_fetch_array($afv_query)) {
if (!isset($ffused[(integer)($value)])) {
AddChildNodeWithText($nartikel_data, 'FREIFELD' . (integer)($value), $afv['value']);
$ffused[(integer)($value)] = true;
}
}
}
}
if (!$_GET['SkipImages']) {
$bilder = array();
foreach ($article['images'] as $key => $image) {
if ((boolean) $image['isPrimary']) {
AddChildNodeWithText($nartikel_data, 'BILDDATEI', $image['filename']);
if (file_exists(DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES . $image['filename'])) {
if ($WithImageURL) {
AddChildNodeWithText($nartikel_data, 'BILDURL', $BaseImageURL . $image['filename']);
}
else {
$bild = @implode("", @file(DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES . $image['filename']));
AddChildNodeWithText($nartikel_data, 'BILD', base64_encode($bild));
}
}
}
else {
$bilder[]['filename'] = $image['filename'];
}
}
unset($article['images']);
$nimages = AddChildNode($nartikel_data, 'IMAGES');
foreach ($bilder as $value) {
$nimage = AddChildNode($nimages, 'IMAGE');
AddChildNodeWithText($nimage, 'NAME', $value['filename']);
if (file_exists(DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES . $value['filename'])) {
if ($WithImageURL) {
AddChildNodeWithText($nimage, 'BILDURL', $BaseImageURL . $value['filename']);
}
else {
$bild = @implode("", @file(DIR_FS_CATALOG . DIR_WS_ORIGINAL_IMAGES . $value['filename']));
AddChildNodeWithText($nimage, 'BILD', base64_encode($bild));
}
}
}
}
unset($article);
}
echo $dom->saveXML();
}
function ReadShopData() {
global $defaults;
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$nshopdata = AddChildNode($dom, 'SHOPDATA');
$ntaxrates = AddChildNode($nshopdata, 'TAXRATES');
$tax_query = xtc_db_query(
"select " .
"tax_rates.tax_class_id," .
"tax_rates.tax_rate" .
" from " .
TABLE_TAX_RATES .
" inner join " .
TABLE_TAX_CLASS .
" on " .
"tax_rates.tax_class_id=tax_class.tax_class_id" .
" inner join " .
TABLE_GEO_ZONES .
" on " .
"tax_rates.tax_zone_id=geo_zones.geo_zone_id" .
" WHERE " .
"(" .
"tax_class.tax_class_title like 'Europ_ische Standards_tze'" .
" or " .
"tax_class.tax_class_title like 'Europ_isch erm__igter Steuersatz'" .
")" .
" and " .
"geo_zones.geo_zone_name = 'Deutschland'");
while ($tax = xtc_db_fetch_array($tax_query)) {
$ntax = AddChildNode($ntaxrates, 'TAX');
AddChildNodeWithText($ntax, 'ID', $tax['tax_class_id']);
AddChildNodeWithText($ntax, 'RATE', $tax['tax_rate']);
}
if(!isset($tax)) {
$tax_query = xtc_db_query(
"select " .
"tax_rates.tax_class_id," .
"tax_rates.tax_rate" .
" from " .
TABLE_TAX_RATES .
" inner join " .
TABLE_GEO_ZONES .
" on " .
"tax_rates.tax_zone_id=geo_zones.geo_zone_id" .
" WHERE " .
"geo_zones.geo_zone_name='Steuerzone EU'");
while ($tax = xtc_db_fetch_array($tax_query)) {
$ntax = AddChildNode($ntaxrates, 'TAX');
AddChildNodeWithText($ntax, 'ID', $tax['tax_class_id']);
AddChildNodeWithText($ntax, 'RATE', $tax['tax_rate']);
}
}
$nshippingstatus = AddChildNode($nshopdata, 'SHIPPINGSTATUS');
$query = xtc_db_query(
"select " .
"shipping_status_id," .
"language_id," .
"shipping_status_name" .
" from " .
TABLE_SHIPPING_STATUS .
" WHERE " .
"language_id = '{$defaults['LangID']}'");
while ($sstatus = xtc_db_fetch_array($query)) {
$nshippingstatus_data = AddChildNode($nshippingstatus, 'SHIPPINGSTATUS_DATA');
AddChildNodeWithText($nshippingstatus_data, 'ID', $sstatus['shipping_status_id']);
AddChildNodeWithText($nshippingstatus_data, 'LANGUAGEID', $sstatus['language_id']);
AddChildNodeWithText($nshippingstatus_data, 'NAME', $sstatus['shipping_status_name']);
}
$ncustomerstatus = AddChildNode($nshopdata, 'CUSTOMERSSTATUS');
$query = xtc_db_query(
"select " .
"customers_status_id," .
"language_id," .
"customers_status_name" .
" from " .
TABLE_CUSTOMERS_STATUS .
" WHERE " .
"language_id = '{$defaults['LangID']}'");
while ($cstatus = xtc_db_fetch_array($query)) {
$ncustomerstatus_data = AddChildNode($ncustomerstatus, 'CUSTOMERSSTATUS_DATA');
AddChildNodeWithText($ncustomerstatus_data, 'ID', $cstatus['customers_status_id']);
AddChildNodeWithText($ncustomerstatus_data, 'LANGUAGEID', $cstatus['language_id']);
AddChildNodeWithText($ncustomerstatus_data, 'NAME', $cstatus['customers_status_name']);
}
echo $dom->saveXML();
}
function ReadHersteller() {
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$nmanufacturers = AddChildNode($dom, 'MANUFACTURERS');
$manufacturers_query = xtc_db_query(
"select " .
"manufacturers_id," .
"manufacturers_name" .
" from " .
TABLE_MANUFACTURERS);
while ($manufacturers = xtc_db_fetch_array($manufacturers_query)) {
$nmanufacturers_data = AddChildNode($nmanufacturers, 'MANUFACTURERS_DATA');
AddChildNodeWithText($nmanufacturers_data, 'ID', $manufacturers['manufacturers_id']);
AddChildNodeWithText($nmanufacturers_data, 'NAME', $manufacturers["manufacturers_name"]);
}
echo $dom->saveXML();
}
function WriteHersteller() {
$Hersteller_Name = xtc_db_prepare_input($_POST['Hersteller_Name']);
$cmd = "select manufacturers_id,manufacturers_name from " . TABLE_MANUFACTURERS .
" where manufacturers_name='$Hersteller_Name'";
$manufacturers_query = xtc_db_query($cmd);
if ($manufacturers = xtc_db_fetch_array($manufacturers_query)) {
$Hersteller_ID = $manufacturers['manufacturers_id'];
}
else {
$insert_sql_data = array('manufacturers_name' => $Hersteller_Name,
'date_added' => 'now()');
xtc_db_perform(TABLE_MANUFACTURERS, $insert_sql_data);
$Hersteller_ID = xtc_db_insert_id();
}
WriteStatus(array(
'MESSAGE' => 'OK',
'ID' => $Hersteller_ID));
}
function OrderUpdate() {
global $client, $defaults;
$info = '';
$post = $_POST;
$order_updated = false;
$statusArray = array(2 => array(2, 'In Bearbeitung'), 3 => array(3, 'Versendet'));
$oID = $post['Order_id'];
$order_exists = true;
$orders_query = xtc_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '$oID' LIMIT 1");
$order = xtc_db_fetch_array($orders_query);
// $produkte = xtc_db_fetch_array($p_query)
if (!$order) {
$order_exists = false;
$info = "Die Bestellung mit der Nummer {$oID} wurde nicht gefunden";
}
// track & trace
$tracking = false;
if (isset($post['Sendungsdienstleister']) && isset($post['Sendungsnummer']) && !empty($post['Sendungsnummer'])) {
$carriers = array();
$carriers_query = xtc_db_query("SELECT ps.parcel_service_id, ps.name, pd.language_id, pd.url, pd.comment
FROM parcel_services ps, parcel_services_description pd
where ps.name LIKE '{$post['Sendungsdienstleister']}%'
and pd.language_id = '2'
and ps.parcel_service_id = pd.parcel_service_id");
while ($carrier = xtc_db_fetch_array($carriers_query)) {
$carrier_id = xtc_db_prepare_input($carrier['parcel_service_id']);
$tracking_id = xtc_db_prepare_input($post['Sendungsnummer']);
$url = preg_replace('/{TRACKING_NUMBER}/', $tracking_id, $carrier['url']);
$sql_data_array = array('order_id' => $oID,
'parcel_service_id' => $carrier_id,
'tracking_code' => $tracking_id,
'parcel_service_name' => $carrier['name'],
'language_id' => $defaults['LangID'],
'url' => $url,
'comment' => $carrier['comment'],
'creation_date' => 'now()'
);
xtc_db_perform('orders_parcel_tracking_codes', $sql_data_array);
$orderTrackID = xtc_db_insert_id();
$orders_parcel_tracking_codes = $sql_data_array;
$orders_parcel_tracking_codes['orders_parcel_tracking_code_id'] = $orderTrackID;
$tracking = true;
}
}
// $orderWriteService = StaticGXCoreLoader::getService('OrderWrite');
// $orderWriteService->updateOrderStatus(
// new IdType((int)$oID),
// new IdType((int)$statusArray[$post['Status']][0]),
// new StringType(''),
// new BoolType(true),
// null);
$orderActions = MainFactory::create('OrderActions');
$orderActions->changeOrderStatus(
new IdType((int)$oID),
new IdType((int)$statusArray[$post['Status']][0]),
new StringType(''),
new BoolType(true),
new BoolType($tracking),
new BoolType(false));
WriteStatus(array(
'MESSAGE' => 'OK',
'INFO' => $info));
}
function ReadAuftraege() {
global $client, $defaults;
$order_from = xtc_db_prepare_input($_GET['order_from']);
$order_count = xtc_db_prepare_input($_GET['order_count']);
$order_to = xtc_db_prepare_input($_GET['order_to']);
$order_status = xtc_db_prepare_input($_GET['order_status']);
$sql = "select orders_id as id from " . TABLE_ORDERS . " where orders_id >= '" . xtc_db_input($order_from) . "'";
if (!isset($order_status) && !isset($order_from)) {
$order_status = 1;
$sql .= "and orders_status = " . $order_status;
}
if ($order_status != '') {
$sql .= " and orders_status = " . $order_status;
}
$orders_query = xtc_db_query($sql);
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$count = 0;
$norders = AddChildNode($dom, 'ORDERS');
while ($orders = xtc_db_fetch_array($orders_query)) {
if ($order_count != 0 && ++$count > $order_count) {
break;
}
$norder = AddChildNode($norders, 'ORDER');
$order = $client->get("orders/{$orders['id']}");
$order['number'] = $order['id'];
if (($order['items'][0]['tax']) > 0) {
(($order['items'][0]['isTaxAllowed'])) ? $order['tax_flag'] = 'J' : $order['tax_flag'] = 'N';
}
elseif (($order['items'][0]['tax']) == 0) {
(($order['items'][0]['isTaxAllowed'])) ? $order['tax_flag'] = '0' : $order['tax_flag'] = '0';
}
else
$order['tax_flag'] = 'J';
switch ($order['addresses']['customer']['gender']) {
case 'm':
$order['addresses']['customer']['gender'] = 'Herr';
break;
case 'f':
$order['addresses']['customer']['gender'] = 'Frau';
break;
default:
$order['addresses']['customer']['gender'] = '';
break;
}
switch ($order['addresses']['delivery']['gender']) {
case 'm':
$order['addresses']['delivery']['gender'] = 'Herr';
break;
case 'f':
$order['addresses']['delivery']['gender'] = 'Frau';
break;
default:
$order['addresses']['delivery']['gender'] = '';
break;
}
$c_query = xtc_db_query("select * from " . TABLE_COUNTRIES . " where countries_id = '{$order['addresses']['customer']['countryId']}'");
if ($country = xtc_db_fetch_array($c_query)) {
$order['addresses']['customer']['country'] = $country['countries_iso_code_2'];
}
if ($order['addresses']['customer']['countryId'] == $order['addresses']['delivery']['countryId']) {
$order['addresses']['delivery']['country'] = $country['countries_iso_code_2'];
}
else {
$d_query = xtc_db_query("select * from " . TABLE_COUNTRIES . " where countries_id = '{$order['addresses']['delivery']['countryId']}'");
if ($country = xtc_db_fetch_array($d_query)) {
$order['addresses']['delivery']['country'] = $country['countries_iso_code_2'];
}
}
$order['shippingType']['tax'] = get_shipping($order);
$order['totals'] = get_tmodul_tax($order);
$order['paymentType'] = get_payment($order);
$query = xtc_db_query("SELECT * FROM `orders_parcel_tracking_codes`
WHERE `orders_parcel_tracking_code_id`=(select max(`orders_parcel_tracking_code_id`) from orders_parcel_tracking_codes)
AND order_id ='{$order['id']}'
AND language_id = '{$defaults['LangID']}'");
if ($tracking = xtc_db_fetch_array($query)) {
$order['parcel_service']['tracking_code'] = $tracking['tracking_code'];
$order['parcel_service']['parcel_service_name'] = $tracking['parcel_service_name'];
}
SerializeToXML($norder, $order);
}
echo $dom->saveXML();
}
function get_shipping($order) {
$shipping_method = explode('_', $order['shippingType']['module']);
$shipping_method = strtoupper($shipping_method[0]);
$cmd = "select * from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_" . $shipping_method . "_TAX_CLASS'";
$query = xtc_db_query($cmd);
if ($shipping = xtc_db_fetch_array($query)) {
$tax_rate = xtc_get_tax_rate($shipping['configuration_value'], $order['addresses']['customer']['countryId'], $order['addresses']['customer']['zoneId']);
}
return $tax_rate;
}
function get_tmodul_tax($order) {
$module = array(array('name' => 'ot_cod_fee', 'prefix' => '0'),
array('name' => 'ot_loworderfee', 'prefix' => '0'),
array('name' => 'ot_ps_fee', 'prefix' => '0'),
array('name' => 'ot_coupon', 'prefix' => '0'),
array('name' => 'ot_gv', 'prefix' => '0')
);
foreach ($order['totals'] as $key => $value) {
$k = array_search($value['class'], array_column($module, 'name'));
if (is_numeric($k)) {
$total_name = str_replace('ot_', '', $value['class']);
$cmd = "select * from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_" . $total_name . "_TAX_CLASS'";
$query = xtc_db_query($cmd);
if ($payment = xtc_db_fetch_array($query)) {
$tax_rate = xtc_get_tax_rate($payment['configuration_value'], $order['addresses']['customer']['countryId'], $order['addresses']['customer']['zoneId']);
}
$order['totals'][$key]['tax'] = $tax_rate;
$order['totals'][$key]['prefix'] = $module[$k]['prefix'];
unset($k);
}
}
return $order['totals'];
}
function existsTable($tablename) {
$cmd = "show tables like '$tablename'";
$query = xtc_db_query($cmd);
return xtc_db_num_rows($query) > 0;
}
function get_payment($order) {
switch ($order['paymentType']['module']) {
case 'sepa':
$cmd = "select sepa_owner, sepa_iban, sepa_bic, sepa_bankname from sepa where orders_id = '{$order['id']}'";
$query = xtc_db_query($cmd);
if ($payment = xtc_db_fetch_array($query)) {
foreach ($payment as $key => $value) {
$order['paymentType'][$key] = $value;
}
}
break;
case 'banktransfer':
$cmd = "select banktransfer_owner, banktransfer_number, banktransfer_bankname, banktransfer_blz from banktransfer where orders_id = '{$order['id']}'";
$query = xtc_db_query($cmd);
if ($payment = xtc_db_fetch_array($query)) {
foreach ($payment as $key => $value) {
$order['paymentType'][$key] = $value;
}
}
break;
case 'paypal':
case 'paypal3':
if (existsTable('paypal_transactions')) {
$cmd = "select * from paypal_transactions "
. "where ecresponse_id = ( select max(ecresponse_id) from paypal_transactions)"
. "and orders_id = '{$order['id']}'";
}
else if (existsTable('orders_paypal_payments')) {
$cmd = "select payment_id transaction_id from orders_paypal_payments" .
" where orders_id = '{$order['id']}'" .
" order by payment_id DESC";
}
if (isset($cmd)) {
$query = xtc_db_query($cmd);
if ($payment = xtc_db_fetch_array($query)) {
$order['paymentType']['transactionID'] = $payment['transaction_id'];
}
}
break;
default:
break;
}
return $order['paymentType'];
}
function getDefaults() {
global $verge41;
$arr = array('DEFAULT_LANGUAGE', 'STORE_COUNTRY');
foreach ($arr as $k => $v) {
if ($verge41) {
$cmd = "select value as configuration_value from gx_configurations where `key` = 'configuration/$v'";
} else {
$cmd = "select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '$v'";
}
$query = xtc_db_query($cmd);
if ($res = xtc_db_fetch_array($query)) {
$rest[$v] = $res['configuration_value'];
}
}
$cmd = "Select * from " . TABLE_LANGUAGES . " where code = '{$rest['DEFAULT_LANGUAGE']}'";
$query = xtc_db_query($cmd);
if ($res = xtc_db_fetch_array($query)) {
$rest['LangID'] = $res['languages_id'];
$rest['charset'] = $res['language_charset'];
}
return $rest;
}
function getLanguages() {
$cmd = "select languages_id, name, code from " . TABLE_LANGUAGES;
$languages_query = xtc_db_query($cmd);
while ($languages = xtc_db_fetch_array($languages_query)) {
$lang[] = array('id' => $languages['languages_id'],
'name' => $languages['name'],
'code' => $languages['code']);
}
return $lang;
}
function CheckLogin($user, $password) {
global $client;
// $url = 'http://meinGambioShop.tld/';
$url = HTTP_SERVER . DIR_WS_CATALOG;
$ok = FALSE;
try {
$client = new AFApi($url . 'api.php/v2/', $user, $password);
} catch (Exception $ex) {
echo $ex->getMessage();
echo $ex->getCode();
echo $ex->getFile();
}
if ($user != '') {
$customers_query = xtc_db_query("select customers_id,customers_status,customers_password" .
" from " . TABLE_CUSTOMERS .
" where customers_email_address = '" . xtc_db_input($user) . "'");
if ($customers = xtc_db_fetch_array($customers_query)) {
// check if customer is Admin
if ($customers['customers_status'] == '0') {
$authService = StaticGXCoreLoader::getService('Auth');
$credentials = MainFactory::create('UsernamePasswordCredentials',
new NonEmptyStringType($user),
new StringType($password));
$ok = $authService->authUser($credentials);
}
}
}
if (!$ok) {
echo "Anmeldung: Name/Passwort nicht korrekt!";
}
return $ok;
}
function imageWrite($filename, $shopfilename, $service = 'ProductWrite') {
$writeService = StaticGXCoreLoader::getService($service);
$filenameFile = new ExistingFile(new NonEmptyStringType($filename));
$shopfilenameType = new FilenameStringType($shopfilename);
if ($service == 'CategoryWrite') {
$realshopfilename = $writeService->importCategoryImageFile($filenameFile, $shopfilenameType);
}
else {
$realshopfilename = $writeService->importProductImageFile($filenameFile, $shopfilenameType);
}
return $realshopfilename;
}
class AFApi {
protected $validMethods = array('GET', 'PUT', 'POST', 'DELETE', 'PATCH');
protected $apiUrl;
protected $cURL;
private $auth;
public $requestmethod;
public $requestresource;
public $requestdata;
public $responsestatuscode;
public $responsecontent;
public $responseerrormessage;
public function __construct($apiUrl, $username, $apiKey) {
$auth = base64_encode("$username:$apiKey");
$this->auth = $auth;
$this->apiUrl = rtrim($apiUrl, '/') . '/';
//Initializes the cURL instance
$this->cURL = curl_init();
curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->cURL, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($this->cURL, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->cURL, CURLOPT_USERAGENT, 'Amicron - Gambio GX3 ApiClient');
curl_setopt($this->cURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $auth,
'Content-Type: application/json',
'accept: application/json')
);
}
public function call($url, $method = 'GET', $data = array(), $params = array()) {
global $clientdebug;
if (!in_array($method, $this->validMethods)) {
echo 'Invalid HTTP-Methode: ' . $method;
}
//$params['auth'] = $this->auth;
//$params['XDEBUG_SESSION_START'] = 'netbeans-xdebug';
$url = rtrim($url, '?');
if (!empty($params)) {
$queryString = http_build_query($params);
$url = $url . '?' . $queryString;
}
$this->requestmethod = $method;
$this->requestresource = $url;
$this->requestdata = $data;
$url = $this->apiUrl . $url;
$dataString = json_encode($data);
curl_setopt($this->cURL, CURLOPT_URL, $url);
curl_setopt($this->cURL, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $dataString);
$result = curl_exec($this->cURL);
$this->responsestatuscode = curl_getinfo($this->cURL, CURLINFO_HTTP_CODE);
$this->responsecontent = $result;
$this->responseerrormessage = curl_error($this->cURL);
$jsonobj = $this->prepareResponse($result);
if (
$this->responsestatuscode == 429
&&
isset($jsonobj['message'])
&&
$jsonobj['message'] == 'Request limit was reached.') {
echo
"Fehler: Die Anzahl der zulässigen Gambio API-Aufrufe im Zeitraum von 15 Minuten wurden überschritten!\n\n" .
"Um dieses Limit zu erhöhen, müssen Sie im Shop die folgende Datei ändern:\n" .
DIR_FS_DOCUMENT_ROOT . "GXMainComponents/Controllers/Api/AbstractApiV2Controller.inc.php\n\n" .
"Dort muss der Wert von \"DEFAULT_RATE_LIMIT\" erhöht werden.\n" .
"Für weitere Fragen wenden Sie sich bitte an den Technischen Support.";
exit;
}
if ($clientdebug) {
//echo json_encode($this->handleError(true));
print_r($this->handleError(true));
}
return $jsonobj;
}
public function get($url, $params = array()) {
return $this->call($url, 'GET', array(), $params);
}
public function post($url, $data = array(), $params = array()) {
return $this->call($url, 'POST', $data, $params);
}
public function put($url, $data = array(), $params = array()) {
return $this->call($url, 'PUT', $data, $params);
}
public function patch($url, $data = array(), $params = array()) {
return $this->call($url, 'PUT', $data, $params);
}
public function delete($url, $data = array(), $params = array()) {
return $this->call($url, 'DELETE', $data, $params);
}
protected function prepareResponse($result) {
$decodedResult = json_decode($result, true);
return $decodedResult;
}
public function handleError($apidebug = false, $full = false, $call = '') {
if ($full && $this->hasError()) {
echo
"Fehler:\n\n" .
"Statuscode: " . $this->responsestatuscode . "\n" .
"Errormessage: " . $this->responseerrormessage . "\n" .
"Content: " . $this->responsecontent;
exit;
}
if ($apidebug || $this->responseerrormessage != '') {
return array(
'Call' => $call,
'Request' => array(
'Method' => $this->requestmethod,
'Resource' => $this->requestresource,
'Data' => $this->requestdata
),
'Response' => array(
'StatusCode' => $this->responsestatuscode,
'ErrorMessage' => $this->responseerrormessage,
'Content' => $this->responsecontent
)
);
}
else {
return '';
}
}
public function hasError() {
return $this->responsestatuscode >= 400 || $this->responseerrormessage != '';
}
}
function WriteStatus($data = array()) {
global $version_major, $version_minor;
$dom = new DOMDocument('1.0', XMLEncoding);
$dom->formatOutput = true;
$nstatus = AddChildNode($dom, 'STATUS');
$nstatus_data = AddChildNode($nstatus, 'STATUS_DATA');
SerializeToXML($nstatus_data, $data);
AddChildNodeWithText($nstatus_data, 'SCRIPT_VERSION_MAJOR', $version_major);
AddChildNodeWithText($nstatus_data, 'SCRIPT_VERSION_MINOR', $version_minor);
echo $dom->saveXML();
}
function AddChildNode(DOMNode $node, $name) {
if ($node instanceof DOMDocument) {
$newnode = $node->createElement($name);
}
else {
$newnode = $node->ownerDocument->createElement($name);
}
$node->appendChild($newnode);
return $newnode;
}
function AddChildNodeWithText(DOMNode $node, $name, $text) {
$newnode = AddChildNode($node, $name);
$newnode->appendChild($node->ownerDocument->createTextNode($text));
return $newnode;
}
function SerializeToXML($node, $arr) {
if (isset($arr) && !empty($arr)) {
foreach ($arr as $key => $value) {
// Numerische Auftragspositionen als "pos"
if (is_numeric($key)) {
$key = "pos";
}
$key = str_replace([' ', '&', ':', '?'] , '_', $key);
switch (gettype($value)) {
case "array":
SerializeToXML(AddChildNode($node, $key), $value);
break;
default:
AddChildNodeWithText($node, $key, $value);
break;
}
}
}
}
?>