Merge branch 'refs/heads/master' into cleanup

This commit is contained in:
Andreas Palm 2024-09-28 23:15:07 +02:00
commit 84c34fa151
4 changed files with 165 additions and 218 deletions

View File

@ -26,7 +26,7 @@ class OrderStatusUpdateRequest
/**
* @var Shipment[] list of shipments for this order
*/
public array $shipments;
public array $shipments = array();
public function getTrackingNumberList() : array {
$list = [];

View File

@ -18526,7 +18526,26 @@ function CheckShopTabelle($artikel)
if(!empty($anummer)){
$value['articleid'] = $anummer;
}
$gruppenpreis = $this->GetVerkaufspreisGruppe($j_id,$value['quantity'],$shopexportArr['preisgruppe'],$waehrung);
if ($gruppenpreis) {
$ap = $this->AddPositionManuellPreisNummer(
$doctype,
$auftrag,
$projekt,
$value['articleid'],
$value['quantity'],
$value['name'],
$gruppenpreis,
$j_umsatzsteuer,
$value['rabatt'],
$shop,
$waehrung,
$warenkorb['articlelist'][$key],
$warenkorb['articlelist']
);
} else {
$ap = $this->AddAuftragPositionNummer($auftrag,$value['articleid'],$value['quantity'],$projekt,"",true, $doctype, $warenkorb['articlelist'][$key]);
}
if(isset($value['webid'])){
$this->app->DB->Update("UPDATE $doctype"."_position SET webid = '".$this->app->DB->real_escape_string($value['webid'])."' WHERE id = '$ap' LIMIT 1");
}
@ -19040,7 +19059,7 @@ function CheckShopTabelle($artikel)
}
}
return array("status" => true, "$auftragid" => $auftrag);
return array("status" => true, "auftragid" => $auftrag);
}

View File

