Skip to content

Commit 422e377

Browse files
committed
[TASK] Add Logging for updating payment and shipping
Relates: #752
1 parent 9fbb768 commit 422e377

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎Classes/Controller/Backend/Order/PaymentController.php‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,35 @@
1212
*/
1313

1414
use Extcode\Cart\Controller\Backend\ActionController;
15+
use Extcode\Cart\Domain\Log\LogServiceInterface;
16+
use Extcode\Cart\Domain\Log\Model\Log;
1517
use Extcode\Cart\Domain\Model\Order\Payment;
1618
use Extcode\Cart\Domain\Repository\Order\PaymentRepository;
1719
use Extcode\Cart\Event\Order\UpdateServiceEvent;
20+
use InvalidArgumentException;
1821
use Psr\Http\Message\ResponseInterface;
1922
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
2023

2124
class PaymentController extends ActionController
2225
{
2326
public function __construct(
24-
protected PaymentRepository $paymentRepository
27+
private readonly PaymentRepository $paymentRepository,
28+
private readonly LogServiceInterface $logService,
2529
) {}
2630

2731
public function updateAction(Payment $payment): ResponseInterface
2832
{
29-
// todo: add logging here
3033
$this->paymentRepository->update($payment);
34+
$this->logService->write(
35+
Log::info(
36+
$this->getOrderItemUid($payment),
37+
'updatePayment',
38+
'Payment was set to ' . $payment->getStatus() . '.',
39+
[
40+
'time' => time(),
41+
]
42+
)
43+
);
3144

3245
$event = new UpdateServiceEvent($payment);
3346
$this->eventDispatcher->dispatch($event);
@@ -41,4 +54,15 @@ public function updateAction(Payment $payment): ResponseInterface
4154

4255
return $this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $payment->getItem()]);
4356
}
57+
58+
private function getOrderItemUid(Payment $payment): int
59+
{
60+
$orderItemUid = $payment->getItem()?->getUid();
61+
62+
if (is_null($orderItemUid)) {
63+
throw new InvalidArgumentException('Method should only called for persisted orders.', 1774715307);
64+
}
65+
66+
return $orderItemUid;
67+
}
4468
}

‎Classes/Controller/Backend/Order/ShippingController.php‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,35 @@
1212
*/
1313

1414
use Extcode\Cart\Controller\Backend\ActionController;
15+
use Extcode\Cart\Domain\Log\LogServiceInterface;
16+
use Extcode\Cart\Domain\Log\Model\Log;
1517
use Extcode\Cart\Domain\Model\Order\Shipping;
1618
use Extcode\Cart\Domain\Repository\Order\ShippingRepository;
1719
use Extcode\Cart\Event\Order\UpdateServiceEvent;
20+
use InvalidArgumentException;
1821
use Psr\Http\Message\ResponseInterface;
1922
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
2023

2124
class ShippingController extends ActionController
2225
{
2326
public function __construct(
24-
protected ShippingRepository $shippingRepository
27+
private readonly ShippingRepository $shippingRepository,
28+
private readonly LogServiceInterface $logService,
2529
) {}
2630

2731
public function updateAction(Shipping $shipping): ResponseInterface
2832
{
29-
// todo: add logging here
3033
$this->shippingRepository->update($shipping);
34+
$this->logService->write(
35+
Log::info(
36+
$this->getOrderItemUid($shipping),
37+
'updateShipping',
38+
'Shipping was set to ' . $shipping->getStatus() . '.',
39+
[
40+
'time' => time(),
41+
]
42+
)
43+
);
3144

3245
$event = new UpdateServiceEvent($shipping);
3346
$this->eventDispatcher->dispatch($event);
@@ -41,4 +54,15 @@ public function updateAction(Shipping $shipping): ResponseInterface
4154

4255
return $this->redirect('show', 'Backend\Order\Order', null, ['orderItem' => $shipping->getItem()]);
4356
}
57+
58+
private function getOrderItemUid(Shipping $shipping): int
59+
{
60+
$orderItemUid = $shipping->getItem()?->getUid();
61+
62+
if (is_null($orderItemUid)) {
63+
throw new InvalidArgumentException('Method should only called for persisted orders.', 1774715307);
64+
}
65+
66+
return $orderItemUid;
67+
}
4468
}

0 commit comments

Comments
 (0)