11
11
use Algolia \AlgoliaSearch \Helper \Entity \SuggestionHelper ;
12
12
use Algolia \AlgoliaSearch \Helper \LandingPageHelper ;
13
13
use Algolia \AlgoliaSearch \Registry \CurrentCategory ;
14
+ use Algolia \AlgoliaSearch \Registry \CurrentProduct ;
14
15
use Algolia \AlgoliaSearch \Service \Product \SortingTransformer ;
15
- use Magento \Catalog \Model \Product ;
16
+ use Magento \Catalog \Api \Data \CategoryInterface ;
17
+ use Magento \Catalog \Api \Data \ProductInterface ;
16
18
use Magento \Checkout \Model \Session as CheckoutSession ;
17
19
use Magento \Customer \Model \Context as CustomerContext ;
18
20
use Magento \Framework \App \ActionInterface ;
19
21
use Magento \Framework \App \Http \Context as HttpContext ;
22
+ use Magento \Framework \Currency \Exception \CurrencyException ;
20
23
use Magento \Framework \Data \CollectionDataSourceInterface ;
21
24
use Magento \Framework \Data \Form \FormKey ;
25
+ use Magento \Framework \Exception \LocalizedException ;
26
+ use Magento \Framework \Exception \NoSuchEntityException ;
22
27
use Magento \Framework \Locale \Currency ;
23
28
use Magento \Framework \Locale \Format ;
24
- use Algolia \AlgoliaSearch \Registry \CurrentProduct ;
25
29
use Magento \Framework \Stdlib \DateTime \DateTime ;
26
30
use Magento \Framework \Url \Helper \Data as UrlHelper ;
27
31
use Magento \Framework \View \Element \Template ;
28
- use Magento \Framework \View \Element \Template \Context ;
29
32
use Magento \Sales \Model \Order ;
30
33
use Magento \Search \Helper \Data as CatalogSearchHelper ;
34
+ use Magento \Store \Api \Data \StoreInterface ;
31
35
32
36
class Algolia extends Template implements CollectionDataSourceInterface
33
37
{
34
- protected $ priceKey ;
38
+ protected ? string $ priceKey = null ;
35
39
36
40
public function __construct (
37
41
protected ConfigHelper $ config ,
@@ -61,66 +65,70 @@ public function __construct(
61
65
}
62
66
63
67
/**
64
- * @return \Magento\Store\Model\Store
68
+ * @throws NoSuchEntityException
65
69
*/
66
- public function getStore ()
70
+ public function getStore (): StoreInterface
67
71
{
68
- /** @var \Magento\Store\Model\Store $store */
69
- $ store = $ this ->_storeManager ->getStore ();
70
-
71
- return $ store ;
72
+ return $ this ->_storeManager ->getStore ();
72
73
}
73
74
74
- public function getConfigHelper ()
75
+ public function getConfigHelper (): ConfigHelper
75
76
{
76
77
return $ this ->config ;
77
78
}
78
79
79
- public function getCoreHelper ()
80
+ public function getCoreHelper (): CoreHelper
80
81
{
81
82
return $ this ->coreHelper ;
82
83
}
83
84
84
- public function getProductHelper ()
85
+ public function getProductHelper (): ProductHelper
85
86
{
86
87
return $ this ->productHelper ;
87
88
}
88
89
89
- public function getCategoryHelper ()
90
+ public function getCategoryHelper (): CategoryHelper
90
91
{
91
92
return $ this ->categoryHelper ;
92
93
}
93
94
94
- public function getSuggestionHelper ()
95
+ public function getSuggestionHelper (): SuggestionHelper
95
96
{
96
97
return $ this ->suggestionHelper ;
97
98
}
98
99
99
- public function getCatalogSearchHelper ()
100
+ public function getCatalogSearchHelper (): CatalogSearchHelper
100
101
{
101
102
return $ this ->catalogSearchHelper ;
102
103
}
103
104
104
- public function getAlgoliaHelper ()
105
+ public function getAlgoliaHelper (): AlgoliaHelper
105
106
{
106
107
return $ this ->algoliaHelper ;
107
108
}
108
109
109
- public function getPersonalizationHelper ()
110
+ public function getPersonalizationHelper (): PersonalizationHelper
110
111
{
111
112
return $ this ->personalizationHelper ;
112
113
}
113
114
114
- public function getCurrencySymbol ()
115
+ /**
116
+ * @throws CurrencyException|NoSuchEntityException
117
+ */
118
+ public function getCurrencySymbol (): ?string
115
119
{
116
120
return $ this ->currency ->getCurrency ($ this ->getCurrencyCode ())->getSymbol ();
117
121
}
118
- public function getCurrencyCode ()
122
+
123
+ /**
124
+ * @throws NoSuchEntityException
125
+ */
126
+ public function getCurrencyCode (): ?string
119
127
{
120
128
return $ this ->getStore ()->getCurrentCurrencyCode ();
121
129
}
122
130
123
- public function getPriceFormat ()
131
+ public function getPriceFormat (): array
124
132
{
125
133
return $ this ->format ->getPriceFormat ();
126
134
}
@@ -130,7 +138,10 @@ public function getGroupId()
130
138
return $ this ->httpContext ->getValue (CustomerContext::CONTEXT_GROUP );
131
139
}
132
140
133
- public function getPriceKey ()
141
+ /**
142
+ * @throws NoSuchEntityException
143
+ */
144
+ public function getPriceKey (): string
134
145
{
135
146
if ($ this ->priceKey === null ) {
136
147
$ currencyCode = $ this ->getCurrencyCode ();
@@ -146,29 +157,34 @@ public function getPriceKey()
146
157
return $ this ->priceKey ;
147
158
}
148
159
149
- public function getStoreId ()
160
+ /**
161
+ * @throws NoSuchEntityException
162
+ */
163
+ public function getStoreId (): int
150
164
{
151
165
return $ this ->getStore ()->getStoreId ();
152
166
}
153
167
154
- public function getCurrentCategory ()
168
+ public function getCurrentCategory (): CategoryInterface
155
169
{
156
170
return $ this ->currentCategory ->get ();
157
171
}
158
172
159
- /** @return Product */
160
- public function getCurrentProduct ()
173
+ public function getCurrentProduct (): ProductInterface
161
174
{
162
175
return $ this ->currentProduct ->get ();
163
176
}
164
177
165
- /** @return Order */
166
- public function getLastOrder ()
178
+ public function getLastOrder (): Order
167
179
{
168
180
return $ this ->checkoutSession ->getLastRealOrder ();
169
181
}
170
182
171
- public function getAddToCartParams () : array
183
+ /**
184
+ * @return array<string, string>
185
+ * @throws LocalizedException
186
+ */
187
+ public function getAddToCartParams (): array
172
188
{
173
189
return [
174
190
'action ' => $ this ->_urlBuilder ->getUrl ('checkout/cart/add ' , []),
@@ -177,15 +193,15 @@ public function getAddToCartParams() : array
177
193
];
178
194
}
179
195
180
- public function getTimestamp ()
196
+ public function getTimestamp (): int | false
181
197
{
182
198
return $ this ->date ->gmtTimestamp ('today midnight ' );
183
199
}
184
200
185
201
/**
186
202
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
187
203
*/
188
- protected function getAddToCartUrl ($ additional = [])
204
+ protected function getAddToCartUrl ($ additional = []): string
189
205
{
190
206
$ continueUrl = $ this ->urlHelper ->getEncodedUrl ($ this ->_urlBuilder ->getCurrentUrl ());
191
207
$ urlParamName = ActionInterface::PARAM_NAME_URL_ENCODED ;
@@ -199,7 +215,7 @@ protected function getAddToCartUrl($additional = [])
199
215
return $ this ->_urlBuilder ->getUrl ('checkout/cart/add ' , $ routeParams );
200
216
}
201
217
202
- protected function getCurrentLandingPage ()
218
+ protected function getCurrentLandingPage (): LandingPage | null | false
203
219
{
204
220
$ landingPageId = $ this ->getRequest ()->getParam ('landing_page_id ' );
205
221
if (!$ landingPageId ) {
0 commit comments