Fix broken ShopUpdates after move to "versandpakete"

This commit is contained in:
Andreas Palm 2024-04-02 23:36:04 +02:00
parent bd94ac8e15
commit 1ab2bea2f1
10 changed files with 233 additions and 226 deletions

View File

@ -0,0 +1,15 @@
<?php
// SPDX-FileCopyrightText: 2024 Andreas Palm
//
// SPDX-License-Identifier: AGPL-3.0-only
namespace Xentral\Modules\Onlineshop\Data;
enum OrderStatus
{
case Imported;
case InProgress;
case Completed;
case Cancelled;
}

View File

@ -0,0 +1,48 @@
<?php
// SPDX-FileCopyrightText: 2024 Andreas Palm
//
// SPDX-License-Identifier: AGPL-3.0-only
namespace Xentral\Modules\Onlineshop\Data;
class OrderStatusUpdateRequest
{
/**
* @var int ID of the (primary/imported) order (ERP domain)
*/
public int $orderId;
/**
* @var string ID of the order (Shop domain)
*/
public string $shopOrderId;
/**
* @var OrderStatus current order status
*/
public OrderStatus $orderStatus;
/**
* @var Shipment[] list of shipments for this order
*/
public array $shipments;
public function getTrackingNumberList() : array {
$list = [];
foreach ($this->shipments as $shipment) {
if (!empty($shipment->trackingNumber))
$list[] = $shipment->trackingNumber;
}
return $list;
}
public function getTrackingUrlList() : array {
$list = [];
foreach ($this->shipments as $shipment) {
if (!empty($shipment->trackingUrl))
$list[] = $shipment->trackingUrl;
}
return $list;
}
}

View File

@ -0,0 +1,30 @@
<?php
// SPDX-FileCopyrightText: 2024 Andreas Palm
//
// SPDX-License-Identifier: AGPL-3.0-only
namespace Xentral\Modules\Onlineshop\Data;
class Shipment
{
/**
* @var int ID of the shipment (ERP domain)
*/
public int $id;
/**
* @var string plain tracking number
*/
public string $trackingNumber;
/**
* @var string URL to view tracking details
*/
public string $trackingUrl;
/**
* @var string shipping method (after mapping to Shop domain)
*/
public string $shippingMethod;
}

View File

