1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DigitalOrigin\Pmt\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 DigitalOrigin\Pmt\Helper\ExtraConfig; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Simulator |
14
|
|
|
* @package DigitalOrigin\Pmt\Block\Product |
15
|
|
|
*/ |
16
|
|
|
class Simulator extends Template |
17
|
|
|
{ |
18
|
|
|
const PROMOTIONS_CATEGORY = 'paylater-promotion-product'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
protected $enabled; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $publicKey; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $productSimulator; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $promotionProductExtra; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Product |
42
|
|
|
*/ |
43
|
|
|
protected $product; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var float |
47
|
|
|
*/ |
48
|
|
|
protected $minAmount; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $minInstallments; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $priceSelector; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected $quantitySelector; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var String |
67
|
|
|
*/ |
68
|
|
|
protected $positionSelector; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Registry |
72
|
|
|
*/ |
73
|
|
|
protected $registry; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var Config |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
protected $extraConfig; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var String |
82
|
|
|
*/ |
83
|
|
|
protected $simulatorType; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Simulator constructor. |
87
|
|
|
* |
88
|
|
|
* @param Context $context |
89
|
|
|
* @param Registry $registry |
90
|
|
|
* @param ExtraConfig $extraConfig |
91
|
|
|
* @param array $data |
92
|
|
|
*/ |
93
|
|
|
public function __construct( |
94
|
|
|
Context $context, |
95
|
|
|
Registry $registry, |
96
|
|
|
ExtraConfig $extraConfig, |
97
|
|
|
array $data = [] |
98
|
|
|
) { |
99
|
|
|
parent::__construct($context, $data); |
100
|
|
|
$this->registry = $registry; |
101
|
|
|
/** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */ |
102
|
|
|
$scopeConfig = $this->_scopeConfig; |
103
|
|
|
$config = $scopeConfig->getValue('payment/paylater'); |
104
|
|
|
|
105
|
|
|
$this->enabled = $config['active']; |
106
|
|
|
$this->publicKey = isset($config['pmt_public_key']) ? $config['pmt_public_key'] : ''; |
107
|
|
|
$this->productSimulator = $config['product_simulator']; |
108
|
|
|
$this->extraConfig = $extraConfig->getExtraConfig(); |
|
|
|
|
109
|
|
|
$this->minAmount = $this->extraConfig['PMT_DISPLAY_MIN_AMOUNT']; |
110
|
|
|
$this->minInstallments = $this->extraConfig['PMT_SIMULATOR_START_INSTALLMENTS']; |
111
|
|
|
$this->priceSelector = $this->extraConfig['PMT_SIMULATOR_CSS_PRICE_SELECTOR']; |
112
|
|
|
$this->quantitySelector = $this->extraConfig['PMT_SIMULATOR_CSS_QUANTITY_SELECTOR']; |
113
|
|
|
$this->positionSelector = $this->extraConfig['PMT_SIMULATOR_CSS_POSITION_SELECTOR']; |
114
|
|
|
$this->simulatorType = $this->extraConfig['PMT_SIMULATOR_DISPLAY_TYPE']; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return Product |
119
|
|
|
*/ |
120
|
|
|
protected function getProduct() |
121
|
|
|
{ |
122
|
|
|
if (is_null($this->product)) { |
123
|
|
|
$this->product = $this->registry->registry('product'); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this->product; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
public function isEnabled() |
133
|
|
|
{ |
134
|
|
|
return $this->enabled; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getPublicKey() |
141
|
|
|
{ |
142
|
|
|
return $this->publicKey; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getPromotionProductExtra() |
149
|
|
|
{ |
150
|
|
|
return $this->promotionProductExtra; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return bool |
155
|
|
|
*/ |
156
|
|
|
public function isProductInPromotion() |
157
|
|
|
{ |
158
|
|
|
try { |
159
|
|
|
/** @var Category $category */ |
160
|
|
|
$category = $this->getProduct()->getCategoryCollection()->addFieldToFilter( |
161
|
|
|
'name', |
162
|
|
|
array('eq' => self::PROMOTIONS_CATEGORY) |
163
|
|
|
)->getFirstItem(); |
164
|
|
|
} catch (\Exception $exception) { |
165
|
|
|
return false; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $category->getName() === self::PROMOTIONS_CATEGORY ? 1 : 0; |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return float |
173
|
|
|
*/ |
174
|
|
|
public function getFinalPrice() |
175
|
|
|
{ |
176
|
|
|
return $this->getProduct()->getFinalPrice(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return array|false|string |
181
|
|
|
*/ |
182
|
|
|
public function getProductSimulator() |
183
|
|
|
{ |
184
|
|
|
return $this->productSimulator; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param int $productSimulator |
189
|
|
|
*/ |
190
|
|
|
public function setProductSimulator($productSimulator) |
191
|
|
|
{ |
192
|
|
|
$this->productSimulator = $productSimulator; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @return float |
197
|
|
|
*/ |
198
|
|
|
public function getMinAmount() |
199
|
|
|
{ |
200
|
|
|
return $this->minAmount; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param float $minAmount |
205
|
|
|
*/ |
206
|
|
|
public function setMinAmount($minAmount) |
207
|
|
|
{ |
208
|
|
|
$this->minAmount = $minAmount; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return int |
213
|
|
|
*/ |
214
|
|
|
public function getMinInstallments() |
215
|
|
|
{ |
216
|
|
|
return $this->minInstallments; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param int $minInstallments |
221
|
|
|
*/ |
222
|
|
|
public function setMinInstallments($minInstallments) |
223
|
|
|
{ |
224
|
|
|
$this->minInstallments = $minInstallments; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return string |
229
|
|
|
*/ |
230
|
|
|
public function getPriceSelector() |
231
|
|
|
{ |
232
|
|
|
return $this->priceSelector; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param string $priceSelector |
237
|
|
|
*/ |
238
|
|
|
public function setPriceSelector($priceSelector) |
239
|
|
|
{ |
240
|
|
|
$this->priceSelector = $priceSelector; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return string |
245
|
|
|
*/ |
246
|
|
|
public function getQuantitySelector() |
247
|
|
|
{ |
248
|
|
|
return $this->quantitySelector; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param string $quantitySelector |
253
|
|
|
*/ |
254
|
|
|
public function setQuantitySelector($quantitySelector) |
255
|
|
|
{ |
256
|
|
|
$this->quantitySelector = $quantitySelector; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @return String |
261
|
|
|
*/ |
262
|
|
|
public function getPositionSelector() |
263
|
|
|
{ |
264
|
|
|
return $this->positionSelector; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param String $positionSelector |
269
|
|
|
*/ |
270
|
|
|
public function setPositionSelector($positionSelector) |
271
|
|
|
{ |
272
|
|
|
$this->positionSelector = $positionSelector; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return String |
278
|
|
|
*/ |
279
|
|
|
public function getSimulatorType() |
280
|
|
|
{ |
281
|
|
|
return $this->simulatorType; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param String $simulatorType |
286
|
|
|
*/ |
287
|
|
|
public function setSimulatorType($simulatorType) |
288
|
|
|
{ |
289
|
|
|
$this->simulatorType = $simulatorType; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
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