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 \Framework \App \ActionInterface ;
30
31
use Magento \Framework \App \Http \Context as HttpContext ;
31
32
use Magento \Framework \Exception \NoSuchEntityException ;
32
33
use Magento \Framework \Stdlib \DateTime \DateTime ;
34
+ use Magento \Framework \Url \EncoderInterface ;
33
35
use Mageplaza \Productslider \Helper \Data ;
34
36
use Mageplaza \Productslider \Model \Config \Source \Additional ;
35
37
@@ -64,14 +66,21 @@ abstract class AbstractSlider extends AbstractProduct
64
66
*/
65
67
protected $ httpContext ;
66
68
69
+ /**
70
+ * @var EncoderInterface|null
71
+ */
72
+ protected $ urlEncoder ;
73
+
67
74
/**
68
75
* AbstractSlider constructor.
76
+ *
69
77
* @param Context $context
70
78
* @param CollectionFactory $productCollectionFactory
71
79
* @param Visibility $catalogProductVisibility
72
80
* @param DateTime $dateTime
73
81
* @param Data $helperData
74
82
* @param HttpContext $httpContext
83
+ * @param EncoderInterface $urlEncoder
75
84
* @param array $data
76
85
*/
77
86
public function __construct (
@@ -81,13 +90,15 @@ public function __construct(
81
90
DateTime $ dateTime ,
82
91
Data $ helperData ,
83
92
HttpContext $ httpContext ,
93
+ EncoderInterface $ urlEncoder ,
84
94
array $ data = []
85
95
) {
86
96
$ this ->_productCollectionFactory = $ productCollectionFactory ;
87
97
$ this ->_catalogProductVisibility = $ catalogProductVisibility ;
88
- $ this ->_date = $ dateTime ;
89
- $ this ->_helperData = $ helperData ;
90
- $ this ->httpContext = $ httpContext ;
98
+ $ this ->_date = $ dateTime ;
99
+ $ this ->_helperData = $ helperData ;
100
+ $ this ->httpContext = $ httpContext ;
101
+ $ this ->urlEncoder = $ urlEncoder ;
91
102
92
103
parent ::__construct ($ context , $ data );
93
104
}
@@ -146,6 +157,26 @@ public function getDisplayAdditional()
146
157
return $ display ;
147
158
}
148
159
160
+ /**
161
+ * Get post parameters.
162
+ *
163
+ * @param Product $product
164
+ *
165
+ * @return array
166
+ */
167
+ public function getAddToCartPostParams (Product $ product )
168
+ {
169
+ $ url = $ this ->getAddToCartUrl ($ product );
170
+
171
+ return [
172
+ 'action ' => $ url ,
173
+ 'data ' => [
174
+ 'product ' => $ product ->getEntityId (),
175
+ ActionInterface::PARAM_NAME_URL_ENCODED => $ this ->urlEncoder ->encode ($ url ),
176
+ ]
177
+ ];
178
+ }
179
+
149
180
/**
150
181
* @return bool
151
182
*/
@@ -180,7 +211,7 @@ public function getSliderId()
180
211
return $ this ->getSlider ()->getSliderId ();
181
212
}
182
213
183
- return time ( );
214
+ return uniqid ( ' - ' , false );
184
215
}
185
216
186
217
/**
@@ -225,7 +256,7 @@ public function getDescription()
225
256
public function getAllOptions ()
226
257
{
227
258
$ sliderOptions = '' ;
228
- $ allConfig = $ this ->_helperData ->getModuleConfig ('slider_design ' );
259
+ $ allConfig = $ this ->_helperData ->getModuleConfig ('slider_design ' );
229
260
230
261
foreach ($ allConfig as $ key => $ value ) {
231
262
if ($ key === 'item_slider ' ) {
@@ -238,7 +269,7 @@ public function getAllOptions()
238
269
if (in_array ($ key , ['loop ' , 'nav ' , 'dots ' , 'lazyLoad ' , 'autoplay ' , 'autoplayHoverPause ' ])) {
239
270
$ value = $ value ? 'true ' : 'false ' ;
240
271
}
241
- $ sliderOptions = $ sliderOptions . $ key . ': ' . $ value . ', ' ;
272
+ $ sliderOptions .= $ key . ': ' . $ value . ', ' ;
242
273
}
243
274
}
244
275
@@ -255,17 +286,19 @@ public function getResponsiveConfig()
255
286
try {
256
287
if ($ slider ->getIsResponsive () === '2 ' ) {
257
288
return $ this ->_helperData ->getResponseValue ();
258
- } else {
259
- $ responsiveConfig = $ slider ->getResponsiveItems () ? $ this ->_helperData ->unserialize ($ slider ->getResponsiveItems ()) : [];
260
289
}
290
+
291
+ $ responsiveConfig = $ slider ->getResponsiveItems ()
292
+ ? $ this ->_helperData ->unserialize ($ slider ->getResponsiveItems ())
293
+ : [];
261
294
} catch (Exception $ e ) {
262
295
$ responsiveConfig = [];
263
296
}
264
297
265
298
$ responsiveOptions = '' ;
266
299
foreach ($ responsiveConfig as $ config ) {
267
300
if ($ config ['size ' ] && $ config ['items ' ]) {
268
- $ responsiveOptions = $ responsiveOptions . $ config ['size ' ] . ':{items: ' . $ config ['items ' ] . '}, ' ;
301
+ $ responsiveOptions .= $ config ['size ' ] . ':{items: ' . $ config ['items ' ] . '}, ' ;
269
302
}
270
303
}
271
304
$ responsiveOptions = rtrim ($ responsiveOptions , ', ' );
0 commit comments