mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-14 20:17:14 +01:00
Compare commits
3 Commits
aac159bcb0
...
6d13973c06
Author | SHA1 | Date | |
---|---|---|---|
|
6d13973c06 | ||
|
0b807455ca | ||
|
d494778fad |
@ -2240,13 +2240,12 @@ class Remote {
|
||||
$this->app->erp->AuftragProtokoll($orderId, 'Versandmeldung an Shop fehlgeschlagen', $bearbeiter);
|
||||
|
||||
$this->logger->error('Versandmeldung an Shop fehlgeschlagen',
|
||||
[
|
||||
'orderId' => $orderId,
|
||||
'shopId' => $shopId,
|
||||
'message' => $response->getMessage()
|
||||
]
|
||||
[
|
||||
'orderId' => $orderId,
|
||||
'shopId' => $shopId,
|
||||
'message' => $response->getMessage()
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2486,7 +2485,21 @@ class Remote {
|
||||
$shoptyp = $this->app->DB->Select("SELECT shoptyp FROM shopexport WHERE id='$id' LIMIT 1");
|
||||
$modulename = trim($this->app->DB->Select("SELECT modulename FROM shopexport WHERE id='$id' LIMIT 1"), '.');
|
||||
$isActionAuth = $action === 'auth';
|
||||
$exception = null;
|
||||
|
||||
$this->logger->debug(
|
||||
'RemoteCommand (Shop '.$id.") ".$action,
|
||||
[
|
||||
'shop' => $id,
|
||||
'action' => $action,
|
||||
'data' => $data
|
||||
]
|
||||
);
|
||||
|
||||
if ($shoptyp === 'custom') {
|
||||
|
||||
$error = null;
|
||||
|
||||
if ($modulename != '') {
|
||||
|
||||
$file = dirname(__DIR__) . '/plugins/external/shopimporter/' . $modulename;
|
||||
@ -2507,29 +2520,37 @@ class Remote {
|
||||
$method = $this->getMethod($obj, $action);
|
||||
if (method_exists($obj, $method)) {
|
||||
$ret = $obj->$method();
|
||||
$this->logger->debug('RemoteCommand result (Shop '.$id.') '.$modulename.' '.$action,
|
||||
[
|
||||
'shop' => $id,
|
||||
'action' => $action,
|
||||
'data' => $data,
|
||||
'result' => $ret
|
||||
]
|
||||
);
|
||||
if (!empty($this->app->stringcleaner)) {
|
||||
$this->app->stringcleaner->XMLArray_clean($ret);
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
$error = 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
$error = 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
$error = 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Datei ' . $file . ' existiert nicht';
|
||||
$error = 'Fehler: Datei ' . $file . ' existiert nicht';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Schnittstelle nicht aktiv';
|
||||
$error = 'Fehler: Schnittstelle nicht aktiv';
|
||||
}
|
||||
} else {
|
||||
$error = 'Fehler: Kein Modul angegeben';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($shoptyp === 'intern') {
|
||||
else if ($shoptyp === 'intern') {
|
||||
if ($modulename != '') {
|
||||
if ($this->app->erp->ModulVorhanden($modulename)) {
|
||||
$obj = $this->app->erp->LoadModul($modulename);
|
||||
@ -2538,94 +2559,57 @@ class Remote {
|
||||
$obj->getKonfig($id, $data);
|
||||
}
|
||||
$method = 'Import' . $action;
|
||||
|
||||
if (method_exists($obj, $method)) {
|
||||
try {
|
||||
$ret = $obj->$method();
|
||||
} catch (Exception $e) {
|
||||
$exception = $e;
|
||||
if ($isActionAuth) {
|
||||
return 'Fehler Auth: ' . $e->getMessage();
|
||||
$error = 'Fehler Auth: ' . $e->getMessage();
|
||||
} else {
|
||||
$error = 'Fehler: ' . $e->getMessage();
|
||||
}
|
||||
return 'Fehler: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
$this->logger->debug('RemoteCommand result (Shop '.$id.') '.$modulename.' '.$action,
|
||||
[
|
||||
'shop' => $id,
|
||||
'action' => $action,
|
||||
'data' => $data,
|
||||
'result' => $ret
|
||||
]
|
||||
);
|
||||
if (!empty($this->app->stringcleaner)) {
|
||||
$this->app->stringcleaner->XMLArray_clean($ret);
|
||||
}
|
||||
$this->parseReturn($ret, $id, $action);
|
||||
return $ret;
|
||||
} else {
|
||||
return 'Fehler: Funktion nicht implementiert: ' . $method;
|
||||
$error = 'Fehler: Funktion nicht implementiert: ' . $method;
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
$error = 'Fehler: Importer konnte nicht initialisiert werden';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Dieses Modul ist nicht verfügbar';
|
||||
$error = 'Fehler: Dieses Modul ist nicht verfügbar';
|
||||
}
|
||||
} elseif ($isActionAuth) {
|
||||
return 'Fehler: Kein Modul vorhanden';
|
||||
$error = 'Fehler: Kein Modul vorhanden';
|
||||
} else {
|
||||
$error = 'Fehler: Kein Modul angegeben';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
$shopexport = $this->app->DB->SelectRow("SELECT * FROM shopexport WHERE id='$id' LIMIT 1");
|
||||
if ($shopexport) {
|
||||
if ($shopexport['shoptyp'] === 'intern' || $shopexport['shoptyp'] === 'custom') {
|
||||
return '';
|
||||
}
|
||||
$token = $shopexport['token'];
|
||||
$url = $shopexport['url'];
|
||||
$z = $shopexport['passwort'];
|
||||
$bezeichnung = $shopexport['bezeichnung'];
|
||||
} else {
|
||||
$token = '';
|
||||
$z = '';
|
||||
$url = '';
|
||||
}
|
||||
if ($isActionAuth) {
|
||||
if ($token === '' || strlen($z) < 32 || $url === '') {
|
||||
return 'Fehler: Bitte Zugangsdaten prüfen';
|
||||
}
|
||||
} elseif ($token === '' || strlen($z) < 32 || $url === '' || !$this->app->DB->Select("SELECT id FROM shopexport WHERE id = '$id' AND aktiv = 1 LIMIT 1")) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tmp = parse_url($url);
|
||||
$tmp['host'] = rtrim($tmp['host'], '/');
|
||||
$tmp['path'] = rtrim($tmp['path'], '/') . '/';
|
||||
|
||||
$aes = new AES($z);
|
||||
$token = base64_encode($aes->encrypt(serialize($token)));
|
||||
$client = new HttpClient($tmp['host'], stripos($url, 'https') === 0 ? 443 : 80);
|
||||
$geturl = $tmp['path'] . 'index.php?module=import&action=' . $action . '&challenge=' . (isset($challenge) ? $challenge : '');
|
||||
//Kein Fragezeichen vor module=import...
|
||||
if (false !== stripos($bezeichnung, 'woocommerce')) {
|
||||
$geturl = $tmp['path'] . 'module=import&action=' . $action . '&challenge=' . (isset($challenge) ? $challenge : '');
|
||||
}
|
||||
if (false !== stripos($bezeichnung, 'shopware plugin')) {
|
||||
$geturl = $tmp['path'] . 'wawisionimporter/?smodule=import&saction=' . $action . '&challenge=' . (isset($challenge) ? $challenge : '');
|
||||
}
|
||||
|
||||
$post_data['token'] = $token;
|
||||
$post_data['data'] = base64_encode(serialize($data));
|
||||
$client->timeout = 120;
|
||||
if (!$client->post($geturl, $post_data)) {
|
||||
|
||||
$this->logger->error('An error occurred',
|
||||
[
|
||||
'error' => $client->getError()
|
||||
]
|
||||
if ($error) {
|
||||
$this->logger->error('RemoteCommand error (Shop '.$id.') '.$modulename.' '.$action,
|
||||
[
|
||||
'error' => $error,
|
||||
'exception' => $exception
|
||||
]
|
||||
);
|
||||
return($error);
|
||||
}
|
||||
|
||||
throw new Exception('An error occurred: ' . $client->getError());
|
||||
//return 'Netzwerkverbindung von WaWison zu Shopimporter fehlgeschlagen: '.$client->getError();
|
||||
}
|
||||
$ret = unserialize(base64_decode($client->getContent()));
|
||||
if (!empty($this->app->stringcleaner)) {
|
||||
$this->app->stringcleaner->XMLArray_clean($ret);
|
||||
}
|
||||
$this->parseReturn($ret, $id, $action);
|
||||
return $ret;
|
||||
|
||||
// Dead code removed here 2024-09-13
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,10 +16,10 @@
|
||||
use Xentral\Components\Http\JsonResponse;
|
||||
use Xentral\Modules\Onlineshop\Data\OrderStatus;
|
||||
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
|
||||
use Xentral\Components\Logger\Logger;
|
||||
|
||||
class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
{
|
||||
|
||||
// protected $canexport = false;
|
||||
|
||||
public $intern = false;
|
||||
@ -55,16 +55,17 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
*/
|
||||
protected $app;
|
||||
protected $dump;
|
||||
|
||||
/** @var Logger $logger */
|
||||
public $logger;
|
||||
|
||||
public function __construct($app, $intern = false)
|
||||
{
|
||||
$this->app=$app;
|
||||
$this->intern = true;
|
||||
|
||||
$this->logger = $app->Container->get('Logger');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function ImportList()
|
||||
{
|
||||
$msg = $this->app->erp->base64_url_encode('<div class="info">Sie können hier die Shops einstellen</div>');
|
||||
@ -72,8 +73,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function returns the number of orders which have not yet been imported
|
||||
*/
|
||||
@ -83,7 +82,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
// We set per_page to 100 - this could lead to a situation where there are more than
|
||||
// 100 new Orders, but we still only return 100.
|
||||
|
||||
|
||||
// Array containing additional settings, namely 'ab_nummer' (containting the next order number to get)
|
||||
// and 'holeallestati' (an integer)
|
||||
$tmp = $this->CatchRemoteCommand('data');
|
||||
@ -97,7 +95,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
if ($number_from) {
|
||||
// Number-based import is selected
|
||||
|
||||
|
||||
// The WooCommerce API doenst allow for a proper "greater than id n" request.
|
||||
// we fake this behavior by creating an array that contains 'many' (~ 1000) consecutive
|
||||
// ids that are greater than $from_number and use this array with the 'include' property
|
||||
@ -115,7 +112,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
'include' => implode(",",$fakeGreaterThanIds),
|
||||
]);
|
||||
|
||||
|
||||
} else {
|
||||
// fetch posts by status
|
||||
|
||||
@ -129,7 +125,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return (!empty($pendingOrders)?count($pendingOrders):0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calling this function queries the api for pending orders and returns them
|
||||
* as an array.
|
||||
@ -141,7 +136,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
*/
|
||||
public function ImportGetAuftrag()
|
||||
{
|
||||
|
||||
// Array containing additional settings, namely 'ab_nummer' (containting the next order number to get)
|
||||
// and 'holeallestati' (an integer)
|
||||
$tmp = $this->CatchRemoteCommand('data');
|
||||
@ -155,7 +149,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
if ($number_from) {
|
||||
// Number-based import is selected
|
||||
|
||||
|
||||
// The WooCommerce API doenst allow for a proper "greater than id n" request.
|
||||
// we fake this behavior by creating an array that contains 'many' (~ 1000) consecutive
|
||||
// ids that are greater than $from_number and use this array with the 'include' property
|
||||
@ -175,7 +168,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
'orderby' => 'id'
|
||||
]);
|
||||
|
||||
|
||||
} else {
|
||||
// fetch posts by status
|
||||
|
||||
@ -188,7 +180,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Return an empty array in case there are no orders to import
|
||||
if ((!empty($pendingOrders)?count($pendingOrders):0) === 0) {
|
||||
return null;
|
||||
@ -214,10 +205,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
return $tmp;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// This function searches the wcOrder for the specified WC Meta key
|
||||
// and returns it if found, null otherise
|
||||
public function get_wc_meta($wcOrder, $meta_key) {
|
||||
@ -231,15 +220,11 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
// Parse the given WooCommerce order, return a Xentral array-represented order.
|
||||
// Overload this method whenever additional attributes are required.
|
||||
public function parseOrder($wcOrder) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$order = array();
|
||||
$order['auftragsdaten'] = $wcOrder;
|
||||
|
||||
@ -273,7 +258,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!empty($wcOrder->subshop)){
|
||||
$order['subshop'] = $wcOrder->subshop;
|
||||
}
|
||||
@ -302,7 +286,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Coupon Codes
|
||||
//
|
||||
@ -333,7 +316,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
|
||||
|
||||
|
||||
$seperateShippingAddress = !self::compareObjects(
|
||||
$wcOrder->billing,
|
||||
$wcOrder->shipping,
|
||||
@ -360,7 +342,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$order['lieferadresse_land'] = $wcOrder->shipping->country;
|
||||
}
|
||||
|
||||
|
||||
// VAT stuff
|
||||
|
||||
$vatId = $this->get_wc_meta($wcOrder, "_billing_ustid");
|
||||
@ -375,7 +356,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$order['zahlungsweise'] = $wcOrder->payment_method;
|
||||
$order['lieferung'] = $wcOrder->shipping_lines[0]->method_id;
|
||||
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@ -408,7 +388,7 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
// The item could be a variable product in which case we have to retrieve the sku of the variation product
|
||||
if (!empty($wcOrderItem->variation_id)) {
|
||||
$variation_product_sku = $this->getSKUByShopId($wcOrderItem->id,$wcOrderItem->variation_id);
|
||||
$variation_product_sku = $this->getSKUByShopId($wcOrderItem->product_id,$wcOrderItem->variation_id);
|
||||
if (!empty($variation_product_sku)) {
|
||||
$orderItem['articleid'] = $variation_product_sku;
|
||||
}
|
||||
@ -417,7 +397,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return $orderItem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Order status to processing, meaning we've successfully imported
|
||||
* the order into our DB. This prevents the order from beeing imported again.
|
||||
@ -432,7 +411,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
@ -455,7 +433,13 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$this->client->post('orders/'.$data->orderId.'/notes', [
|
||||
'note' => 'Tracking Code: ' . $trackingCode
|
||||
]);
|
||||
$this->WooCommerceLog("Tracking Code Rückmeldung für Auftrag: $data->orderId", $trackingCode);
|
||||
|
||||
$this->logger->info("WooCommerce Tracking Code Rückmeldung für Auftrag: ".$data->orderId,
|
||||
[
|
||||
'orderId' => $data->orderId,
|
||||
'trackingCode' => $trackingCode
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$updateData = [
|
||||
@ -472,12 +456,16 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
],
|
||||
];
|
||||
$this->client->put('orders/'.$data->orderId, $updateData);
|
||||
$this->WooCommerceLog("Statusrückmeldung 'completed' für Auftrag: $data->orderId", $this->statusCompleted );
|
||||
|
||||
$this->logger->info("WooCommerce Statusrückmeldung 'completed' für Auftrag: ".$data->orderId,
|
||||
[
|
||||
'orderId' => $data->orderId,
|
||||
'status' => $this->statusCompleted
|
||||
]
|
||||
);
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function syncs the current stock to the remote WooCommerce shop
|
||||
* @return int
|
||||
@ -524,8 +512,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
if (empty($remoteIdInformation['id'])) {
|
||||
// The online shop doesnt know this article, write to log and continue with next product
|
||||
$this->WooCommerceLog("Artikel $nummer wurde im Online-Shop nicht gefunden! Falsche Artikelnummer im Shop hinterlegt?");
|
||||
|
||||
$this->logger->error("WooCommerce Artikel $nummer wurde im Online-Shop nicht gefunden! Falsche Artikelnummer im Shop hinterlegt?");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -541,21 +529,19 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
}else{
|
||||
$result = $this->client->put('products/' . $remoteIdInformation['id'], $updateProductParams);
|
||||
}
|
||||
$this->WooCommerceLog("WooCommerce Lagerzahlenübertragung für Artikel: $nummer / $remoteIdInformation[id] - Anzahl: $lageranzahl", $result);
|
||||
|
||||
$this->logger->error("WooCommerce Lagerzahlenübertragung für Artikel: $nummer / $remoteIdInformation[id] - Anzahl: $lageranzahl",
|
||||
[
|
||||
'result' => $result
|
||||
]
|
||||
);
|
||||
$anzahl++;
|
||||
}
|
||||
|
||||
|
||||
return $anzahl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function ImportStorniereAuftrag() {
|
||||
$orderId = $this->CatchRemoteCommand('data')['auftrag'];
|
||||
|
||||
|
||||
if (!empty($orderId)) {
|
||||
$this->client->put('orders/'.$orderId, [
|
||||
'status' => 'cancelled',
|
||||
@ -563,22 +549,13 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
} else {
|
||||
return 'failed';
|
||||
}
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
|
||||
public function ImportSendList() {
|
||||
|
||||
|
||||
$tmp = $this->catchRemoteCommand('data');
|
||||
|
||||
$anzahl = 0;
|
||||
|
||||
for($i=0;$i<(!empty($tmp)?count($tmp):0);$i++){
|
||||
|
||||
|
||||
|
||||
$artikel = $tmp[$i]['artikel'];
|
||||
$nummer = $tmp[$i]['nummer'];
|
||||
if(!empty($tmp[$i]['artikelnummer_fremdnummern'][0]['nummer'])){
|
||||
@ -604,7 +581,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$dim_width = $tmp[$i]['breite'];
|
||||
$dim_height = $tmp[$i]['hoehe'];
|
||||
|
||||
|
||||
// Sanitize dimensions
|
||||
if (self::emptyString($weight_kg))
|
||||
$weight_kg = null;
|
||||
@ -619,11 +595,9 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$dim_height = null;
|
||||
|
||||
|
||||
|
||||
$meta_desc = $tmp[$i]['metadescription_de'];
|
||||
$meta_title = $tmp[$i]['metatitle_de'];
|
||||
|
||||
|
||||
$pseudopreis = $tmp[$i]['pseudopreis'];//*1.19;
|
||||
if($pseudopreis <= $preis)$pseudopreis = $preis;
|
||||
$steuersatz = $tmp[$i]['steuersatz'];
|
||||
@ -657,7 +631,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Attributes that are used for both updating an existing product as well as creating a new one
|
||||
$commonProductAtts = [
|
||||
'name' => $name_de,
|
||||
@ -675,7 +648,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
'meta_data' => $commonMetaData,
|
||||
];
|
||||
|
||||
|
||||
if($lageranzahl===0){
|
||||
$commonProductAtts['stock_status'] = 'outofstock';
|
||||
$commonProductAtts['manage_stock'] = true;
|
||||
@ -693,30 +665,22 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$commonProductAtts['stock_quantity'] = (int)$lageranzahl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!is_null($product_id)) {
|
||||
// Such a product already appears to exist, so we update it
|
||||
$this->client->put('products/'.$product_id, array_merge([
|
||||
|
||||
], $commonProductAtts));
|
||||
|
||||
$this->WooCommerceLog("WooCommerce Artikel geändert für Artikel: $nummer / $product_id");
|
||||
|
||||
$this->logger->info("WooCommerce Artikel geändert für Artikel: $nummer / $product_id");
|
||||
}
|
||||
else{
|
||||
// create a new product
|
||||
$product_id = $this->client->post('products/', array_merge([
|
||||
'sku' => $nummer,
|
||||
], $commonProductAtts))->id;
|
||||
|
||||
|
||||
|
||||
$this->WooCommerceLog("WooCommerce neuer Artikel angelegt: $nummer");
|
||||
|
||||
$this->logger->info("WooCommerce neuer Artikel angelegt: $nummer");
|
||||
}
|
||||
|
||||
|
||||
// TODO: Kategoriebaum und Bilder werden noch nicht uebertragen
|
||||
|
||||
// if(isset($tmp[$i]['kompletter_kategorienbaum'])){
|
||||
@ -729,13 +693,10 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
// $this->save_images($dateien, $product_id);
|
||||
// }
|
||||
|
||||
|
||||
// Update the associated product categories
|
||||
|
||||
$chosenCats = array();
|
||||
if(isset($tmp[$i]['kategorien']) || isset($tmp[$i]['kategoriename'])){
|
||||
|
||||
|
||||
$kategorien = $tmp[$i]['kategorien'];
|
||||
if (!($kategorien) && !self::emptyString($tmp[$i]['kategoriename'])) {
|
||||
$kategorien = array(
|
||||
@ -745,11 +706,9 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
);
|
||||
}
|
||||
if((!empty($kategorien)?count($kategorien):0)>0){
|
||||
|
||||
// Retrive all WC categories via API
|
||||
$allWooCommerceCategories = $this->client->get('products/categories', ['per_page' => '100']);
|
||||
|
||||
|
||||
$searchWpCategories = [];
|
||||
foreach($allWooCommerceCategories as $a){
|
||||
$searchWpCategories[$a->id] = $a->name;
|
||||
@ -764,13 +723,10 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
// If WC has a matching category. We match based on name!
|
||||
if(array_search($wawi_cat_name,array_values($searchWpCategories)) !== false) {
|
||||
|
||||
// get id of that WC Category
|
||||
$wcCatId = array_search($wawi_cat_name,$searchWpCategories);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
// No matching category exists
|
||||
$wcCatId = $this->client->post('products/categories', [
|
||||
'name' => $wawi_cat_name,
|
||||
@ -778,14 +734,12 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($wcCatId) {
|
||||
// update category. We first retrieve the product and append the new product category, not replace the entire category array.
|
||||
$alreadyAssignedWCCats = $this->client->get('products/'.$product_id, [
|
||||
'per_page' => 1,
|
||||
])->categories;
|
||||
|
||||
|
||||
// Get ids of existing categories
|
||||
$existingCategoryIds = [];
|
||||
foreach ($alreadyAssignedWCCats as $cat) {
|
||||
@ -814,16 +768,10 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$anzahl++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $anzahl;
|
||||
|
||||
// return array($product_id,$anzahl,$nummer,$steuersatz, $preis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks the connection to the WooCommerce API by trying a simple API request
|
||||
*
|
||||
@ -839,7 +787,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is called by class.remote.php, initializes some class variables from the DB
|
||||
* @param [type] $shopid [description]
|
||||
@ -876,8 +823,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$ImportWooCommerceApiKey,
|
||||
//WooCommerce API Secret
|
||||
$ImportWooCommerceApiSecret,
|
||||
|
||||
["query_string_auth" => true]
|
||||
["query_string_auth" => true],
|
||||
$this->logger
|
||||
);
|
||||
|
||||
}
|
||||
@ -919,8 +866,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
$ImportWooCommerceApiUrl,
|
||||
$ImportWooCommerceApiKey,
|
||||
$ImportWooCommerceApiSecret,
|
||||
|
||||
['query_string_auth' => true]
|
||||
['query_string_auth' => true],
|
||||
$this->logger
|
||||
);
|
||||
$auth = $this->ImportAuth();
|
||||
|
||||
@ -931,7 +878,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
@ -987,7 +933,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
* @throws WCHttpClientException
|
||||
*/
|
||||
private function getShopIdBySKU($sku) {
|
||||
|
||||
// Retrieve the product with the given sku.
|
||||
// Note: We limit the result set to 1 (per_page=1), so this doesnt work
|
||||
// if there are multiple products with the same sku. should not happen in practice anyway
|
||||
@ -1005,7 +950,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private function getSKUByShopId($articleid, $variationid) {
|
||||
$product = $this->client->get("products/$articleid/variations/$variationid");
|
||||
|
||||
@ -1023,7 +967,7 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
'ausblenden'=>array('abholmodus'=>array('zeitbereich')),
|
||||
'archiv'=>array('ab_nummer'),
|
||||
'felder'=>array(
|
||||
'protokoll'=>array('typ'=>'checkbox','bezeichnung'=>'Protokollierung im Logfile:'),
|
||||
// 'protokoll'=>array('typ'=>'checkbox','bezeichnung'=>'Protokollierung im Logfile:'),
|
||||
'ImportWoocommerceApiKey'=>array('typ'=>'text','bezeichnung'=>'{|API Key:','size'=>60),
|
||||
'ImportWoocommerceApiSecret'=>array('typ'=>'text','bezeichnung'=>'{|API Secret|}:','size'=>60),
|
||||
'ImportWoocommerceApiUrl'=>array('typ'=>'text','bezeichnung'=>'{|API Url|}:','size'=>40),
|
||||
@ -1034,20 +978,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes data to the syslog
|
||||
* @param [type] $nachricht message that will be logged
|
||||
* @param string $dump php array or object, printed using print_r
|
||||
*/
|
||||
public function WooCommerceLog($nachricht, $dump = '')
|
||||
{
|
||||
if($this->protokoll){
|
||||
$this->app->erp->LogFile($nachricht, print_r($dump, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares two Objects and returns true if every variable in items
|
||||
* is the same in $a and $b
|
||||
@ -1068,8 +998,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true when the string entered is empty, after stripping whitespace
|
||||
* @param String $string input
|
||||
@ -1081,11 +1009,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class WCClient
|
||||
{
|
||||
|
||||
/**
|
||||
* WooCommerce REST API WCClient version.
|
||||
*/
|
||||
@ -1098,6 +1023,9 @@ class WCClient
|
||||
*/
|
||||
public $http;
|
||||
|
||||
/** @var Logger $logger */
|
||||
public $logger;
|
||||
|
||||
/**
|
||||
* Initialize client.
|
||||
*
|
||||
@ -1108,9 +1036,10 @@ class WCClient
|
||||
*
|
||||
* @throws WCHttpClientException
|
||||
*/
|
||||
public function __construct($url, $consumerKey, $consumerSecret, $options = [])
|
||||
public function __construct($url, $consumerKey, $consumerSecret, $options = [], $logger)
|
||||
{
|
||||
$this->http = new WCHttpClient($url, $consumerKey, $consumerSecret, $options);
|
||||
$this->http = new WCHttpClient($url, $consumerKey, $consumerSecret, $options, $logger);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1190,7 +1119,6 @@ class WCClient
|
||||
|
||||
class WCResponse
|
||||
{
|
||||
|
||||
/**
|
||||
* WCResponse code.
|
||||
*
|
||||
@ -1289,7 +1217,6 @@ class WCResponse
|
||||
|
||||
class WCOptions
|
||||
{
|
||||
|
||||
/**
|
||||
* Default WooCommerce REST API version.
|
||||
*/
|
||||
@ -1423,7 +1350,6 @@ class WCOptions
|
||||
|
||||
class WCRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* WCRequest url.
|
||||
*
|
||||
@ -1596,7 +1522,6 @@ class WCRequest
|
||||
|
||||
class WCOAuth
|
||||
{
|
||||
|
||||
/**
|
||||
* OAuth signature method algorithm.
|
||||
*/
|
||||
@ -1906,7 +1831,6 @@ class WCHttpClientException extends \Exception
|
||||
|
||||
class WCHttpClient
|
||||
{
|
||||
|
||||
/**
|
||||
* cURL handle.
|
||||
*
|
||||
@ -1963,6 +1887,9 @@ class WCHttpClient
|
||||
*/
|
||||
private $responseHeaders;
|
||||
|
||||
/** @var Logger $logger */
|
||||
public $logger;
|
||||
|
||||
/**
|
||||
* Initialize HTTP client.
|
||||
*
|
||||
@ -1973,7 +1900,7 @@ class WCHttpClient
|
||||
*
|
||||
* @throws WCHttpClientException
|
||||
*/
|
||||
public function __construct($url, $consumerKey, $consumerSecret, $options)
|
||||
public function __construct($url, $consumerKey, $consumerSecret, $options, $logger)
|
||||
{
|
||||
if (!function_exists('curl_version')) {
|
||||
throw new WCHttpClientException('cURL is NOT installed on this server', -1, new WCRequest(), new WCResponse());
|
||||
@ -1983,6 +1910,7 @@ class WCHttpClient
|
||||
$this->url = $this->buildApiUrl($url);
|
||||
$this->consumerKey = $consumerKey;
|
||||
$this->consumerSecret = $consumerSecret;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2171,7 +2099,6 @@ class WCHttpClient
|
||||
*/
|
||||
protected function createResponse()
|
||||
{
|
||||
|
||||
// Set response headers.
|
||||
$this->responseHeaders = '';
|
||||
curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, function ($_, $headers) {
|
||||
@ -2195,7 +2122,7 @@ class WCHttpClient
|
||||
*/
|
||||
protected function setDefaultCurlSettings()
|
||||
{
|
||||
$verifySsl = $this->options->verifySsl();
|
||||
// $verifySsl = $this->options->verifySsl();
|
||||
$timeout = $this->options->getTimeout();
|
||||
$followRedirects = $this->options->getFollowRedirects();
|
||||
|
||||
@ -2236,6 +2163,13 @@ class WCHttpClient
|
||||
$errorCode = $errors->code;
|
||||
}
|
||||
|
||||
$this->logger->error('WooCommerce Error',
|
||||
[
|
||||
'request' => $this->request,
|
||||
'response' => $this->response
|
||||
]
|
||||
);
|
||||
|
||||
throw new WCHttpClientException(
|
||||
sprintf('Error: %s [%s]', $errorMessage, $errorCode),
|
||||
$this->response->getCode(),
|
||||
@ -2294,8 +2228,6 @@ class WCHttpClient
|
||||
public function request($endpoint, $method, $data = [], $parameters = [])
|
||||
{
|
||||
|
||||
|
||||
|
||||
// Initialize cURL.
|
||||
$this->ch = curl_init();
|
||||
|
||||
@ -2308,7 +2240,6 @@ class WCHttpClient
|
||||
// Get response.
|
||||
$response = $this->createResponse();
|
||||
|
||||
|
||||
// Check for cURL errors.
|
||||
if (curl_errno($this->ch)) {
|
||||
throw new WCHttpClientException('cURL Error: ' . \curl_error($this->ch), 0, $request, $response);
|
||||
|
Loading…
Reference in New Issue
Block a user