8
8
namespace Opengento \Gdpr \Controller \Adminhtml \Guest ;
9
9
10
10
use Exception ;
11
- use Magento \Backend \Model \ View \ Result \ RedirectFactory ;
12
- use Magento \Framework \App \Action \HttpGetActionInterface ;
11
+ use Magento \Backend \App \ Action ;
12
+ use Magento \Backend \App \Action \Context ;
13
13
use Magento \Framework \App \Filesystem \DirectoryList ;
14
- use Magento \Framework \App \RequestInterface ;
15
14
use Magento \Framework \App \Response \Http \FileFactory ;
16
15
use Magento \Framework \App \ResponseInterface ;
17
16
use Magento \Framework \Controller \ResultInterface ;
17
+ use Magento \Framework \Exception \AlreadyExistsException ;
18
+ use Magento \Framework \Exception \CouldNotSaveException ;
18
19
use Magento \Framework \Exception \LocalizedException ;
19
20
use Magento \Framework \Exception \NoSuchEntityException ;
20
- use Magento \Framework \Message \ManagerInterface ;
21
21
use Magento \Framework \Phrase ;
22
22
use Magento \Sales \Api \OrderRepositoryInterface ;
23
23
use Magento \Store \Model \StoreManagerInterface ;
24
+ use Opengento \Gdpr \Api \Data \ExportEntityInterface ;
24
25
use Opengento \Gdpr \Api \ExportEntityManagementInterface ;
25
26
use Opengento \Gdpr \Api \ExportEntityRepositoryInterface ;
26
27
use Opengento \Gdpr \Model \Config ;
27
28
28
- class Export implements HttpGetActionInterface
29
+ class Export extends Action
29
30
{
30
31
public const ADMIN_RESOURCE = 'Opengento_Gdpr::order_export ' ;
31
32
32
33
public function __construct (
33
- private RequestInterface $ request ,
34
- private ManagerInterface $ messageManager ,
34
+ Context $ context ,
35
35
private StoreManagerInterface $ storeManager ,
36
36
private OrderRepositoryInterface $ orderRepository ,
37
37
private ExportEntityManagementInterface $ exportEntityManagement ,
38
38
private ExportEntityRepositoryInterface $ exportEntityRepository ,
39
39
private Config $ config ,
40
- private RedirectFactory $ redirectFactory ,
41
40
private FileFactory $ fileFactory
42
- ) {}
41
+ ) {
42
+ parent ::__construct ($ context );
43
+ }
43
44
44
45
public function execute (): ResultInterface |ResponseInterface
45
46
{
46
47
try {
47
- $ orderId = (int )$ this ->request ->getParam ('id ' );
48
+ $ orderId = (int )$ this ->getRequest () ->getParam ('id ' );
48
49
if ($ this ->isOrderExportEnabled ($ orderId )) {
49
- $ exportEntity = $ this ->exportEntityManagement ->export (
50
- $ this ->exportEntityRepository ->getByEntity ($ orderId , 'order ' )
51
- );
50
+ $ exportEntity = $ this ->exportEntityManagement ->export ($ this ->fetchEntity ($ orderId ));
52
51
53
52
return $ this ->fileFactory ->create (
54
53
'guest_privacy_data_ ' . $ exportEntity ->getEntityId () . '.zip ' ,
@@ -65,7 +64,7 @@ public function execute(): ResultInterface|ResponseInterface
65
64
$ this ->messageManager ->addExceptionMessage ($ e , new Phrase ('An error occurred on the server. ' ));
66
65
}
67
66
68
- return $ this ->redirectFactory ->create ()->setRefererOrBaseUrl ();
67
+ return $ this ->resultRedirectFactory ->create ()->setRefererOrBaseUrl ();
69
68
}
70
69
71
70
/**
@@ -77,4 +76,18 @@ private function isOrderExportEnabled(int $orderId): bool
77
76
$ this ->storeManager ->getStore ($ this ->orderRepository ->get ($ orderId )->getStoreId ())->getWebsiteId ()
78
77
);
79
78
}
79
+
80
+ /**
81
+ * @throws AlreadyExistsException
82
+ * @throws CouldNotSaveException
83
+ * @throws LocalizedException
84
+ */
85
+ private function fetchEntity (int $ orderId ): ExportEntityInterface
86
+ {
87
+ try {
88
+ return $ this ->exportEntityRepository ->getByEntity ($ orderId , 'order ' );
89
+ } catch (NoSuchEntityException ) {
90
+ return $ this ->exportEntityManagement ->create ($ orderId , 'order ' );
91
+ }
92
+ }
80
93
}
0 commit comments