@ -387,15 +387,16 @@ function GetLaender()
$join = ''; $join = '';
$where = ''; $where = '';
$app->erp->RunHook('shop_rueckmeldung', 2, $join, $where); $app->erp->RunHook('shop_rueckmeldung', 2, $join, $where);
$sql = "SELECT a.id,apro.zeit, a.shop, l.id as lieferschein, v.id as versandid, l.projekt $sql = "SELECT DISTINCT a.id, a.shop
FROM auftrag AS a FROM auftrag a
LEFT JOIN lieferschein AS l on l.auftragid = a.id LEFT JOIN lieferschein l on l.auftragid = a.id
LEFT JOIN auftrag_protokoll AS apro ON a.id = apro.auftrag AND apro.grund LIKE 'Auftrag importiert vom Shop' LEFT JOIN projekt pr ON l.projekt = pr.id
LEFT JOIN projekt AS pr ON l.projekt = pr.id LEFT JOIN lieferschein_position lp ON lp.lieferschein = l.id
LEFT JOIN versand AS v ON v.lieferschein = l.id LEFT JOIN versandpaket_lieferschein_position vlp ON vlp.lieferschein_position = lp.id
LEFT JOIN versandpakete v ON (v.lieferschein_ohne_pos = l.id OR v.id = vlp.versandpaket)
$join $join
WHERE a.status = 'abgeschlossen' AND $subwhere AND WHERE a.status = 'abgeschlossen' AND $subwhere AND
DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 2 WEEK),'%Y-%m-%d') < a.datum AND DATE_SUB(NOW(),INTERVAL 2 WEEK) < a.datum AND
a.shopextstatus <> 'abgeschlossen' AND a.shop > 0 AND a.shopextstatus <> 'abgeschlossen' AND a.shop > 0 AND
( (
( v.tracking <> '' AND l.status = 'versendet') OR ( v.tracking <> '' AND l.status = 'versendet') OR

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
* SPDX-FileCopyrightText: 2022 Andreas Palm * SPDX-FileCopyrightText: 2022-2024 Andreas Palm
* SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany * SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany
* *
* SPDX-License-Identifier: LicenseRef-EGPL-3.1 * SPDX-License-Identifier: LicenseRef-EGPL-3.1
@ -20,6 +20,10 @@
*/ */
?> ?>
<?php <?php
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
use Xentral\Modules\Onlineshop\Data\Shipment;
use Xentral\Modules\Onlineshop\Data\ShopConnectorResponseInterface; use Xentral\Modules\Onlineshop\Data\ShopConnectorResponseInterface;
class Remote class Remote
@ -2301,133 +2305,58 @@ class Remote
return $result; return $result;
} }
public function getDataToSendForUpdateOrder(int $shopId, int $orderId): array public function getDataToSendForUpdateOrder(int $shopId, int $orderId): ?OrderStatusUpdateRequest
{ {
$orderArr = $this->app->DB->SelectRow("SELECT * FROM `auftrag` WHERE `id` = {$orderId} LIMIT 1"); $orderArr = $this->app->DB->SelectRow("SELECT `zahlungsweise`, `shopextid` FROM `auftrag` WHERE `id` = $orderId LIMIT 1");
$status = $orderArr['status']; if (empty($orderArr))
$zahlungsweise = $orderArr['zahlungsweise']; return null;
$shopextid = $orderArr['shopextid'];
$internet = $orderArr['internet'];
$deliveryNoteArr = $this->app->DB->SelectRow(
"SELECT `id`, `versandart` FROM `lieferschein` WHERE `auftragid` = {$orderId} LIMIT 1"
);
$trackingArr = null;
$versandart = '';
$tracking = '';
$shippingProduct = null;
if(!empty($deliveryNoteArr)) {
$deliveryNoteId = $deliveryNoteArr['id'];
$versandart = $deliveryNoteArr['versandart'];
$query =
"SELECT *
FROM `shopexport_versandarten`
WHERE `aktiv`=1 AND `versandart_wawision` = '{$versandart}' AND `shop` = {$shopId} AND `versandart_wawision` <> ''
LIMIT 1";
$shippingMapping = $this->app->DB->SelectRow($query);
$versandartAusgehend = $shippingMapping['versandart_ausgehend'] ?? null;
$shippingProduct = $shippingMapping['produkt_ausgehend'] ?? null;
if(!empty($versandartAusgehend)){ $data = new OrderStatusUpdateRequest();
$versandart = $versandartAusgehend; $data->orderId = $orderId;
} $data->shopOrderId = $orderArr['shopextid'];
$trackingArr = $this->app->DB->SelectPairs(
sprintf( $statusArr = $this->app->DB->SelectFirstCols("SELECT DISTINCT status FROM auftrag WHERE id = $orderId OR teillieferungvon = $orderId");
"SELECT `id`, `tracking` if (in_array('storniert', $statusArr))
FROM `versand` $data->orderStatus = OrderStatus::Cancelled;
WHERE `lieferschein` = {$deliveryNoteId} AND `tracking` <> '' if (in_array('abgeschlossen', $statusArr))
ORDER BY `id` DESC" $data->orderStatus = OrderStatus::Completed;
) if (in_array('freigegeben', $statusArr))
); $data->orderStatus = OrderStatus::InProgress;
$tracking = ''; if (in_array('angelegt', $statusArr))
if(!empty($trackingArr)) { $data->orderStatus = OrderStatus::Imported;
$tracking = reset($trackingArr);
$sql = "
SELECT
v.id,
v.tracking,
v.tracking_link,
COALESCE(sv.versandart_ausgehend, sv.versandart_shop, v.versandart) versandart
FROM
auftrag a
LEFT JOIN lieferschein l ON
l.auftragid = a.id
LEFT JOIN lieferschein_position lp ON
lp.lieferschein = l.id
LEFT JOIN versandpaket_lieferschein_position vlp ON
vlp.lieferschein_position = lp.id
LEFT JOIN versandpakete v ON
vlp.versandpaket = v.id OR v.lieferschein_ohne_pos = l.id
LEFT JOIN shopexport_versandarten sv ON
sv.versandart_wawision = v.versandart AND sv.shop = $shopId
WHERE a.id = $orderId OR a.teillieferungvon = $orderId
ORDER BY v.id";
$shipments = $this->app->DB->SelectArr($sql);
foreach ($shipments as $shipment) {
$item = new Shipment();
$item->id = $shipment['id'];
$item->trackingNumber = $shipment['tracking'];
$item->trackingUrl = $shipment['tracking_link'];
$item->shippingMethod = $shipment['versandart'];
$data->shipments[] = $item;
} }
$positionen = $this->app->DB->SelectArr( return $data;
"SELECT ap.webid, trim(lp.geliefert)+0 AS `geliefert`, trim(lp.menge)+0 AS `menge`, lp.id
FROM `lieferschein_position` AS `lp`
INNER JOIN `lieferschein` AS `l` ON l.id = lp.lieferschein
INNER JOIN `auftrag` AS `a` ON a.id = l.auftragid
INNER JOIN `auftrag_position` AS `ap` ON ap.id = lp.auftrag_position_id
WHERE l.id = {$deliveryNoteId} AND ap.webid <> '' "
);
$allPositions = false;
if(!empty($positionen)) {
$allPositions = true;
foreach($positionen as $position) {
if($position['geliefert'] > 0) {
$itemlist[] = array('webid'=>$position['webid'],'quantity'=>$position['geliefert']);
if($position['geliefert'] < $position['menge']) {
$allPositions = false;
}
}
elseif($this->app->DB->Select("SELECT trim(sum(geliefert))+0
FROM lieferschein_position
WHERE explodiert_parent = '".$position['id']."' AND lieferschein = '$deliveryNoteId'")) {
$itemlist[] = array('webid'=>$position['webid'],'quantity'=>$position['menge']);
}
else {
$allPositions = false;
}
}
if($allPositions && (!empty($itemlist)?count($itemlist):0) <
$this->app->DB->Select(
sprintf('SELECT count(id) FROM auftrag_position WHERE auftrag = %d', $orderId)
)
) {
$allPositions = false;
}
}
}
if(!empty($itemlist)) {
$data['itemlist'] = $itemlist;
if($allPositions) {
$data['allpositions'] = 1;
}
}
$data['orderId'] = $orderId;
$data['auftrag'] = $shopextid;
$data['internet'] = $internet;
$data['zahlungsweise'] = $zahlungsweise;
$data['versandart'] = $versandart;
if(!empty($trackingArr)) {
$data['trackinglist'] = $trackingArr;
}
if($status==='abgeschlossen') {
$data['versand']='1';
$data['zahlung']='1';
if($shippingProduct !== null) {
$data['shipping_product'] = $shippingProduct;
}
if($tracking!='') {
$data['tracking']=$tracking;
$lastShippingId = (int)$this->app->DB->Select(
sprintf(
"SELECT `id` FROM `versand` WHERE `lieferschein` = %d AND `lieferschein` > 0
ORDER BY `id` DESC LIMIT 1",
$deliveryNoteId
)
);
$trackinglink = $lastShippingId > 0 && method_exists($this->app->erp,'GetTrackinglink')
?$this->app->erp->GetTrackinglink($lastShippingId):'';
if($trackinglink) {
$data['trackinglink'] = $trackinglink;
if(!empty($trackingArr)) {
foreach($trackingArr as $versandId => $track) {
$data['trackinglinklist'][$versandId] = $this->app->erp->GetTrackinglink($versandId);
}
}
}
$trackinglinkRaw = $lastShippingId > 0 && method_exists($this->app->erp,'GetTrackingRawLink')
?$this->app->erp->GetTrackingRawLink($lastShippingId):'';
if(!empty($trackinglinkRaw)) {
$data['trackinglinkraw'] = $trackinglinkRaw;
}
}
}
return $data;
} }
/** /**
@ -2438,9 +2367,10 @@ class Remote
*/ */
public function RemoteUpdateAuftrag($shopId, $orderId) public function RemoteUpdateAuftrag($shopId, $orderId)
{ {
$data = $this->getDataToSendForUpdateOrder((int)$shopId, (int)$orderId); $data = $this->getDataToSendForUpdateOrder((int)$shopId, (int)$orderId);
if($data['versand']=='1' || $data['zahlung']=='1') if($data?->orderStatus !== OrderStatus::Completed)
{ return;
$bearbeiter = 'Cronjob'; $bearbeiter = 'Cronjob';
if(isset($this->app->User)){ if(isset($this->app->User)){
$bearbeiter = $this->app->DB->real_escape_string($this->app->User->GetName()); $bearbeiter = $this->app->DB->real_escape_string($this->app->User->GetName());
@ -2465,7 +2395,6 @@ class Remote
$this->app->erp->AuftragProtokoll($orderId, 'Versandmeldung an Shop &uuml;bertragen', $bearbeiter); $this->app->erp->AuftragProtokoll($orderId, 'Versandmeldung an Shop &uuml;bertragen', $bearbeiter);
$this->app->DB->Update("UPDATE `auftrag` SET `shopextstatus` = 'abgeschlossen' WHERE `id` = $orderId LIMIT 1"); $this->app->DB->Update("UPDATE `auftrag` SET `shopextstatus` = 'abgeschlossen' WHERE `id` = $orderId LIMIT 1");
}
} }
/** /**

View File

@ -6,6 +6,9 @@
* SPDX-License-Identifier: LicenseRef-EGPL-3.1 * SPDX-License-Identifier: LicenseRef-EGPL-3.1
*/ */
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
class Shopimporter_Presta extends ShopimporterBase class Shopimporter_Presta extends ShopimporterBase
{ {
private $app; private $app;
@ -161,18 +164,21 @@ class Shopimporter_Presta extends ShopimporterBase
public function ImportUpdateAuftrag() public function ImportUpdateAuftrag()
{ {
$auftrag = $this->data['auftrag']; /** @var OrderStatusUpdateRequest $data */
$data = $this->CatchRemoteCommand('data');
if ($data->orderStatus !== OrderStatus::Completed)
return;
$obj = $this->prestaRequest('GET', 'order_histories?schema=blank'); $obj = $this->prestaRequest('GET', 'order_histories?schema=blank');
$obj->order_history->id_order = $auftrag; $obj->order_history->id_order = $data->shopOrderId;
$obj->order_history->id_order_state = $this->idabgeschlossen; $obj->order_history->id_order_state = $this->idabgeschlossen;
$this->prestaRequest('POST', 'order_histories', $obj->asXML()); $this->prestaRequest('POST', 'order_histories', $obj->asXML());
$req = $this->prestaRequest('GET', "order_carriers?filter[id_order]=$auftrag&display=[id]"); $req = $this->prestaRequest('GET', "order_carriers?filter[id_order]=$data->shopOrderId&display=[id]");
$orderCarrierId = strval($req->order_carriers->order_carrier[0]->id); $orderCarrierId = strval($req->order_carriers->order_carrier[0]->id);
$req = $this->prestaRequest('GET', "order_carriers/$orderCarrierId"); $req = $this->prestaRequest('GET', "order_carriers/$orderCarrierId");
$req->order_carrier->tracking_number = $this->data['tracking']; $req->order_carrier->tracking_number = join(',', $data->getTrackingNumberList());
$this->prestaRequest('PUT', "order_carriers/$orderCarrierId", $req->asXML()); $this->prestaRequest('PUT', "order_carriers/$orderCarrierId", $req->asXML());
} }

View File

@ -14,6 +14,8 @@
?> ?>
<?php <?php
use Xentral\Components\Http\JsonResponse; use Xentral\Components\Http\JsonResponse;
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
include_once 'Shopimporter_Shopify_Adapter.php'; include_once 'Shopimporter_Shopify_Adapter.php';
@ -3381,17 +3383,21 @@ class Shopimporter_Shopify extends ShopimporterBase
public function ImportUpdateAuftrag() public function ImportUpdateAuftrag()
{ {
$tmp = $this->CatchRemoteCommand('data'); /** @var OrderStatusUpdateRequest $req */
$req = $this->CatchRemoteCommand('data');
if ($req->orderStatus !== OrderStatus::Completed)
return;
// pruefe ob $tmp[datei] vorhanden wenn nicht lege an sonst update [inhalt] und [checksum] // pruefe ob $tmp[datei] vorhanden wenn nicht lege an sonst update [inhalt] und [checksum]
$auftrag = $tmp['auftrag']; $auftrag = $req->shopOrderId;
if(!empty($auftrag)){ if(!empty($auftrag)){
$zahlungok = $tmp['zahlung'];
$versandok = $tmp['versand'];
$tracking = $tmp['tracking'];
$versandart = $tmp['versandart'];
$data = array(); $data = array();
$data['fulfillment'] = array('tracking_number' => $tracking, 'tracking_company' => $versandart, 'notify_customer' => false); $data['fulfillment'] = [
'tracking_numbers' => $req->getTrackingNumberList(),
'tracking_company' => $req->shipments[0]?->shippingMethod,
'notify_customer' => false,
'tracking_urls' => $req->getTrackingUrlList()
];
if(!empty($this->location)){ if(!empty($this->location)){
$data['fulfillment']['location_id'] = $this->location; $data['fulfillment']['location_id'] = $this->location;
} }
@ -3410,16 +3416,10 @@ class Shopimporter_Shopify extends ShopimporterBase
if($this->shopifytracking){ if($this->shopifytracking){
$data['fulfillment']['notify_customer'] = true; $data['fulfillment']['notify_customer'] = true;
} }
if(!empty($tmp['trackinglinkraw'])) {
$data['fulfillment']['tracking_urls'] = [$tmp['trackinglinkraw']];
}
elseif(!empty($tmp['trackinglink'])){
$data['fulfillment']['tracking_urls'] = [$tmp['trackinglink']];
}
$result = $this->adapter->call('orders/' . $auftrag . '/fulfillments.json', 'POST', $data); $result = $this->adapter->call('orders/' . $auftrag . '/fulfillments.json', 'POST', $data);
if($this->logging){ if($this->logging){
$this->app->erp->LogFile(array($tmp, $auftrag, $data, $result['data'])); $this->app->erp->LogFile(array($data, $auftrag, $data, $result['data']));
} }
$this->adapter->call('orders/' . $auftrag . '/metafields.json', 'POST', array('metafield' => [ $this->adapter->call('orders/' . $auftrag . '/metafields.json', 'POST', array('metafield' => [
'key' => 'sync_status', 'key' => 'sync_status',
@ -3429,7 +3429,7 @@ class Shopimporter_Shopify extends ShopimporterBase
])); ]));
}else{ }else{
if($this->logging){ if($this->logging){
$this->app->erp->LogFile(array($tmp, $auftrag,'Kein Auftrag')); $this->app->erp->LogFile(array($data, $auftrag,'Kein Auftrag'));
} }
} }
return 'OK'; return 'OK';

View File

@ -1,4 +1,4 @@
<?php <?php
/* /*
**** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE **** **** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
* *
@ -10,10 +10,12 @@
* to obtain the text of the corresponding license version. * to obtain the text of the corresponding license version.
* *
**** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE **** **** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
*/ */
?> ?>
<?php <?php
use Xentral\Components\Http\JsonResponse; use Xentral\Components\Http\JsonResponse;
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
class Shopimporter_Shopware extends ShopimporterBase class Shopimporter_Shopware extends ShopimporterBase
{ {
@ -2520,38 +2522,19 @@ class Shopimporter_Shopware extends ShopimporterBase
//TODO fuer AuftragImport //TODO fuer AuftragImport
public function ImportUpdateAuftrag() public function ImportUpdateAuftrag()
{ {
$tmp = $this->CatchRemoteCommand('data'); /** @var OrderStatusUpdateRequest $data */
$data = $this->CatchRemoteCommand('data');
if ($data->orderStatus !== OrderStatus::Completed)
return;
// pruefe ob $tmp[datei] vorhanden wenn nicht lege an sonst update [inhalt] und [checksum] // pruefe ob $tmp[datei] vorhanden wenn nicht lege an sonst update [inhalt] und [checksum]
$auftrag = $tmp['auftrag']; $auftrag = $data->shopOrderId;
$zahlungok = $tmp['zahlung'];
$versandok = $tmp['versand'];
$tracking = $tmp['tracking'];
/*if($zahlungok=='ok' || $zahlungok=='1')
$status_zahlung=12;
else
$status_zahlung=1;
if($versandok=='ok' || $versandok=='1')
$status_versand=7;
else
$status_versand=1;*/
/*
$date = new DateTime();
$date->modify('+10 days');
$date = $date->format(DateTime::ISO8601);
*/
$result = $this->adapter->put('orders/'.$auftrag, array( $result = $this->adapter->put('orders/'.$auftrag, array(
// 'paymentStatusId' => $status_zahlung, 'orderStatusId' => $this->abgeschlossenStatusId,
'orderStatusId' => $this->abgeschlossenStatusId,//$status_versand, 'trackingCode' => join(',', $data->getTrackingNumberList())
'trackingCode' => $tracking
//'comment' => 'Neuer Kommentar',
//'transactionId' => '0',
// 'clearedDate' => $date,
)); ));
$this->ShopwareLog("Abschlussstatusrückmeldung für Auftrag: $auftrag", print_r($result,true)); $this->ShopwareLog("Abschlussstatusrückmeldung für Auftrag: $auftrag", print_r($result,true));
//$this->app->DB->Delete("DELETE FROM auftraege WHERE id='$auftrag' LIMIT 1");
return 'ok'; return 'ok';
} }

View File

@ -15,6 +15,8 @@
<?php <?php
use Xentral\Components\Http\JsonResponse; use Xentral\Components\Http\JsonResponse;
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
use Xentral\Modules\Shopware6\Client\Shopware6Client; use Xentral\Modules\Shopware6\Client\Shopware6Client;
use Xentral\Modules\Shopware6\Data\PriceData; use Xentral\Modules\Shopware6\Data\PriceData;
@ -3408,9 +3410,12 @@ class Shopimporter_Shopware6 extends ShopimporterBase
*/ */
public function ImportUpdateAuftrag() public function ImportUpdateAuftrag()
{ {
$tmp = $this->CatchRemoteCommand('data'); /** @var OrderStatusUpdateRequest $data */
$auftrag = $tmp['auftrag']; $data = $this->CatchRemoteCommand('data');
$tracking = $tmp['tracking']; if ($data->orderStatus !== OrderStatus::Completed)
return;
$auftrag = $data->shopOrderId;
$this->shopwareRequest('POST', '_action/order/'.$auftrag.'/state/complete'); $this->shopwareRequest('POST', '_action/order/'.$auftrag.'/state/complete');
@ -3421,17 +3426,17 @@ class Shopimporter_Shopware6 extends ShopimporterBase
$this->shopwareRequest('POST', '_action/order_delivery/'.$deliveryId.'/state/ship'); $this->shopwareRequest('POST', '_action/order_delivery/'.$deliveryId.'/state/ship');
$deliveryData = [ $deliveryData = [
'trackingCodes' => [$tracking] 'trackingCodes' => [$data->getTrackingNumberList()]
]; ];
$this->shopwareRequest('PATCH', 'order-delivery/'.$deliveryId,$deliveryData); $this->shopwareRequest('PATCH', 'order-delivery/'.$deliveryId,$deliveryData);
} }
$this->sendInvoce($auftrag); $this->sendInvoce($auftrag);
$this->addCustomFieldToOrder((string)$auftrag); $this->addCustomFieldToOrder($auftrag);
if(empty($tmp['orderId'])) { if(empty($data->orderId)) {
return; return;
} }
$this->updateStorageForOrderIntId((int)$tmp['orderId']); $this->updateStorageForOrderIntId($data->orderId);
} }
public function ImportStorniereAuftrag() public function ImportStorniereAuftrag()

View File

@ -1,4 +1,4 @@
<?php <?php
/* /*
**** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE **** **** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
* *
@ -10,10 +10,12 @@
* to obtain the text of the corresponding license version. * to obtain the text of the corresponding license version.
* *
**** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE **** **** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
*/ */
?> ?>
<?php <?php
use Xentral\Components\Http\JsonResponse; use Xentral\Components\Http\JsonResponse;
use Xentral\Modules\Onlineshop\Data\OrderStatus;
use Xentral\Modules\Onlineshop\Data\OrderStatusUpdateRequest;
class Shopimporter_Woocommerce extends ShopimporterBase class Shopimporter_Woocommerce extends ShopimporterBase
{ {
@ -442,47 +444,35 @@ class Shopimporter_Woocommerce extends ShopimporterBase
*/ */
public function ImportUpdateAuftrag() public function ImportUpdateAuftrag()
{ {
$tmp = $this->CatchRemoteCommand('data'); /** @var OrderStatusUpdateRequest $data */
$data = $this->CatchRemoteCommand('data');
if ($data->orderStatus !== OrderStatus::Completed)
return;
$orderId = $tmp['auftrag']; $trackingCode = $data->shipments[0]?->trackingNumber;
$paymentOk = $tmp['zahlung'];
$shippingOk = $tmp['versand'];
$trackingCode = $tmp['tracking'];
$carrier = $tmp['versandart'];
if ($paymentOk === 'ok' || $paymentOk === '1'){
$paymentOk = true;
}
if ($shippingOk === 'ok' || $shippingOk === '1'){
$shippingOk = true;
}
if (!empty($trackingCode)) { if (!empty($trackingCode)) {
$this->client->post('orders/'.$orderId.'/notes', [ $this->client->post('orders/'.$data->orderId.'/notes', [
'note' => 'Tracking Code: ' . $trackingCode 'note' => 'Tracking Code: ' . $trackingCode
]); ]);
$this->WooCommerceLog("Tracking Code Rückmeldung für Auftrag: $orderId", $trackingCode); $this->WooCommerceLog("Tracking Code Rückmeldung für Auftrag: $data->orderId", $trackingCode);
} }
if ($paymentOk && $shippingOk) { $updateData = [
$updateData = [ 'status' => $this->statusCompleted,
'status' => $this->statusCompleted, 'meta_data' => [
'meta_data' => [ [
[ 'key' => 'tracking_code',
'key' => 'tracking_code', 'value' => $data->shipments[0]?->trackingNumber
'value' => $trackingCode
],
[
'key' => 'shipping_carrier',
'value' => $carrier
]
], ],
]; [
$this->client->put('orders/'.$orderId, $updateData); 'key' => 'shipping_carrier',
$this->WooCommerceLog("Statusrückmeldung 'completed' für Auftrag: $orderId",$this->statusCompleted ); 'value' => $data->shipments[0]?->shippingMethod
} ]
],
];
$this->client->put('orders/'.$data->orderId, $updateData);
$this->WooCommerceLog("Statusrückmeldung 'completed' für Auftrag: $data->orderId", $this->statusCompleted );
return 'ok'; return 'ok';
} }