|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pagantis\Pagantis\Block\Product; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Backend\Block\Template\Context; |
|
6
|
|
|
use Magento\Catalog\Model\Category; |
|
7
|
|
|
use Magento\Catalog\Model\Product; |
|
8
|
|
|
use Magento\Framework\Registry; |
|
9
|
|
|
use Magento\Framework\View\Element\Template; |
|
10
|
|
|
use Pagantis\Pagantis\Helper\ExtraConfig; |
|
11
|
|
|
use Magento\Framework\Locale\Resolver; |
|
12
|
|
|
use Zend\Db\Sql\Ddl\Column\Boolean; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Simulator |
|
16
|
|
|
* @package Pagantis\Pagantis\Block\Product |
|
17
|
|
|
*/ |
|
18
|
|
|
class Simulator extends Template |
|
19
|
|
|
{ |
|
20
|
|
|
const PROMOTIONS_CATEGORY = 'pagantis-promotion-product'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $enabled; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $publicKey; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $productSimulator; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $promotionProductExtra; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var Product |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $product; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var float |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $minAmount; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var int |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $minInstallments; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $priceSelector; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $quantitySelector; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var String |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $positionSelector; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var Registry |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $registry; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @var Config |
|
|
|
|
|
|
79
|
|
|
*/ |
|
80
|
|
|
protected $extraConfig; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @var String |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $simulatorType; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @var String |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $store; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var Boolean |
|
94
|
|
|
*/ |
|
95
|
|
|
protected $promoted; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Simulator constructor. |
|
99
|
|
|
* |
|
100
|
|
|
* @param Context $context |
|
101
|
|
|
* @param Registry $registry |
|
102
|
|
|
* @param ExtraConfig $extraConfig |
|
103
|
|
|
* @param Resolver $store |
|
104
|
|
|
* @param array $data |
|
105
|
|
|
*/ |
|
106
|
|
|
public function __construct( |
|
107
|
|
|
Context $context, |
|
108
|
|
|
Registry $registry, |
|
109
|
|
|
ExtraConfig $extraConfig, |
|
110
|
|
|
Resolver $store, |
|
111
|
|
|
array $data = [] |
|
112
|
|
|
) { |
|
113
|
|
|
parent::__construct($context, $data); |
|
114
|
|
|
$this->registry = $registry; |
|
115
|
|
|
$this->store = $store; |
|
|
|
|
|
|
116
|
|
|
/** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */ |
|
117
|
|
|
$scopeConfig = $this->_scopeConfig; |
|
118
|
|
|
$config = $scopeConfig->getValue('payment/pagantis'); |
|
119
|
|
|
|
|
120
|
|
|
$this->enabled = $config['active']; |
|
121
|
|
|
$this->publicKey = isset($config['pagantis_public_key']) ? $config['pagantis_public_key'] : ''; |
|
122
|
|
|
$this->productSimulator = $config['product_simulator']; |
|
123
|
|
|
$this->extraConfig = $extraConfig->getExtraConfig(); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
$this->minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']; |
|
126
|
|
|
$this->minInstallments = $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']; |
|
127
|
|
|
$this->priceSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']; |
|
128
|
|
|
$this->quantitySelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']; |
|
129
|
|
|
$this->positionSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']; |
|
130
|
|
|
$this->simulatorType = $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE']; |
|
131
|
|
|
$this->promotedMessage = $this->extraConfig['PAGANTIS_PROMOTION_EXTRA']; |
|
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
$this->promoted = $this->isProductInPromotion(); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getLocale() |
|
140
|
|
|
{ |
|
141
|
|
|
return strstr($this->store->getLocale(), '_', true); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param $locale |
|
146
|
|
|
* |
|
147
|
|
|
* @return bool |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getAllowedCountry($locale) |
|
150
|
|
|
{ |
|
151
|
|
|
$locale = strtolower($locale); |
|
152
|
|
|
$allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
|
153
|
|
|
return (in_array(strtolower($locale), $allowedCountries)); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return Product |
|
158
|
|
|
*/ |
|
159
|
|
|
protected function getProduct() |
|
160
|
|
|
{ |
|
161
|
|
|
if (is_null($this->product)) { |
|
162
|
|
|
$this->product = $this->registry->registry('product'); |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return $this->product; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return bool |
|
170
|
|
|
*/ |
|
171
|
|
|
public function isEnabled() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->enabled; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return string |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getPublicKey() |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->publicKey; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return string |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getPromotionProductExtra() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->promotionProductExtra; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @return bool |
|
194
|
|
|
*/ |
|
195
|
|
|
public function isProductInPromotion() |
|
196
|
|
|
{ |
|
197
|
|
|
try { |
|
198
|
|
|
return ($this->getProduct()->getData('pagantis_promoted') === '1') ? 'true' : 'false'; |
|
|
|
|
|
|
199
|
|
|
} catch (\Exception $exception) { |
|
200
|
|
|
return 'false'; |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return float |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getFinalPrice() |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->getProduct()->getFinalPrice(); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @return array|false|string |
|
214
|
|
|
*/ |
|
215
|
|
|
public function getProductSimulator() |
|
216
|
|
|
{ |
|
217
|
|
|
return $this->productSimulator; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @param int $productSimulator |
|
222
|
|
|
*/ |
|
223
|
|
|
public function setProductSimulator($productSimulator) |
|
224
|
|
|
{ |
|
225
|
|
|
$this->productSimulator = $productSimulator; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @return float |
|
230
|
|
|
*/ |
|
231
|
|
|
public function getMinAmount() |
|
232
|
|
|
{ |
|
233
|
|
|
return $this->minAmount; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param float $minAmount |
|
238
|
|
|
*/ |
|
239
|
|
|
public function setMinAmount($minAmount) |
|
240
|
|
|
{ |
|
241
|
|
|
$this->minAmount = $minAmount; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @return int |
|
246
|
|
|
*/ |
|
247
|
|
|
public function getMinInstallments() |
|
248
|
|
|
{ |
|
249
|
|
|
return $this->minInstallments; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @param int $minInstallments |
|
254
|
|
|
*/ |
|
255
|
|
|
public function setMinInstallments($minInstallments) |
|
256
|
|
|
{ |
|
257
|
|
|
$this->minInstallments = $minInstallments; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @return string |
|
262
|
|
|
*/ |
|
263
|
|
|
public function getPriceSelector() |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->priceSelector; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @param string $priceSelector |
|
270
|
|
|
*/ |
|
271
|
|
|
public function setPriceSelector($priceSelector) |
|
272
|
|
|
{ |
|
273
|
|
|
$this->priceSelector = $priceSelector; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @return string |
|
278
|
|
|
*/ |
|
279
|
|
|
public function getQuantitySelector() |
|
280
|
|
|
{ |
|
281
|
|
|
return $this->quantitySelector; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @param string $quantitySelector |
|
286
|
|
|
*/ |
|
287
|
|
|
public function setQuantitySelector($quantitySelector) |
|
288
|
|
|
{ |
|
289
|
|
|
$this->quantitySelector = $quantitySelector; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @return String |
|
294
|
|
|
*/ |
|
295
|
|
|
public function getPositionSelector() |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->positionSelector; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @param String $positionSelector |
|
302
|
|
|
*/ |
|
303
|
|
|
public function setPositionSelector($positionSelector) |
|
304
|
|
|
{ |
|
305
|
|
|
$this->positionSelector = $positionSelector; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* @return String |
|
311
|
|
|
*/ |
|
312
|
|
|
public function getSimulatorType() |
|
313
|
|
|
{ |
|
314
|
|
|
return $this->simulatorType; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param String $simulatorType |
|
319
|
|
|
*/ |
|
320
|
|
|
public function setSimulatorType($simulatorType) |
|
321
|
|
|
{ |
|
322
|
|
|
$this->simulatorType = $simulatorType; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* @return Boolean |
|
327
|
|
|
*/ |
|
328
|
|
|
public function getPromoted() |
|
329
|
|
|
{ |
|
330
|
|
|
return $this->promoted; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* @param Boolean $promoted |
|
335
|
|
|
*/ |
|
336
|
|
|
public function setPromoted($promoted) |
|
337
|
|
|
{ |
|
338
|
|
|
$this->promoted = $promoted; |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths