1212 */
1313
1414use Extcode \Cart \Controller \Backend \ActionController ;
15+ use Extcode \Cart \Domain \Log \LogServiceInterface ;
16+ use Extcode \Cart \Domain \Log \Model \Log ;
1517use Extcode \Cart \Domain \Model \Order \Shipping ;
1618use Extcode \Cart \Domain \Repository \Order \ShippingRepository ;
1719use Extcode \Cart \Event \Order \UpdateServiceEvent ;
20+ use InvalidArgumentException ;
1821use Psr \Http \Message \ResponseInterface ;
1922use TYPO3 \CMS \Extbase \Utility \LocalizationUtility ;
2023
2124class 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