diff --git a/src/Facade/MollieShipment.php b/src/Facade/MollieShipment.php index cdf26a1f5..7fb507aec 100644 --- a/src/Facade/MollieShipment.php +++ b/src/Facade/MollieShipment.php @@ -161,6 +161,7 @@ public function setShipment(string $orderDeliveryId, Context $context): bool $lastTransaction = $this->extractor->extractLastMolliePayment($order->getTransactions()); if (!$lastTransaction instanceof OrderTransactionEntity) { + $this->logger->info( sprintf( 'The last transaction of the order (%s) is not a mollie payment! No shipment will be sent to mollie', @@ -170,7 +171,9 @@ public function setShipment(string $orderDeliveryId, Context $context): bool return false; } + $trackingInfoStruct = $this->createTrackingInfoStructFromDelivery($delivery); + $addedMollieShipment = $this->mollieApiOrderService->setShipment($mollieOrderId, $trackingInfoStruct, $order->getSalesChannelId()); if ($addedMollieShipment) { @@ -467,11 +470,14 @@ private function findMatchingLineItems(OrderEntity $order, string $itemIdentifie private function createTrackingInfoStructFromDelivery(OrderDeliveryEntity $orderDeliveryEntity):?ShipmentTrackingInfoStruct{ $trackingCodes = $orderDeliveryEntity->getTrackingCodes(); $shippingMethod = $orderDeliveryEntity->getShippingMethod(); - if (count($trackingCodes) !== 1 && ! $shippingMethod instanceof ShippingMethodEntity) { + if($shippingMethod === null){ + return null; + } + if (count($trackingCodes) !== 1) { return null; } - return $this->createTrackingInfoStruct($shippingMethod->getName(),$trackingCodes[0], $shippingMethod->getTrackingUrl()); + return $this->createTrackingInfoStruct((string)$shippingMethod->getName(),$trackingCodes[0], (string)$shippingMethod->getTrackingUrl()); } private function createTrackingInfoStruct(string $trackingCarrier, string $trackingCode, string $trackingUrl): ?ShipmentTrackingInfoStruct diff --git a/tests/PHPUnit/Facade/MollieShipment/SetShipmentTest.php b/tests/PHPUnit/Facade/MollieShipment/SetShipmentTest.php index 3b321651b..deee49636 100644 --- a/tests/PHPUnit/Facade/MollieShipment/SetShipmentTest.php +++ b/tests/PHPUnit/Facade/MollieShipment/SetShipmentTest.php @@ -188,7 +188,7 @@ public function testThatOrderDeliveryCustomFieldsAreNotWrittenWhenApiCallUnsucce $deliveryId = $delivery->getId(); $this->orderDeliveryService->method('getDelivery')->willReturn($delivery); $this->mollieApiOrderService->method('setShipment') - ->with($mollieOrderId, $salesChannelId) + ->with($mollieOrderId, null, $salesChannelId) ->willReturn(false); // custom fields for shipping are never written @@ -201,6 +201,7 @@ public function testThatOrderDeliveryCustomFieldsAreNotWrittenWhenApiCallUnsucce public function testThatOrderDeliveryCustomFieldsAreWrittenWhenApiCallSuccessful(): void { $transaction = $this->createTransaction('Kiener\MolliePayments\Handler\Method\FooMethod'); + $order = $this->createOrder($transaction); $mollieOrderId = 'foo'; $customFields[CustomFieldsInterface::MOLLIE_KEY][CustomFieldsInterface::ORDER_KEY] = $mollieOrderId; @@ -215,7 +216,7 @@ public function testThatOrderDeliveryCustomFieldsAreWrittenWhenApiCallSuccessful $deliveryId = $delivery->getId(); $this->orderDeliveryService->method('getDelivery')->willReturn($delivery); $this->mollieApiOrderService->method('setShipment') - ->with($mollieOrderId, $salesChannelId) + ->with($mollieOrderId, null,$salesChannelId) ->willReturn(true); // custom fields for shipping are written