6
6
use Algolia \AlgoliaSearch \Helper \InsightsHelper ;
7
7
use Magento \Framework \Event \Observer ;
8
8
use Magento \Framework \Event \ObserverInterface ;
9
+ use Psr \Log \LoggerInterface ;
9
10
10
11
class CheckoutCartProductAddAfter implements ObserverInterface
11
12
{
@@ -15,12 +16,17 @@ class CheckoutCartProductAddAfter implements ObserverInterface
15
16
/** @var InsightsHelper */
16
17
private $ insightsHelper ;
17
18
19
+ /** @var LoggerInterface */
20
+ private $ logger ;
21
+
18
22
public function __construct (
19
23
Data $ dataHelper ,
20
- InsightsHelper $ insightsHelper
24
+ InsightsHelper $ insightsHelper ,
25
+ LoggerInterface $ logger
21
26
) {
22
27
$ this ->dataHelper = $ dataHelper ;
23
28
$ this ->insightsHelper = $ insightsHelper ;
29
+ $ this ->logger = $ logger ;
24
30
}
25
31
26
32
/**
@@ -58,19 +64,27 @@ public function execute(Observer $observer)
58
64
if ($ this ->getConfigHelper ()->isClickConversionAnalyticsEnabled ($ storeId )
59
65
&& $ this ->getConfigHelper ()->getConversionAnalyticsMode ($ storeId ) === 'add_to_cart ' ) {
60
66
if ($ product ->hasData ('queryId ' )) {
61
- $ userClient ->convertedObjectIDsAfterSearch (
67
+ try {
68
+ $ userClient ->convertedObjectIDsAfterSearch (
69
+ __ ('Added to Cart ' ),
70
+ $ this ->dataHelper ->getIndexName ('_products ' , $ storeId ),
71
+ [$ product ->getId ()],
72
+ $ product ->getData ('queryId ' )
73
+ );
74
+ } catch (\Exception $ e ) {
75
+ $ this ->logger ->critical ($ e );
76
+ }
77
+ }
78
+ } else {
79
+ try {
80
+ $ userClient ->convertedObjectIDs (
62
81
__ ('Added to Cart ' ),
63
82
$ this ->dataHelper ->getIndexName ('_products ' , $ storeId ),
64
- [$ product ->getId ()],
65
- $ product ->getData ('queryId ' )
83
+ [$ product ->getId ()]
66
84
);
85
+ } catch (\Exception $ e ) {
86
+ $ this ->logger ->critical ($ e );
67
87
}
68
- } else {
69
- $ userClient ->convertedObjectIDs (
70
- __ ('Added to Cart ' ),
71
- $ this ->dataHelper ->getIndexName ('_products ' , $ storeId ),
72
- [$ product ->getId ()]
73
- );
74
88
}
75
89
}
76
90
}
0 commit comments