@ -2246,7 +2246,6 @@ class Remote {
'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();
}
return 'Fehler: ' . $e->getMessage();
}
if (!empty($this->app->stringcleaner)) {
$this->app->stringcleaner->XMLArray_clean($ret);
}
$this->parseReturn($ret, $id, $action);
return $ret;
$error = 'Fehler Auth: ' . $e->getMessage();
} else {
return 'Fehler: Funktion nicht implementiert: ' . $method;
$error = 'Fehler: ' . $e->getMessage();
}
} elseif ($isActionAuth) {
return 'Fehler: Importer konnte nicht initialisiert werden';
}
} elseif ($isActionAuth) {
return 'Fehler: Dieses Modul ist nicht verfügbar';
}
} elseif ($isActionAuth) {
return 'Fehler: Kein Modul vorhanden';
}
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&uuml;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',
$this->logger->debug('RemoteCommand result (Shop '.$id.') '.$modulename.' '.$action,
[
'error' => $client->getError()
'shop' => $id,
'action' => $action,
'data' => $data,
'result' => $ret
]
);
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);
} else {
$error = 'Fehler: Funktion nicht implementiert: ' . $method;
}
} elseif ($isActionAuth) {
$error = 'Fehler: Importer konnte nicht initialisiert werden';
}
} elseif ($isActionAuth) {
$error = 'Fehler: Dieses Modul ist nicht verf&uuml;gbar';
}
} elseif ($isActionAuth) {
$error = 'Fehler: Kein Modul vorhanden';
} else {
$error = 'Fehler: Kein Modul angegeben';
}
}
if ($error) {
$this->logger->error('RemoteCommand error (Shop '.$id.') '.$modulename.' '.$action,
[
'error' => $error,
'exception' => $exception
]
);
return($error);
}
return $ret;
// Dead code removed here 2024-09-13
}
/**

View File

@ -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&ouml;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;
@ -211,13 +202,9 @@ class Shopimporter_Woocommerce extends ShopimporterBase
'warenkorb' => base64_encode(serialize($order)),
];
}
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 +218,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 +256,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
}
}
if(!empty($wcOrder->subshop)){
$order['subshop'] = $wcOrder->subshop;
}
@ -302,7 +284,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
}
//
//
// Coupon Codes
//
@ -333,7 +314,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
$seperateShippingAddress = !self::compareObjects(
$wcOrder->billing,
$wcOrder->shipping,
@ -360,7 +340,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
$order['lieferadresse_land'] = $wcOrder->shipping->country;
}
// VAT stuff
$vatId = $this->get_wc_meta($wcOrder, "_billing_ustid");
@ -375,7 +354,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
$order['zahlungsweise'] = $wcOrder->payment_method;
$order['lieferung'] = $wcOrder->shipping_lines[0]->method_id;
return $order;
}
@ -408,7 +386,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 +395,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 +409,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
]);
}
return 'ok';
}
@ -446,16 +422,25 @@ class Shopimporter_Woocommerce extends ShopimporterBase
{
/** @var OrderStatusUpdateRequest $data */
$data = $this->CatchRemoteCommand('data');
if ($data->orderStatus !== OrderStatus::Completed)
return;
if (isset($data->shipments)) {
$trackingCode = $data->shipments[0]?->trackingNumber;
}
if (!empty($trackingCode)) {
$this->client->post('orders/'.$data->orderId.'/notes', [
$this->client->post('orders/'.$data->shopOrderId.'/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->shopOrderId,
'trackingCode' => $trackingCode
]
);
}
$updateData = [
@ -463,7 +448,7 @@ class Shopimporter_Woocommerce extends ShopimporterBase
'meta_data' => [
[
'key' => 'tracking_code',
'value' => $data->shipments[0]?->trackingNumber
'value' => $trackingCode
],
[
'key' => 'shipping_carrier',
@ -471,13 +456,17 @@ 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->client->put('orders/'.$data->shopOrderId, $updateData);
$this->logger->info("WooCommerce Statusrückmeldung 'completed' für Auftrag: ".$data->orderId,
[
'orderId' => $data->shopOrderId,
'status' => $this->statusCompleted
]
);
return 'ok';
}
/**
* This function syncs the current stock to the remote WooCommerce shop
* @return int
@ -524,8 +513,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 +530,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 +550,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 +582,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 +596,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 +632,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 +649,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
'meta_data' => $commonMetaData,
];
if($lageranzahl===0){
$commonProductAtts['stock_status'] = 'outofstock';
$commonProductAtts['manage_stock'] = true;
@ -693,30 +666,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 +694,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 +707,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 +724,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 +735,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 +769,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 +788,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
}
}
/**
* This is called by class.remote.php, initializes some class variables from the DB
* @param [type] $shopid [description]
@ -858,6 +806,7 @@ class Shopimporter_Woocommerce extends ShopimporterBase
}
$this->protokoll = $preferences['felder']['protokoll'];
$this->ssl_ignore = $preferences['felder']['ssl_ignore'];
$ImportWooCommerceApiSecret = $preferences['felder']['ImportWoocommerceApiSecret'];
$ImportWooCommerceApiKey = $preferences['felder']['ImportWoocommerceApiKey'];
$ImportWooCommerceApiUrl = $preferences['felder']['ImportWoocommerceApiUrl'];
@ -876,8 +825,9 @@ class Shopimporter_Woocommerce extends ShopimporterBase
$ImportWooCommerceApiKey,
//WooCommerce API Secret
$ImportWooCommerceApiSecret,
["query_string_auth" => true]
["query_string_auth" => true],
$this->logger,
$this->ssl_ignore
);
}
@ -919,8 +869,9 @@ class Shopimporter_Woocommerce extends ShopimporterBase
$ImportWooCommerceApiUrl,
$ImportWooCommerceApiKey,
$ImportWooCommerceApiSecret,
['query_string_auth' => true]
['query_string_auth' => true],
$this->logger,
$this->ssl_ignore
);
$auth = $this->ImportAuth();
@ -931,7 +882,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
return null;
}
/**
* @return array[]
*/
@ -987,7 +937,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 +954,6 @@ class Shopimporter_Woocommerce extends ShopimporterBase
return null;
}
private function getSKUByShopId($articleid, $variationid) {
$product = $this->client->get("products/$articleid/variations/$variationid");
@ -1023,7 +971,8 @@ 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:'),
'ssl_ignore'=>array('typ'=>'checkbox','bezeichnung'=>'SSL-Prüfung abschalten:','info' => 'Nur für Testzwecke!'),
'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 +983,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 +1003,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 +1014,8 @@ class Shopimporter_Woocommerce extends ShopimporterBase
}
class WCClient
{
/**
* WooCommerce REST API WCClient version.
*/
@ -1098,6 +1028,11 @@ class WCClient
*/
public $http;
/** @var Logger $logger */
public $logger;
public $ssl_ignore = false;
/**
* Initialize client.
*
@ -1108,9 +1043,10 @@ class WCClient
*
* @throws WCHttpClientException
*/
public function __construct($url, $consumerKey, $consumerSecret, $options = [])
public function __construct($url, $consumerKey, $consumerSecret, $options = [], $logger, $ssl_ignore)
{
$this->http = new WCHttpClient($url, $consumerKey, $consumerSecret, $options);
$this->http = new WCHttpClient($url, $consumerKey, $consumerSecret, $options, $logger, $ssl_ignore);
$this->logger = $logger;
}
/**
@ -1190,7 +1126,6 @@ class WCClient
class WCResponse
{
/**
* WCResponse code.
*
@ -1289,7 +1224,6 @@ class WCResponse
class WCOptions
{
/**
* Default WooCommerce REST API version.
*/
@ -1423,7 +1357,6 @@ class WCOptions
class WCRequest
{
/**
* WCRequest url.
*
@ -1596,7 +1529,6 @@ class WCRequest
class WCOAuth
{
/**
* OAuth signature method algorithm.
*/
@ -1906,7 +1838,6 @@ class WCHttpClientException extends \Exception
class WCHttpClient
{
/**
* cURL handle.
*
@ -1963,6 +1894,11 @@ class WCHttpClient
*/
private $responseHeaders;
/** @var Logger $logger */
public $logger;
public $ssl_ignore = false;
/**
* Initialize HTTP client.
*
@ -1973,7 +1909,7 @@ class WCHttpClient
*
* @throws WCHttpClientException
*/
public function __construct($url, $consumerKey, $consumerSecret, $options)
public function __construct($url, $consumerKey, $consumerSecret, $options, $logger, $ssl_ignore)
{
if (!function_exists('curl_version')) {
throw new WCHttpClientException('cURL is NOT installed on this server', -1, new WCRequest(), new WCResponse());
@ -1983,6 +1919,8 @@ class WCHttpClient
$this->url = $this->buildApiUrl($url);
$this->consumerKey = $consumerKey;
$this->consumerSecret = $consumerSecret;
$this->logger = $logger;
$this->ssl_ignore = $ssl_ignore;
}
/**
@ -2171,7 +2109,6 @@ class WCHttpClient
*/
protected function createResponse()
{
// Set response headers.
$this->responseHeaders = '';
curl_setopt($this->ch, CURLOPT_HEADERFUNCTION, function ($_, $headers) {
@ -2195,7 +2132,10 @@ class WCHttpClient
*/
protected function setDefaultCurlSettings()
{
if (!$this->ssl_ignore) {
$verifySsl = $this->options->verifySsl();
}
$timeout = $this->options->getTimeout();
$followRedirects = $this->options->getFollowRedirects();
@ -2236,6 +2176,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 +2241,6 @@ class WCHttpClient
public function request($endpoint, $method, $data = [], $parameters = [])
{
// Initialize cURL.
$this->ch = curl_init();
@ -2308,7 +2253,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);