27
27
use Magento \Catalog \Model \Product ;
28
28
use Magento \Catalog \Model \Product \Visibility ;
29
29
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
30
+ use Magento \Catalog \Pricing \Price \FinalPrice ;
30
31
use Magento \Framework \App \ActionInterface ;
31
32
use Magento \Framework \App \Http \Context as HttpContext ;
33
+ use Magento \Framework \App \ObjectManager ;
34
+ use Magento \Framework \DataObject \IdentityInterface ;
35
+ use Magento \Framework \Exception \LocalizedException ;
32
36
use Magento \Framework \Exception \NoSuchEntityException ;
37
+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
38
+ use Magento \Framework \Pricing \Render ;
33
39
use Magento \Framework \Stdlib \DateTime \DateTime ;
34
40
use Magento \Framework \Url \EncoderInterface ;
41
+ use Magento \Widget \Block \BlockInterface ;
35
42
use Mageplaza \Productslider \Helper \Data ;
36
43
use Mageplaza \Productslider \Model \Config \Source \Additional ;
37
44
38
45
/**
39
46
* Class AbstractSlider
40
47
* @package Mageplaza\Productslider\Block
41
48
*/
42
- abstract class AbstractSlider extends AbstractProduct
49
+ abstract class AbstractSlider extends AbstractProduct implements BlockInterface, IdentityInterface
43
50
{
51
+ private $ priceCurrency ;
52
+
44
53
/**
45
54
* @var DateTime
46
55
*/
@@ -133,6 +142,7 @@ public function getCacheKeyInfo()
133
142
{
134
143
return [
135
144
'MAGEPLAZA_PRODUCT_SLIDER ' ,
145
+ $ this ->getPriceCurrency ()->getCurrency ()->getCode (),
136
146
$ this ->_storeManager ->getStore ()->getId (),
137
147
$ this ->httpContext ->getValue (\Magento \Customer \Model \Context::CONTEXT_GROUP ),
138
148
$ this ->getSliderId ()
@@ -157,6 +167,18 @@ public function getDisplayAdditional()
157
167
return $ display ;
158
168
}
159
169
170
+ /**
171
+ * @return mixed
172
+ */
173
+ private function getPriceCurrency ()
174
+ {
175
+ if ($ this ->priceCurrency === null ) {
176
+ $ this ->priceCurrency = ObjectManager::getInstance ()
177
+ ->get (PriceCurrencyInterface::class);
178
+ }
179
+ return $ this ->priceCurrency ;
180
+ }
181
+
160
182
/**
161
183
* Get post parameters.
162
184
*
@@ -185,6 +207,61 @@ public function canShowPrice()
185
207
return in_array (Additional::SHOW_PRICE , $ this ->getDisplayAdditional (), true );
186
208
}
187
209
210
+ /**
211
+ * @return bool|\Magento\Framework\View\Element\BlockInterface
212
+ * @throws LocalizedException
213
+ */
214
+ protected function getPriceRender ()
215
+ {
216
+ return $ this ->getLayout ()->getBlock ('product.price.render.default ' );
217
+ }
218
+
219
+ /**
220
+ * @param Product $product
221
+ * @param null $priceType
222
+ * @param string $renderZone
223
+ * @param array $arguments
224
+ *
225
+ * @return string
226
+ * @throws LocalizedException
227
+ */
228
+ public function getProductPriceHtml (
229
+ Product $ product ,
230
+ $ priceType = null ,
231
+ $ renderZone = Render::ZONE_ITEM_LIST ,
232
+ array $ arguments = []
233
+ ) {
234
+ if (!isset ($ arguments ['zone ' ])) {
235
+ $ arguments ['zone ' ] = $ renderZone ;
236
+ }
237
+ $ arguments ['price_id ' ] = isset ($ arguments ['price_id ' ])
238
+ ? $ arguments ['price_id ' ]
239
+ : 'old-price- ' . $ product ->getId () . '- ' . $ priceType ;
240
+ $ arguments ['include_container ' ] = isset ($ arguments ['include_container ' ])
241
+ ? $ arguments ['include_container ' ]
242
+ : true ;
243
+ $ arguments ['display_minimal_price ' ] = isset ($ arguments ['display_minimal_price ' ])
244
+ ? $ arguments ['display_minimal_price ' ]
245
+ : true ;
246
+
247
+ /** @var Render $priceRender */
248
+ $ priceRender = $ this ->getLayout ()->getBlock ('product.price.render.default ' );
249
+ if (!$ priceRender ) {
250
+ $ priceRender = $ this ->getLayout ()->createBlock (
251
+ Render::class,
252
+ 'product.price.render.default ' ,
253
+ ['data ' => ['price_render_handle ' => 'catalog_product_prices ' ]]
254
+ );
255
+ }
256
+
257
+ return $ priceRender ->render (
258
+ FinalPrice::PRICE_CODE ,
259
+ $ product ,
260
+ $ arguments
261
+ );
262
+ }
263
+
264
+
188
265
/**
189
266
* @return bool
190
267
*/
@@ -295,9 +372,13 @@ public function getResponsiveConfig()
295
372
$ responsiveConfig = [];
296
373
}
297
374
375
+ if (empty ($ responsiveConfig )) {
376
+ return '' ;
377
+ }
378
+
298
379
$ responsiveOptions = '' ;
299
380
foreach ($ responsiveConfig as $ config ) {
300
- if ($ config ['size ' ] && $ config ['items ' ]) {
381
+ if (! empty ( $ config ['size ' ]) && ! empty ( $ config ['items ' ]) ) {
301
382
$ responsiveOptions .= $ config ['size ' ] . ':{items: ' . $ config ['items ' ] . '}, ' ;
302
383
}
303
384
}
@@ -339,6 +420,23 @@ public function getStoreId()
339
420
return $ this ->_storeManager ->getStore ()->getId ();
340
421
}
341
422
423
+ /**
424
+ * @return array|string[]
425
+ */
426
+ public function getIdentities ()
427
+ {
428
+ $ identities = [];
429
+ if ($ this ->getProductCollection ()) {
430
+ foreach ($ this ->getProductCollection () as $ product ) {
431
+ if ($ product instanceof IdentityInterface) {
432
+ $ identities += $ product ->getIdentities ();
433
+ }
434
+ }
435
+ }
436
+
437
+ return $ identities ?: [Product::CACHE_TAG ];
438
+ }
439
+
342
440
/**
343
441
* Get Product Count is displayed
344
442
*
0 commit comments