Completed
Push — master ( e05b34...9fcd87 )
by
unknown
16s queued 11s
created

Simulator::getPromotedMessage()   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 0
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
     * Simulator constructor.
114
     *
115
     * @param Context        $context
116
     * @param Registry       $registry
117
     * @param ExtraConfig    $extraConfig
118
     * @param Resolver $store
119
     * @param array          $data
120
     */
121
    public function __construct(
122
        Context $context,
123
        Registry $registry,
124
        ExtraConfig $extraConfig,
125
        Resolver $store,
126
        array $data = []
127
    ) {
128
        parent::__construct($context, $data);
129
        $this->registry = $registry;
130
        $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...
131
        /** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
132
        $scopeConfig = $this->_scopeConfig;
133
        $config = $scopeConfig->getValue('payment/pagantis');
134
135
        $this->enabled = $config['active'];
136
        $this->publicKey = isset($config['pagantis_public_key']) ? $config['pagantis_public_key'] : '';
137
        $this->productSimulator = $config['product_simulator'];
138
        $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...
139
140
        $this->minAmount = $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'];
141
        $this->minInstallments = $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'];
142
        $this->priceSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'];
143
        $this->quantitySelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'];
144
        $this->positionSelector = $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'];
145
        $this->simulatorType = $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'];
146
        $this->promotedMessage = $this->extraConfig['PAGANTIS_PROMOTION_EXTRA'];
147
        $this->thousandSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'];
148
        $this->decimalSeparator = $this->extraConfig['PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'];
149
150
        $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...
151
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getLocale()
157
    {
158
        return strstr($this->store->getLocale(), '_', true);
159
    }
160
161
    /**
162
     * @param $locale
163
     *
164
     * @return bool
165
     */
166
    public function getAllowedCountry($locale)
167
    {
168
        $locale = strtolower($locale);
169
        $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
170
        return (in_array(strtolower($locale), $allowedCountries));
171
    }
172
173
    /**
174
     * @return Product
175
     */
176
    protected function getProduct()
177
    {
178
        if (is_null($this->product)) {
179
            $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

179
            $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...
180
        }
181
182
        return $this->product;
183
    }
184
185
    /**
186
     * @return bool
187
     */
188
    public function isEnabled()
189
    {
190
        return $this->enabled;
191
    }
192
193
    /**
194
     * @return string
195
     */
196
    public function getPublicKey()
197
    {
198
        return $this->publicKey;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    public function getPromotionProductExtra()
205
    {
206
        return $this->promotionProductExtra;
207
    }
208
209
    /**
210
     * @return bool
211
     */
212
    public function isProductInPromotion()
213
    {
214
        try {
215
            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...
216
        } catch (\Exception $exception) {
217
            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...
218
        }
219
    }
220
221
    /**
222
     * @return float
223
     */
224
    public function getFinalPrice()
225
    {
226
        return $this->getProduct()->getFinalPrice();
227
    }
228
229
    /**
230
     * @return array|false|string
231
     */
232
    public function getProductSimulator()
233
    {
234
        return $this->productSimulator;
235
    }
236
237
    /**
238
     * @param int $productSimulator
239
     */
240
    public function setProductSimulator($productSimulator)
241
    {
242
        $this->productSimulator = $productSimulator;
243
    }
244
245
    /**
246
     * @return float
247
     */
248
    public function getMinAmount()
249
    {
250
        return $this->minAmount;
251
    }
252
253
    /**
254
     * @param float $minAmount
255
     */
256
    public function setMinAmount($minAmount)
257
    {
258
        $this->minAmount = $minAmount;
259
    }
260
261
    /**
262
     * @return int
263
     */
264
    public function getMinInstallments()
265
    {
266
        return $this->minInstallments;
267
    }
268
269
    /**
270
     * @param int $minInstallments
271
     */
272
    public function setMinInstallments($minInstallments)
273
    {
274
        $this->minInstallments = $minInstallments;
275
    }
276
277
    /**
278
     * @return string
279
     */
280
    public function getPriceSelector()
281
    {
282
        return $this->priceSelector;
283
    }
284
285
    /**
286
     * @param string $priceSelector
287
     */
288
    public function setPriceSelector($priceSelector)
289
    {
290
        $this->priceSelector = $priceSelector;
291
    }
292
293
    /**
294
     * @return string
295
     */
296
    public function getQuantitySelector()
297
    {
298
        return $this->quantitySelector;
299
    }
300
301
    /**
302
     * @param string $quantitySelector
303
     */
304
    public function setQuantitySelector($quantitySelector)
305
    {
306
        $this->quantitySelector = $quantitySelector;
307
    }
308
309
    /**
310
     * @return String
311
     */
312
    public function getPositionSelector()
313
    {
314
        return $this->positionSelector;
315
    }
316
317
    /**
318
     * @param String $positionSelector
319
     */
320
    public function setPositionSelector($positionSelector)
321
    {
322
        $this->positionSelector = $positionSelector;
323
    }
324
325
326
    /**
327
     * @return String
328
     */
329
    public function getSimulatorType()
330
    {
331
        return $this->simulatorType;
332
    }
333
334
    /**
335
     * @param String $simulatorType
336
     */
337
    public function setSimulatorType($simulatorType)
338
    {
339
        $this->simulatorType = $simulatorType;
340
    }
341
342
    /**
343
     * @return Boolean
344
     */
345
    public function getPromoted()
346
    {
347
        return $this->promoted;
348
    }
349
350
    /**
351
     * @param Boolean $promoted
352
     */
353
    public function setPromoted($promoted)
354
    {
355
        $this->promoted = $promoted;
356
    }
357
358
    /**
359
     * @return String
360
     */
361
    public function getPromotedMessage()
362
    {
363
        return $this->promotedMessage;
364
    }
365
366
    /**
367
     * @param String $promotedMessage
368
     */
369
    public function setPromotedMessage($promotedMessage)
370
    {
371
        $this->promotedMessage = $promotedMessage;
372
    }
373
374
    /**
375
     * @return String
376
     */
377
    public function getThousandSeparator()
378
    {
379
        return $this->thousandSeparator;
380
    }
381
382
    /**
383
     * @param String $thousandSeparator
384
     */
385
    public function setThousandSeparator($thousandSeparator)
386
    {
387
        $this->thousandSeparator = $thousandSeparator;
388
    }
389
390
    /**
391
     * @return String
392
     */
393
    public function getDecimalSeparator()
394
    {
395
        return $this->decimalSeparator;
396
    }
397
398
    /**
399
     * @param String $decimalSeparator
400
     */
401
    public function setDecimalSeparator($decimalSeparator)
402
    {
403
        $this->decimalSeparator = $decimalSeparator;
404
    }
405
}
406