Completed
Push — master ( 2b2ac1...08c5b9 )
by pablo
12s queued 11s
created

Simulator::setQuantitySelector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Bug introduced by
The type Pagantis\Pagantis\Block\Product\Config was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
     * @var String
99
     */
100
    protected $promotedMessage;
101
102
    /**
103
     * @var String
104
     */
105
    protected $thousandSeparator;
106
107
    /**
108
     * @var String
109
     */
110
    protected $decimalSeparator;
111
112
    /**
113
     * @var String
114
     */
115
    protected $separator;
116
117
    /**
118
     * Simulator constructor.
119
     *
120
     * @param Context        $context
121
     * @param Registry       $registry
122
     * @param ExtraConfig    $extraConfig
123
     * @param Resolver $store
124
     * @param array          $data
125
     */
126
    public function __construct(
127
        Context $context,
128
        Registry $registry,
129
        ExtraConfig $extraConfig,
130
        Resolver $store,
131
        array $data = []
132
    ) {
133
        parent::__construct($context, $data);
134
        $this->registry = $registry;
135
        $this->store = $store;
0 ignored issues
show
Documentation Bug introduced by
It seems like $store of type Magento\Framework\Locale\Resolver is incompatible with the declared type string of property $store.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
136
        /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
137
        $scopeConfig = $this->_scopeConfig;
138
        $config = $scopeConfig->getValue('payment/pagantis');
139
140
        $this->enabled = $config['active'];
141
        $this->publicKey = isset($config['pagantis_public_key']) ? $config['pagantis_public_key'] : '';
142
        $this->productSimulator = $config['product_simulator'];
143
        $this->extraConfig = $extraConfig->getExtraConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extraConfig->getExtraConfig() of type array or array is incompatible with the declared type Pagantis\Pagantis\Block\Product\Config of property $extraConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
144
145
        $this->minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'];
146
        $this->minInstallments = $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'];
147
        $this->priceSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'];
148
        $this->quantitySelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'];
149
        $this->positionSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'];
150
        $this->simulatorType = $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'];
151
        $this->promotedMessage = $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'];
152
        $this->thousandSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'];
153
        $this->decimalSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'];
154
        $this->separator = __('ó');
155
156
        $this->promoted = $this->isProductInPromotion();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->isProductInPromotion() of type boolean is incompatible with the declared type Zend\Db\Sql\Ddl\Column\Boolean of property $promoted.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
157
    }
158
159
    /**
160
     * @return string
161
     */
162
    public function getLocale()
163
    {
164
        return strstr($this->store->getLocale(), '_', true);
165
    }
166
167
    /**
168
     * @return string
169
     */
170
    public function getCountry()
171
    {
172
        return strstr($this->store->getLocale(), '_', true);
173
    }
174
175
    /**
176
     * @param $locale
177
     *
178
     * @return bool
179
     */
180
    public function getAllowedCountry($locale)
181
    {
182
        $locale = strtolower($locale);
183
        $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
184
        return (in_array(strtolower($locale), $allowedCountries));
185
    }
186
187
    /**
188
     * @return Product
189
     */
190
    protected function getProduct()
191
    {
192
        if (is_null($this->product)) {
193
            $this->product = $this->registry->registry('product');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Registry::registry() has been deprecated: 102.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

193
            $this->product = /** @scrutinizer ignore-deprecated */ $this->registry->registry('product');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
194
        }
195
196
        return $this->product;
197
    }
198
199
    /**
200
     * @return bool
201
     */
202
    public function isEnabled()
