6
6
7
7
use Magento \Framework \App \Action \HttpPostActionInterface ;
8
8
use Magento \Framework \App \RequestInterface ;
9
- use Meta \Conversion \Helper \ServerSideHelper ;
10
- use Meta \Conversion \Helper \ServerEventFactory ;
11
9
use Meta \BusinessExtension \Helper \FBEHelper ;
12
10
use Magento \Framework \Controller \Result \JsonFactory ;
13
11
use Magento \Framework \Controller \Result \Json ;
12
+ use Magento \Framework \MessageQueue \PublisherInterface ;
13
+ use Magento \Framework \Serialize \Serializer \Json as JsonSerializer ;
14
14
15
15
class Tracker implements HttpPostActionInterface
16
16
{
@@ -19,11 +19,6 @@ class Tracker implements HttpPostActionInterface
19
19
*/
20
20
private $ request ;
21
21
22
- /**
23
- * @var ServerSideHelper
24
- */
25
- private $ serverSideHelper ;
26
-
27
22
/**
28
23
* @var FBEHelper
29
24
*/
@@ -40,33 +35,36 @@ class Tracker implements HttpPostActionInterface
40
35
private $ jsonFactory ;
41
36
42
37
/**
43
- * @var ServerEventFactory
38
+ * @var PublisherInterface
44
39
*/
45
- private $ serverEventFactory ;
40
+ private $ publisher ;
41
+
42
+ /**
43
+ * @var JsonSerializer
44
+ */
45
+ private $ jsonSerializer ;
46
46
47
47
/**
48
- * Constructor
49
- *
50
48
* @param RequestInterface $request
51
- * @param ServerSideHelper $serverSideHelper
52
49
* @param FBEHelper $fbeHelper
53
50
* @param JsonFactory $jsonFactory
54
- * @param ServerEventFactory $serverEventFactory
51
+ * @param PublisherInterface $publisher
52
+ * @param JsonSerializer $jsonSerializer
55
53
* @param array $pixelEvents
56
54
*/
57
55
public function __construct (
58
56
RequestInterface $ request ,
59
- ServerSideHelper $ serverSideHelper ,
60
57
FBEHelper $ fbeHelper ,
61
58
JsonFactory $ jsonFactory ,
62
- ServerEventFactory $ serverEventFactory ,
59
+ PublisherInterface $ publisher ,
60
+ JsonSerializer $ jsonSerializer ,
63
61
array $ pixelEvents = []
64
62
) {
65
63
$ this ->request = $ request ;
66
- $ this ->serverSideHelper = $ serverSideHelper ;
67
64
$ this ->fbeHelper = $ fbeHelper ;
68
65
$ this ->jsonFactory = $ jsonFactory ;
69
- $ this ->serverEventFactory = $ serverEventFactory ;
66
+ $ this ->publisher = $ publisher ;
67
+ $ this ->jsonSerializer = $ jsonSerializer ;
70
68
$ this ->pixelEvents = $ pixelEvents ;
71
69
}
72
70
@@ -81,22 +79,13 @@ public function execute(): Json
81
79
try {
82
80
$ params = $ this ->request ->getParams ();
83
81
$ eventName = $ params ['eventName ' ];
84
- $ eventId = $ params ['eventId ' ];
85
82
86
83
if ($ eventName ) {
87
84
$ payload = $ this ->pixelEvents [$ eventName ]->getPayload ($ params );
85
+ $ payload ['event_id ' ] = $ params ['eventId ' ];
86
+ $ payload ['event_type ' ] = $ this ->pixelEvents [$ eventName ]->getEventType ();
88
87
if (isset ($ payload )) {
89
- // Add source and pluginVersion in the payload as custom properties
90
- $ payload ['custom_properties ' ] = [];
91
- $ payload ['custom_properties ' ]['source ' ] = $ this ->fbeHelper ->getSource ();
92
- $ payload ['custom_properties ' ]['pluginVersion ' ] = $ this ->fbeHelper ->getPluginVersion ();
93
- $ eventType = $ this ->pixelEvents [$ eventName ]->getEventType ();
94
- $ event = $ this ->serverEventFactory ->createEvent ($ eventType , array_filter ($ payload ), $ eventId );
95
- if (isset ($ payload ['userDataFromOrder ' ])) {
96
- $ this ->serverSideHelper ->sendEvent ($ event , $ payload ['userDataFromOrder ' ]);
97
- } else {
98
- $ this ->serverSideHelper ->sendEvent ($ event );
99
- }
88
+ $ this ->publisher ->publish ('send.conversion.event.to.meta ' , $ this ->jsonSerializer ->serialize ($ payload ));
100
89
$ response ['success ' ] = true ;
101
90
}
102
91
}
0 commit comments