Passed
Pull Request — master (#45)
by Raúl
02:36
created

Pagantis::getExtraConfig()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 7
nc 4
nop 2
dl 0
loc 14
rs 9.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the official Pagantis module for PrestaShop.
4
 *
5
 * @author    Pagantis <[email protected]>
6
 * @copyright 2015-2016 Pagantis
7
 * @license   proprietary
8
 */
9
10
if (!defined('_PS_VERSION_')) {
11
    exit;
12
}
13
14
define('_PS_PAGANTIS_DIR', _PS_MODULE_DIR_. '/pagantis');
0 ignored issues
show
Bug introduced by
The constant _PS_MODULE_DIR_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
15
define('PROMOTIONS_CATEGORY', 'pagantis-promotion-product');
16
define('PROMOTIONS_CATEGORY_NAME', 'Pagantis Promoted Product');
17
18
require _PS_PAGANTIS_DIR.'/vendor/autoload.php';
19
20
/**
21
 * Class Pagantis
22
 */
23
class Pagantis extends PaymentModule
0 ignored issues
show
Bug introduced by
The type PaymentModule 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...
24
{
25
    /**
26
     * @var string
27
     */
28
    public $url = 'https://pagantis.com';
29
30
    /**
31
     * @var bool
32
     */
33
    public $bootstrap = true;
34
35
    /**
36
     * Default module advanced configuration values
37
     *
38
     * @var array
39
     */
40
    public $defaultConfigs = array(
41
        'PAGANTIS_TITLE' => 'Instant Financing',
42
        'PAGANTIS_SIMULATOR_DISPLAY_TYPE' => 'sdk.simulator.types.SIMPLE',
43
        'PAGANTIS_SIMULATOR_DISPLAY_SKIN' => 'sdk.simulator.skins.BLUE',
44
        'PAGANTIS_SIMULATOR_DISPLAY_POSITION' => 'hookDisplayProductButtons',
45
        'PAGANTIS_SIMULATOR_START_INSTALLMENTS' => '3',
46
        'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR' => 'default',
47
        'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION' => 'sdk.simulator.positions.INNER',
48
        'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR' => 'default',
49
        'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR' => 'default',
50
        'PAGANTIS_FORM_DISPLAY_TYPE' => '0',
51
        'PAGANTIS_DISPLAY_MIN_AMOUNT' => '1',
52
        'PAGANTIS_URL_OK' => '',
53
        'PAGANTIS_URL_KO' => '',
54
        'PAGANTIS_ALLOWED_COUNTRIES' => 'a:2:{i:0;s:2:"es";i:1;s:2:"it";}',
55
        'PAGANTIS_PROMOTION_EXTRA' => 'Finance this product without interest! - 0% TAE',
56
        'PAGANTIS_SIMULATOR_THOUSAND_SEPARATOR' => '.',
57
        'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR' => ',',
58
    );
59
60
    /**
61
     * Pagantis constructor.
62
     *
63
     * Define the module main properties so that prestashop understands what are the module requirements
64
     * and how to manage the module.
65
     *
66
     */
67
    public function __construct()
68
    {
69
        $this->name = 'pagantis';
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
70
        $this->tab = 'payments_gateways';
0 ignored issues
show
Bug Best Practice introduced by
The property tab does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
71
        $this->version = '8.2.0';
0 ignored issues
show
Bug Best Practice introduced by
The property version does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72
        $this->author = 'Pagantis';
0 ignored issues
show
Bug Best Practice introduced by
The property author does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
73
        $this->currencies = true;
0 ignored issues
show
Bug Best Practice introduced by
The property currencies does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
74
        $this->currencies_mode = 'checkbox';
0 ignored issues
show
Bug Best Practice introduced by
The property currencies_mode does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
75
        $this->module_key = '2b9bc901b4d834bb7069e7ea6510438f';
0 ignored issues
show
Bug Best Practice introduced by
The property module_key does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
76
        $this->ps_versions_compliancy = array('min' => '1.5', 'max' => _PS_VERSION_);
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug Best Practice introduced by
The property ps_versions_compliancy does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
        $this->displayName = $this->l('Pagantis');
0 ignored issues
show
Bug Best Practice introduced by
The property displayName does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
        $this->description = $this->l(
0 ignored issues
show
Bug Best Practice introduced by
The property description does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
79
            'Instant, easy and effective financial tool for your customers'
80
        );
81
82
        $sql_file = dirname(__FILE__).'/sql/install.sql';
83
        $this->loadSQLFile($sql_file);
84
85
        $this->checkEnvVariables();
86
87
        $this->migrate();
88
89
        $this->checkHooks();
90
91
        $this->checkPromotionCategory();
92
93
        parent::__construct();
94
95
        $lang = Language::getLanguage($this->context->language->id);
0 ignored issues
show
Bug introduced by
The type Language 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...
96
        $langArray = explode("-", $lang['language_code']);
97
        if (count($langArray) != 2 && isset($lang['locale'])) {
98
            $langArray = explode("-", $lang['locale']);
99
        }
100
        $this->language = Tools::strtoupper($langArray[count($langArray)-1]);
0 ignored issues
show
Bug Best Practice introduced by
The property language does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The type Tools 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...
101
102
        // Prevent null language detection
103
        $this->language = ($this->language) ? $this->language : 'ES';
104
    }
105
106
    /**
107
     * Configure the variables for Pagantis payment method.
108
     *
109
     * @return bool
110
     */
111
    public function install()
112
    {
113
        if (!extension_loaded('curl')) {
114
            $this->_errors[] =
0 ignored issues
show
Bug Best Practice introduced by
The property _errors does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
115
                $this->l('You have to enable the cURL extension on your server to install this module');
116
            return false;
117
        }
118
        if (!version_compare(phpversion(), '5.3.0', '>=')) {
119
            $this->_errors[] = $this->l('The PHP version bellow 5.3.0 is not supported');
120
            return false;
121
        }
122
123
        Configuration::updateValue('pagantis_is_enabled', 1);
0 ignored issues
show
Bug introduced by
The type Configuration 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...
124
        Configuration::updateValue('pagantis_simulator_is_enabled', 1);
125
        Configuration::updateValue('pagantis_public_key', '');
126
        Configuration::updateValue('pagantis_private_key', '');
127
128
        $return =  (parent::install()
129
            && $this->registerHook('displayShoppingCart')
130
            && $this->registerHook('paymentOptions')
131
            && $this->registerHook('displayRightColumn')
132
            && $this->registerHook('displayLeftColumn')
133
            && $this->registerHook('displayRightColumnProduct')
134
            && $this->registerHook('displayLeftColumnProduct')
135
            && $this->registerHook('displayProductButtons')
136
            && $this->registerHook('displayOrderConfirmation')
137
            && $this->registerHook('header')
138
        );
139
140
        if ($return && _PS_VERSION_ < "1.7") {
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
141
            $return = $this->registerHook('payment');
142
        }
143
144
        return $return;
145
    }
146
147
    /**
148
     * Remove the production private api key and remove the files
149
     *
150
     * @return bool
151
     */
152
    public function uninstall()
153
    {
154
        Configuration::deleteByName('pagantis_public_key');
155
        Configuration::deleteByName('pagantis_private_key');
156
157
        return parent::uninstall();
158
    }
159
160
    /**
161
     * Migrate the configs of older versions < 7x to new configurations
162
     */
163
    public function migrate()
164
    {
165
        if (Configuration::get('PAGANTIS_MIN_AMOUNT')) {
166
            Db::getInstance()->update(
0 ignored issues
show
Bug introduced by
The type Db 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...
167
                'pagantis_config',
168
                array('value' => Configuration::get('PAGANTIS_MIN_AMOUNT')),
169
                'config = \'PAGANTIS_DISPLAY_MIN_AMOUNT\''
170
            );
171
            Configuration::updateValue('PAGANTIS_MIN_AMOUNT', false);
172
            Configuration::updateValue('pagantis_is_enabled', 1);
173
            Configuration::updateValue('pagantis_simulator_is_enabled', 1);
174
175
            // migrating pk/tk from previous version
176
            if (Configuration::get('pagantis_public_key') === false
177
                && Configuration::get('PAGANTIS_PUBLIC_KEY_PROD')
178
            ) {
179
                Configuration::updateValue('pagantis_public_key', Configuration::get('PAGANTIS_PUBLIC_KEY_PROD'));
180
                Configuration::updateValue('PAGANTIS_PUBLIC_KEY_PROD', false);
181
            } elseif (Configuration::get('pagantis_public_key') === false
182
                && Configuration::get('PAGANTIS_PUBLIC_KEY_TEST')
183
            ) {
184
                Configuration::updateValue('pagantis_public_key', Configuration::get('PAGANTIS_PUBLIC_KEY_TEST'));
185
                Configuration::updateValue('PAGANTIS_PUBLIC_KEY_TEST', false);
186
            }
187
188
            if (Configuration::get('pagantis_private_key') === false
189
                && Configuration::get('PAGANTIS_PRIVATE_KEY_PROD')
190
            ) {
191
                Configuration::updateValue('pagantis_private_key', Configuration::get('PAGANTIS_PRIVATE_KEY_PROD'));
192
                Configuration::updateValue('PAGANTIS_PRIVATE_KEY_PROD', false);
193
            } elseif (Configuration::get('pagantis_private_key') === false
194
                && Configuration::get('PAGANTIS_PRIVATE_KEY_TEST')
195
            ) {
196
                Configuration::updateValue('pagantis_private_key', Configuration::get('PAGANTIS_PRIVATE_KEY_TEST'));
197
                Configuration::updateValue('PAGANTIS_PRIVATE_KEY_TEST', false);
198
            }
199
        }
200
    }
201
202
    /**
203
     * Check if new hooks used in new 7x versions are enabled and activate them if needed
204
     *
205
     * @throws PrestaShopDatabaseException
206
     */
207
    public function checkHooks()
208
    {
209
        try {
210
            $sql_content = 'select * from ' . _DB_PREFIX_. 'hook_module where 
0 ignored issues
show
Bug introduced by
The constant _DB_PREFIX_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
211
            id_module = \'' . Module::getModuleIdByName($this->name) . '\' and 
0 ignored issues
show
Bug introduced by
The type Module 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...
212
            id_shop = \'' . Shop::getContextShopID() . '\' and 
0 ignored issues
show
Bug introduced by
The type Shop 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...
213
            id_hook = \'' . Hook::getIdByName('header') . '\'';
0 ignored issues
show
Bug introduced by
The type Hook 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...
214
            $hook_exists = Db::getInstance()->ExecuteS($sql_content);
215
            if (empty($hook_exists)) {
216
                $sql_insert = 'insert into ' . _DB_PREFIX_.  'hook_module 
217
            (id_module, id_shop, id_hook, position)
218
            values
219
            (\''. Module::getModuleIdByName($this->name) . '\',
220
            \''. Shop::getContextShopID() . '\',
221
            \''. Hook::getIdByName('header') . '\',
222
            150)';
223
                Db::getInstance()->execute($sql_insert);
224
            }
225
        } catch (\Exception $exception) {
226
            // continue without errors
227
        }
228
    }
229
230
    /**
231
     * @throws PrestaShopDatabaseException
232
     */
233
    public function checkEnvVariables()
234
    {
235
        $sql_content = 'select * from ' . _DB_PREFIX_. 'pagantis_config';
0 ignored issues
show
Bug introduced by
The constant _DB_PREFIX_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
236
        $dbConfigs = Db::getInstance()->executeS($sql_content);
237
238
        // Convert a multimple dimension array for SQL insert statements into a simple key/value
239
        $simpleDbConfigs = array();
240
        foreach ($dbConfigs as $config) {
241
            $simpleDbConfigs[$config['config']] = $config['value'];
242
        }
243
        $newConfigs = array_diff_key($this->defaultConfigs, $simpleDbConfigs);
244
        if (!empty($newConfigs)) {
245
            $data = array();
246
            foreach ($newConfigs as $key => $value) {
247
                $data[] = array(
248
                    'config' => $key,
249
                    'value' => $value,
250
                );
251
            }
252
            Db::getInstance()->insert('pagantis_config', $data);
253
        }
254
    }
255
256
    /**
257
     * @param $sql_file
258
     * @return bool
259
     */
260
    public function loadSQLFile($sql_file)
261
    {
262
        $sql_content = Tools::file_get_contents($sql_file);
263
        $sql_content = str_replace('PREFIX_', _DB_PREFIX_, $sql_content);
0 ignored issues
show
Bug introduced by
The constant _DB_PREFIX_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
264
        $sql_requests = preg_split("/;\s*[\r\n]+/", $sql_content);
265
266
        $result = true;
267
        foreach ($sql_requests as $request) {
268
            if (!empty($request)) {
269
                $result &= Db::getInstance()->execute(trim($request));
270
            }
271
        }
272
273
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
274
    }
275
276
    /**
277
     * Check amount of order > minAmount
278
     * Check valid currency
279
     * Check API variables are set
280
     *
281
     * @return bool
282
     * @throws PrestaShopDatabaseException
283
     * @throws PrestaShopException
284
     */
285
    public function isPaymentMethodAvailable()
286
    {
287
        $cart                      = $this->context->cart;
288
        $currency                  = new Currency($cart->id_currency);
0 ignored issues
show
Bug introduced by
The type Currency 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...
289
        $availableCurrencies       = array('EUR');
290
        $pagantisDisplayMinAmount  = Pagantis::getExtraConfig('PAGANTIS_DISPLAY_MIN_AMOUNT');
291
        $pagantisPublicKey         = Configuration::get('pagantis_public_key');
292
        $pagantisPrivateKey        = Configuration::get('pagantis_private_key');
293
        $allowedCountries          = unserialize(Pagantis::getExtraConfig('PAGANTIS_ALLOWED_COUNTRIES'));
294
        return (
295
            $cart->getOrderTotal() >= $pagantisDisplayMinAmount &&
296
            in_array($currency->iso_code, $availableCurrencies) &&
297
            in_array(Tools::strtolower($this->language), $allowedCountries) &&
298
            $pagantisPublicKey &&
299
            $pagantisPrivateKey
300
        );
301
    }
302
303
    /**
304
     * @param Cart $cart
305
     *
306
     * @return array
307
     * @throws Exception
308
     */
309
    private function getButtonTemplateVars(Cart $cart)
0 ignored issues
show
Bug introduced by
The type Cart 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...
310
    {
311
        $currency = new Currency(($cart->id_currency));
312
313
        return array(
314
            'pagantis_button' => '#pagantis_payment_button',
315
            'pagantis_currency_iso' => $currency->iso_code,
316
            'pagantis_cart_total' => $cart->getOrderTotal(),
317
        );
318
    }
319
320
    /**
321
     * Header hook
322
     */
323
    public function hookHeader()
324
    {
325
        $url = 'https://cdn.pagantis.com/js/pg-v2/sdk.js';
326
        if ($this->language == 'ES' || $this->language == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->language of type mixed|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
327
            $url = 'https://cdn.pagantis.com/js/pmt-v2/sdk.js';
328
        }
329
        if (_PS_VERSION_ >= "1.7") {
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
330
            $this->context->controller->registerJavascript(
331
                sha1(mt_rand(1, 90000)),
332
                $url,
333
                array('server' => 'remote')
334
            );
335
        } else {
336
            $this->context->controller->addJS($url);
337
        }
338
        $this->context->controller->addJS($this->getPathUri(). 'views/js/simulator.js');
339
    }
340
341
    /**
342
     * @return array
343
     * @throws Exception
344
     */
345
    public function hookPaymentOptions()
346
    {
347
        if (!$this->isPaymentMethodAvailable()) {
348
            return array();
349
        }
350
351
        /** @var Cart $cart */
352
        $cart                               = $this->context->cart;
353
        $orderTotal                         = $cart->getOrderTotal();
354
        $promotedAmount                     = 0;
355
        $link                               = $this->context->link;
356
        $pagantisPublicKey                  = Configuration::get('pagantis_public_key');
357
        $pagantisSimulatorIsEnabled         = Configuration::get('pagantis_simulator_is_enabled');
358
        $pagantisIsEnabled                  = Configuration::get('pagantis_is_enabled');
359
        $pagantisSimulatorType              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_TYPE');
360
        $pagantisSimulatorCSSSelector       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR');
361
        $pagantisSimulatorPriceSelector     = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR');
362
        $pagantisSimulatorQuotesStart       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_START_INSTALLMENTS');
363
        $pagantisSimulatorSkin              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_SKIN');
364
        $pagantisSimulatorPosition          = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION');
365
        $pagantisTitle                      = $this->l(Pagantis::getExtraConfig('PAGANTIS_TITLE'));
366
        $pagantisSimulatorThousandSeparator = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_THOUSAND_SEPARATOR');
367
        $pagantisSimulatorDecimalSeparator  = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR');
368
369
        $items = $cart->getProducts(true);
370
        foreach ($items as $key => $item) {
371
            $itemCategories = ProductCore::getProductCategoriesFull($item['id_product']);
0 ignored issues
show
Bug introduced by
The type ProductCore 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...
372
            if (in_array(PROMOTIONS_CATEGORY_NAME, array_column($itemCategories, 'name')) !== false) {
373
                $promotedAmount += Product::getPriceStatic($item['id_product']);
0 ignored issues
show
Bug introduced by
The type Product 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...
374
            }
375
        }
376
377
        $this->context->smarty->assign($this->getButtonTemplateVars($cart));
378
        $this->context->smarty->assign(array(
379
            'amount'                             => $orderTotal,
380
            'locale'                             => $this->language,
381
            'pagantisPublicKey'                  => $pagantisPublicKey,
382
            'pagantisCSSSelector'                => $pagantisSimulatorCSSSelector,
383
            'pagantisPriceSelector'              => $pagantisSimulatorPriceSelector,
384
            'pagantisQuotesStart'                => $pagantisSimulatorQuotesStart,
385
            'pagantisSimulatorIsEnabled'         => $pagantisSimulatorIsEnabled,
386
            'pagantisSimulatorType'              => $pagantisSimulatorType,
387
            'pagantisSimulatorSkin'              => $pagantisSimulatorSkin,
388
            'pagantisSimulatorPosition'          => $pagantisSimulatorPosition,
389
            'pagantisIsEnabled'                  => $pagantisIsEnabled,
390
            'pagantisTitle'                      => $pagantisTitle,
391
            'paymentUrl'                         => $link->getModuleLink('pagantis', 'payment'),
392
            'pagantisSimulatorThousandSeparator' => $pagantisSimulatorThousandSeparator,
393
            'pagantisSimulatorDecimalSeparator'  => $pagantisSimulatorDecimalSeparator,
394
            'ps_version'                         => str_replace('.', '-', Tools::substr(_PS_VERSION_, 0, 3)),
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
395
        ));
396
397
        $logo = ($this->language == 'ES' || $this->language == null) ? 'logo_pagamastarde.png' : 'logo_pagantis.png';
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->language of type mixed|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
398
        $paymentOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption();
0 ignored issues
show
Bug introduced by
The type PrestaShop\PrestaShop\Core\Payment\PaymentOption 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...
399
        $paymentOption
400
            ->setCallToActionText($pagantisTitle)
401
            ->setAction($link->getModuleLink('pagantis', 'payment'))
402
            ->setLogo($this->getPathUri(). 'views/img/' . $logo)
403
            ->setModuleName(__CLASS__)
404
        ;
405
406
        $paymentOption->setAdditionalInformation(
407
            $this->fetch('module:pagantis/views/templates/hook/checkout.tpl')
408
        );
409
410
        return array($paymentOption);
411
    }
412
413
    /**
414
     * Get the form for editing the BackOffice options of the module
415
     *
416
     * @return array
417
     */
418
    private function getConfigForm()
419
    {
420
        return array(
421
            'form' => array(
422
                'legend' => array(
423
                    'title' => $this->l('Basic Settings'),
424
                    'icon' => 'icon-cogs',
425
                ),
426
                'input' => array(
427
                    array(
428
                        'name' => 'pagantis_is_enabled',
429
                        'type' =>  (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch',
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
430
                        'label' => $this->l('Module is enabled'),
431
                        'prefix' => '<i class="icon icon-key"></i>',
432
                        'class' => 't',
433
                        'required' => true,
434
                        'values'=> array(
435
                            array(
436
                                'id' => 'pagantis_is_enabled_true',
437
                                'value' => 1,
438
                                'label' => $this->l('Yes', get_class($this), null, false),
439
                            ),
440
                            array(
441
                                'id' => 'pagantis_is_enabled_false',
442
                                'value' => 0,
443
                                'label' => $this->l('No', get_class($this), null, false),
444
                            ),
445
                        )
446
                    ),
447
                    array(
448
                        'name' => 'pagantis_public_key',
449
                        'suffix' => $this->l('ex: pk_fd53cd467ba49022e4gf215e'),
450
                        'type' => 'text',
451
                        'size' => 60,
452
                        'label' => $this->l('Public Key'),
453
                        'prefix' => '<i class="icon icon-key"></i>',
454
                        'col' => 6,
455
                        'required' => true,
456
                    ),
457
                    array(
458
                        'name' => 'pagantis_private_key',
459
                        'suffix' => $this->l('ex: 21e5723a97459f6a'),
460
                        'type' => 'text',
461
                        'size' => 60,
462
                        'label' => $this->l('Secret Key'),
463
                        'prefix' => '<i class="icon icon-key"></i>',
464
                        'col' => 6,
465
                        'required' => true,
466
                    ),
467
                    array(
468
                        'name' => 'pagantis_simulator_is_enabled',
469
                        'type' => (version_compare(_PS_VERSION_, '1.6')<0) ?'radio' :'switch',
470
                        'label' => $this->l('Simulator is enabled'),
471
                        'prefix' => '<i class="icon icon-key"></i>',
472
                        'class' => 't',
473
                        'required' => true,
474
                        'values'=> array(
475
                            array(
476
                                'id' => 'pagantis_simulator_is_enabled_on',
477
                                'value' => 1,
478
                                'label' => $this->l('Yes'),
479
                            ),
480
                            array(
481
                                'id' => 'pagantis_simulator_is_enabled_off',
482
                                'value' => 0,
483
                                'label' => $this->l('No'),
484
                            ),
485
                        )
486
                    ),
487
                ),
488
                'submit' => array(
489
                    'title' => $this->l('Save'),
490
                ),
491
            ),
492
        );
493
    }
494
495
    /**
496
     * Form configuration function
497
     *
498
     * @param array $settings
499
     *
500
     * @return string
501
     */
502
    private function renderForm(array $settings)
503
    {
504
        $helper = new HelperForm();
0 ignored issues
show
Bug introduced by
The type HelperForm 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...
505
        $helper->show_toolbar = false;
506
        $helper->table = $this->table;
507
        $helper->module = $this;
508
        $helper->default_form_language = $this->context->language->id;
509
        $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
510
        $helper->identifier = $this->identifier;
511
        $helper->submit_action = 'submit'.$this->name;
512
        $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
0 ignored issues
show
Bug introduced by
The type AdminController 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...
513
        $helper->token = Tools::getAdminTokenLite('AdminModules');
514
        $helper->tpl_vars = array(
515
            'fields_value' => $settings,
516
            'languages' => $this->context->controller->getLanguages(),
517
            'id_language' => $this->context->language->id,
518
        );
519
520
        $helper->fields_value['pagantis_url_ok'] = Configuration::get('pagantis_url_ok');
521
522
        return $helper->generateForm(array($this->getConfigForm()));
523
    }
524
525
    /**
526
     * Function to update the variables of Pagantis Module in the backoffice of prestashop
527
     *
528
     * @return string
529
     * @throws SmartyException
530
     */
531
    public function getContent()
532
    {
533
        $error = '';
534
        $message = '';
535
        $settings = array();
536
        $settings['pagantis_public_key'] = Configuration::get('pagantis_public_key');
537
        $settings['pagantis_private_key'] = Configuration::get('pagantis_private_key');
538
        $settingsKeys = array(
539
            'pagantis_is_enabled',
540
            'pagantis_public_key',
541
            'pagantis_private_key',
542
            'pagantis_simulator_is_enabled',
543
        );
544
545
        //Different Behavior depending on 1.6 or earlier
546
        if (Tools::isSubmit('submit'.$this->name)) {
547
            foreach ($settingsKeys as $key) {
548
                switch ($key) {
549
                    case 'pagantis_public_key':
550
                        $value = Tools::getValue($key);
551
                        if (!$value) {
552
                            $error = $this->l('Please add a Pagantis API Public Key');
553
                            break;
554
                        }
555
                        Configuration::updateValue($key, $value);
556
                        $settings[$key] = $value;
557
                        break;
558
                    case 'pagantis_private_key':
559
                        $value = Tools::getValue($key);
560
                        if (!$value) {
561
                            $error = $this->l('Please add a Pagantis API Private Key');
562
                            break;
563
                        }
564
                        Configuration::updateValue($key, $value);
565
                        $settings[$key] = $value;
566
                        break;
567
                    default:
568
                        $value = Tools::getValue($key);
569
                        Configuration::updateValue($key, $value);
570
                        $settings[$key] = $value;
571
                        break;
572
                }
573
                $message = $this->displayConfirmation($this->l('All changes have been saved'));
574
            }
575
        } else {
576
            foreach ($settingsKeys as $key) {
577
                    $settings[$key] = Configuration::get($key);
578
            }
579
        }
580
581
        if ($error) {
582
            $message = $this->displayError($error);
583
        }
584
585
        $logo = $this->getPathUri(). 'views/img/logo_pagantis.png';
586
        if ($this->language == 'ES' || $this->language == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->language of type mixed|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
587
            $logo = $this->getPathUri(). 'views/img/logo_pagamastarde.png';
588
        }
589
        $tpl = $this->local_path.'views/templates/admin/config-info.tpl';
590
        $this->context->smarty->assign(array(
591
            'logo' => $logo,
592
            'form' => $this->renderForm($settings),
593
            'message' => $message,
594
            'version' => 'v'.$this->version,
595
        ));
596
597
        return $this->context->smarty->fetch($tpl);
598
    }
599
600
    /**
601
     * Hook to show payment method, this only applies on prestashop <= 1.6
602
     *
603
     * @param $params
604
     * @return bool | string
605
     * @throws Exception
606
     */
607
    public function hookPayment($params)
608
    {
609
        if (!$this->isPaymentMethodAvailable()) {
610
            return false;
611
        }
612
613
        /** @var Cart $cart */
614
615
        $cart                               = $params['cart'];
616
        $orderTotal                         = $cart->getOrderTotal();
617
        $promotedAmount                     = 0;
618
        $link                               = $this->context->link;
619
        $pagantisPublicKey                  = Configuration::get('pagantis_public_key');
620
        $pagantisSimulatorIsEnabled         = Configuration::get('pagantis_simulator_is_enabled');
621
        $pagantisIsEnabled                  = Configuration::get('pagantis_is_enabled');
622
        $pagantisSimulatorType              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_TYPE');
623
        $pagantisSimulatorCSSSelector       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR');
624
        $pagantisSimulatorPriceSelector     = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR');
625
        $pagantisSimulatorQuotesStart       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_START_INSTALLMENTS');
626
        $pagantisSimulatorSkin              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_SKIN');
627
        $pagantisSimulatorPosition          = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION');
628
        $pagantisTitle                      = $this->l(Pagantis::getExtraConfig('PAGANTIS_TITLE'));
629
        $pagantisSimulatorThousandSeparator = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_THOUSAND_SEPARATOR');
630
        $pagantisSimulatorDecimalSeparator  = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR');
631
632
        $items = $cart->getProducts(true);
633
        foreach ($items as $key => $item) {
634
            $itemCategories = ProductCore::getProductCategoriesFull($item['id_product']);
635
            if (in_array(PROMOTIONS_CATEGORY_NAME, array_column($itemCategories, 'name')) !== false) {
636
                $promotedAmount += Product::getPriceStatic($item['id_product']);
637
            }
638
        }
639
640
        $this->context->smarty->assign($this->getButtonTemplateVars($cart));
641
        $this->context->smarty->assign(array(
642
            'amount'                             => $orderTotal,
643
            'promotedAmount'                     => $promotedAmount,
644
            'locale'                             => $this->language,
645
            'logo' => ($this->language == 'ES' || $this->language == null) ? 'pagamastarde.png' : 'pagantis.png',
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->language of type mixed|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
646
            'pagantisPublicKey'                  => $pagantisPublicKey,
647
            'pagantisCSSSelector'                => $pagantisSimulatorCSSSelector,
648
            'pagantisPriceSelector'              => $pagantisSimulatorPriceSelector,
649
            'pagantisQuotesStart'                => $pagantisSimulatorQuotesStart,
650
            'pagantisSimulatorIsEnabled'         => $pagantisSimulatorIsEnabled,
651
            'pagantisSimulatorType'              => $pagantisSimulatorType,
652
            'pagantisSimulatorSkin'              => $pagantisSimulatorSkin,
653
            'pagantisSimulatorPosition'          => $pagantisSimulatorPosition,
654
            'pagantisIsEnabled'                  => $pagantisIsEnabled,
655
            'pagantisTitle'                      => $pagantisTitle,
656
            'pagantisSimulatorThousandSeparator' => $pagantisSimulatorThousandSeparator,
657
            'pagantisSimulatorDecimalSeparator'  => $pagantisSimulatorDecimalSeparator,
658
            'paymentUrl'                         => $link->getModuleLink('pagantis', 'payment'),
659
            'ps_version'                         => str_replace('.', '-', Tools::substr(_PS_VERSION_, 0, 3)),
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
660
        ));
661
662
        $supercheckout_enabled = Module::isEnabled('supercheckout');
663
        $onepagecheckoutps_enabled = Module::isEnabled('onepagecheckoutps');
664
        $onepagecheckout_enabled = Module::isEnabled('onepagecheckout');
665
666
        $return = true;
667
        if ($supercheckout_enabled || $onepagecheckout_enabled || $onepagecheckoutps_enabled) {
668
            $this->checkLogoExists();
669
            $return = $this->display(__FILE__, 'views/templates/hook/onepagecheckout.tpl');
670
        } elseif (_PS_VERSION_ < 1.7) {
671
            $return = $this->display(__FILE__, 'views/templates/hook/checkout.tpl');
672
        }
673
        return $return;
674
    }
675
676
    /**
677
     * @param string $functionName
678
     *:
679
     * @return string
680
     * @throws PrestaShopDatabaseException
681
     * @throws PrestaShopException
682
     */
683
    public function productPageSimulatorDisplay($functionName)
684
    {
685
        $productConfiguration = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_POSITION');
686
        /** @var ProductCore $product */
687
        $product = new Product(Tools::getValue('id_product'));
688
        $amount = $product->getPublicPrice();
689
690
        $itemCategoriesNames = array_column(Product::getProductCategoriesFull($product->id), 'name');
691
        $isPromotedProduct = in_array(PROMOTIONS_CATEGORY_NAME, $itemCategoriesNames);
692
693
        $pagantisPublicKey                  = Configuration::get('pagantis_public_key');
694
        $pagantisSimulatorIsEnabled         = Configuration::get('pagantis_simulator_is_enabled');
695
        $pagantisIsEnabled                  = Configuration::get('pagantis_is_enabled');
696
        $pagantisSimulatorType              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_TYPE');
697
        $pagantisSimulatorCSSSelector       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR');
698
        $pagantisSimulatorPriceSelector     = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR');
699
        $pagantisSimulatorQuantitySelector  = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR');
700
        $pagantisSimulatorQuotesStart       = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_START_INSTALLMENTS');
701
        $pagantisSimulatorSkin              = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_SKIN');
702
        $pagantisSimulatorPosition          = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION');
703
        $pagantisDisplayMinAmount           = Pagantis::getExtraConfig('PAGANTIS_DISPLAY_MIN_AMOUNT');
704
        $pagantisPromotionExtra             = Pagantis::getExtraConfig('PAGANTIS_PROMOTION_EXTRA');
705
        $pagantisSimulatorThousandSeparator = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_THOUSAND_SEPARATOR');
706
        $pagantisSimulatorDecimalSeparator  = Pagantis::getExtraConfig('PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR');
707
708
        if ($functionName != $productConfiguration ||
709
            $amount <= 0 ||
710
            $amount < $pagantisDisplayMinAmount ||
711
            !$pagantisSimulatorType
712
        ) {
713
            return null;
714
        }
715
716
        $this->context->smarty->assign(array(
717
            'amount'                             => $amount,
718
            'locale'                             => $this->language,
719
            'pagantisPublicKey'                  => $pagantisPublicKey,
720
            'pagantisCSSSelector'                => $pagantisSimulatorCSSSelector,
721
            'pagantisPriceSelector'              => $pagantisSimulatorPriceSelector,
722
            'pagantisQuantitySelector'           => $pagantisSimulatorQuantitySelector,
723
            'pagantisSimulatorIsEnabled'         => $pagantisSimulatorIsEnabled,
724
            'pagantisIsEnabled'                  => $pagantisIsEnabled,
725
            'pagantisSimulatorType'              => $pagantisSimulatorType,
726
            'pagantisSimulatorSkin'              => $pagantisSimulatorSkin,
727
            'pagantisSimulatorPosition'          => $pagantisSimulatorPosition,
728
            'pagantisQuotesStart'                => $pagantisSimulatorQuotesStart,
729
            'isPromotedProduct'                  => $isPromotedProduct,
730
            'pagantisPromotionExtra'             => $this->l($pagantisPromotionExtra),
731
            'pagantisSimulatorThousandSeparator' => $pagantisSimulatorThousandSeparator,
732
            'pagantisSimulatorDecimalSeparator'  => $pagantisSimulatorDecimalSeparator,
733
            'ps_version'                         => str_replace('.', '-', Tools::substr(_PS_VERSION_, 0, 3)),
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
734
        ));
735
736
        return $this->display(__FILE__, 'views/templates/hook/product-simulator.tpl');
737
    }
738
739
    /**
740
     * @return string
741
     * @throws PrestaShopDatabaseException
742
     * @throws PrestaShopException
743
     */
744
    public function hookDisplayRightColumn()
745
    {
746
747
        return $this->productPageSimulatorDisplay(__FUNCTION__);
748
    }
749
750
    /**
751
     * @return string
752
     * @throws PrestaShopDatabaseException
753
     * @throws PrestaShopException
754
     */
755
    public function hookDisplayLeftColumn()
756
    {
757
        return $this->productPageSimulatorDisplay(__FUNCTION__);
758
    }
759
760
    /**
761
     * @return string
762
     * @throws PrestaShopDatabaseException
763
     * @throws PrestaShopException
764
     */
765
    public function hookDisplayRightColumnProduct()
766
    {
767
        return $this->productPageSimulatorDisplay(__FUNCTION__);
768
    }
769
770
    /**
771
     * @return string
772
     * @throws PrestaShopDatabaseException
773
     * @throws PrestaShopException
774
     */
775
    public function hookDisplayLeftColumnProduct()
776
    {
777
        return $this->productPageSimulatorDisplay(__FUNCTION__);
778
    }
779
780
    /**
781
     * @return string
782
     * @throws PrestaShopDatabaseException
783
     * @throws PrestaShopException
784
     */
785
    public function hookDisplayProductButtons()
786
    {
787
        return $this->productPageSimulatorDisplay(__FUNCTION__);
788
    }
789
790
    /**
791
     * @param array $params
792
     *
793
     * @return string
794
     */
795
    public function hookDisplayOrderConfirmation($params)
796
    {
797
        $paymentMethod = (_PS_VERSION_ < 1.7) ? ($params["objOrder"]->payment) : ($params["order"]->payment);
0 ignored issues
show
Bug introduced by
The constant _PS_VERSION_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
798
799
        if ($paymentMethod == $this->displayName) {
800
            return $this->display(__FILE__, 'views/templates/hook/payment-return.tpl');
801
        }
802
803
        return null;
804
    }
805
806
    /**
807
     * Check logo exists in OPC module
808
     */
809
    public function checkLogoExists()
810
    {
811
        $logoPmt = _PS_MODULE_DIR_ . '/onepagecheckoutps/views/img/payments/pagamastarde.png';
0 ignored issues
show
Bug introduced by
The constant _PS_MODULE_DIR_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
812
        $logoPg = _PS_MODULE_DIR_ . '/onepagecheckoutps/views/img/payments/pagantis.png';
813
        if (!file_exists($logoPmt) && is_dir(_PS_MODULE_DIR_ . '/onepagecheckoutps/views/img/payments')) {
814
            copy(
815
                _PS_PAGANTIS_DIR . '/views/img/logo_pagamastarde.png',
816
                $logoPmt
817
            );
818
        }
819
        if (!file_exists($logoPg) && is_dir(_PS_MODULE_DIR_ . '/onepagecheckoutps/views/img/payments')) {
820
            copy(
821
                _PS_PAGANTIS_DIR . '/views/img/logo_pagantis.png',
822
                $logoPg
823
            );
824
        }
825
    }
826
827
    /**
828
     * checkPromotionCategory
829
     */
830
    public function checkPromotionCategory()
831
    {
832
        $categories = array_column(Category::getCategories(null, false, false), 'name');
0 ignored issues
show
Bug introduced by
The type Category 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...
833
        if (!in_array(PROMOTIONS_CATEGORY_NAME, $categories)) {
834
            /** @var CategoryCore $category */
835
            $category = new Category();
836
            $category->is_root_category = false;
837
            $category->link_rewrite = array( 1=> PROMOTIONS_CATEGORY );
838
            $category->meta_description = array( 1=> PROMOTIONS_CATEGORY );
839
            $category->meta_keywords = array( 1=> PROMOTIONS_CATEGORY );
840
            $category->meta_title = array( 1=> PROMOTIONS_CATEGORY );
841
            $category->name = array( 1=> PROMOTIONS_CATEGORY_NAME );
842
            $category->id_parent = Configuration::get('PS_HOME_CATEGORY');
843
            $category->active=0;
844
            $description = 'Pagantis: Products with this category have free financing assumed by the merchant. ' .
845
                'Use it to promote your products or brands.';
846
            $category->description = $this->l($description);
847
            $category->save();
848
        }
849
    }
850
851
852
    public static function getExtraConfig($config = null, $default = '')
853
    {
854
        if (is_null($config)) {
855
            return '';
856
        }
857
858
        $sql = 'SELECT value FROM '._DB_PREFIX_.'pagantis_config where config = \'' . pSQL($config) . '\' limit 1';
0 ignored issues
show
Bug introduced by
The constant _DB_PREFIX_ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function pSQL was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

858
        $sql = 'SELECT value FROM '._DB_PREFIX_.'pagantis_config where config = \'' . /** @scrutinizer ignore-call */ pSQL($config) . '\' limit 1';
Loading history...
859
        if ($results = Db::getInstance()->ExecuteS($sql)) {
860
            if (is_array($results) && count($results) === 1 && isset($results[0]['value'])) {
861
                return $results[0]['value'];
862
            }
863
        }
864
865
        return $default;
866
    }
867
}
868