203
    {
204
        return $this->enabled;
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    public function getPublicKey()
211
    {
212
        return $this->publicKey;
213
    }
214
215
    /**
216
     * @return string
217
     */
218
    public function getPromotionProductExtra()
219
    {
220
        return $this->promotionProductExtra;
221
    }
222
223
    /**
224
     * @return bool
225
     */
226
    public function isProductInPromotion()
227
    {
228
        try {
229
            return ($this->getProduct()->getData('pagantis_promoted') === '1') ? 'true' : 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getProduct... '1' ? 'true' : 'false' returns the type string which is incompatible with the documented return type boolean.
Loading history...
230
        } catch (\Exception $exception) {
231
            return 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'false' returns the type string which is incompatible with the documented return type boolean.
Loading history...
232
        }
233
    }
234
235
    /**
236
     * @return float
237
     */
238
    public function getFinalPrice()
239
    {
240
        return $this->getProduct()->getFinalPrice();
241
    }
242
243
    /**
244
     * @return array|false|string
245
     */
246
    public function getProductSimulator()
247
    {
248
        return $this->productSimulator;
249
    }
250
251
    /**
252
     * @param int $productSimulator
253
     */
254
    public function setProductSimulator($productSimulator)
255
    {
256
        $this->productSimulator = $productSimulator;
257
    }
258
259
    /**
260
     * @return float
261
     */
262
    public function getMinAmount()
263
    {
264
        return $this->minAmount;
265
    }
266
267
    /**
268
     * @param float $minAmount
269
     */
270
    public function setMinAmount($minAmount)
271
    {
272
        $this->minAmount = $minAmount;
273
    }
274
275
    /**
276
     * @return int
277
     */
278
    public function getMinInstallments()
279
    {
280
        return $this->minInstallments;
281
    }
282
283
    /**
284
     * @param int $minInstallments
285
     */
286
    public function setMinInstallments($minInstallments)
287
    {
288
        $this->minInstallments = $minInstallments;
289
    }
290
291
    /**
292
     * @return string
293
     */
294
    public function getPriceSelector()
295
    {
296
        return $this->priceSelector;
297
    }
298
299
    /**
300
     * @param string $priceSelector
301
     */
302
    public function setPriceSelector($priceSelector)
303
    {
304
        $this->priceSelector = $priceSelector;
305
    }
306
307
    /**
308
     * @return string
309
     */
310
    public function getQuantitySelector()
311
    {
312
        return $this->quantitySelector;
313
    }
314
315
    /**
316
     * @param string $quantitySelector
317
     */
318
    public function setQuantitySelector($quantitySelector)
319
    {
320
        $this->quantitySelector = $quantitySelector;
321
    }
322
323
    /**
324
     * @return String
325
     */
326
    public function getPositionSelector()
327
    {
328
        return $this->positionSelector;
329
    }
330
331
    /**
332
     * @param String $positionSelector
333
     */
334
    public function setPositionSelector($positionSelector)
335
    {
336
        $this->positionSelector = $positionSelector;
337
    }
338
339
340
    /**
341
     * @return String
342
     */
343
    public function getSimulatorType()
344
    {
345
        return $this->simulatorType;
346
    }
347
348
    /**
349
     * @param String $simulatorType
350
     */
351
    public function setSimulatorType($simulatorType)
352
    {
353
        $this->simulatorType = $simulatorType;
354
    }
355
356
    /**
357
     * @return Boolean
358
     */
359
    public function getPromoted()
360
    {
361
        return $this->promoted;
362
    }
363
364
    /**
365
     * @param Boolean $promoted
366
     */
367
    public function setPromoted($promoted)
368
    {
369
        $this->promoted = $promoted;
370
    }
371
372
    /**
373
     * @return String
374
     */
375
    public function getPromotedMessage()
376
    {
377
        return $this->promotedMessage;
378
    }
379
380
    /**
381
     * @param String $promotedMessage
382
     */
383
    public function setPromotedMessage($promotedMessage)
384
    {
385
        $this->promotedMessage = $promotedMessage;
386
    }
387
388
    /**
389
     * @return String
390
     */
391
    public function getThousandSeparator()
392
    {
393
        return $this->thousandSeparator;
394
    }
395
396
    /**
397
     * @param String $thousandSeparator
398
     */
399
    public function setThousandSeparator($thousandSeparator)
400
    {
401
        $this->thousandSeparator = $thousandSeparator;
402
    }
403
404
    /**
405
     * @return String
406
     */
407
    public function getDecimalSeparator()
408
    {
409
        return $this->decimalSeparator;
410
    }
411
412
    /**
413
     * @param String $decimalSeparator
414
     */
415
    public function setDecimalSeparator($decimalSeparator)
416
    {
417
        $this->decimalSeparator = $decimalSeparator;
418
    }
419
420
    /**
421
     * @return String
422
     */
423
    public function getSeparator()
424
    {
425
        return $this->separator;
426
    }
427
428
    /**
429
     * @param String $separator
430
     */
431
    public function setSeparator($separator)
432
    {
433
        $this->separator = $separator;
434
    }
435
}
436