Skip to content

Commit

Permalink
PLUGINRANGERS-267 | Adjust plugin to the version 9 guidelines (#269)
Browse files Browse the repository at this point in the history
* feat: Migrated config + autoloader

* feat: Adapted doofinder-ajax.php

* feat: Removed all the .php files from root folder except main file

* feat: Version bump to 4.10.0

* fix: Changed PHP linter versions
  • Loading branch information
davidmolinacano authored Dec 16, 2024
1 parent 479b16c commit bfa5473
Show file tree
Hide file tree
Showing 19 changed files with 389 additions and 341 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3
name: PHP Syntax check 5.4|5.6|7.2|7.4|8.0|8.4
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -17,14 +17,20 @@ jobs:
- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master

- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@master
- name: PHP syntax checker 7.4
uses: prestashop/github-action-php-lint/7.4@master

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master

- name: PHP syntax checker 8.4
uses: prestashop/github-action-php-lint/8.4@master

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- run: composer install

Expand Down
32 changes: 0 additions & 32 deletions cache.php

This file was deleted.

103 changes: 0 additions & 103 deletions config.php

This file was deleted.

56 changes: 56 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Doofinder
* @copyright Doofinder
* @license GPLv3
*/
if (!defined('_PS_VERSION_')) {
exit;
}

use PrestaShop\Module\Doofinder\Src\Entity\DoofinderApi;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderInstallation;

class DoofinderAjaxModuleFrontController extends ModuleFrontController
{
/**
* Assign template vars related to page content.
*
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();

$this->ajax = 1;

$checkApiKey = Tools::getValue('check_api_key');
if ($checkApiKey) {
exit(DoofinderApi::checkApiKey(true));
}

$autoinstaller = Tools::getValue('autoinstaller');
$shopId = Tools::getValue('shop_id', null);
if ($autoinstaller) {
if (Tools::getValue('token') == Tools::encrypt('doofinder-ajax')) {
header('Content-Type:application/json; charset=utf-8');
DoofinderInstallation::autoinstaller($shopId);
$this->ajaxRender(json_encode(['success' => true]));
exit;
} else {
$this->ajaxRender(json_encode([
'success' => false, 'errors' => ['Forbidden access. Invalid token for autoinstaller.'],
]));
exit;
}
}
}
}
39 changes: 39 additions & 0 deletions controllers/front/cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Doofinder
* @copyright Doofinder
* @license GPLv3
*/
if (!defined('_PS_VERSION_')) {
exit;
}

class DoofinderCacheModuleFrontController extends ModuleFrontController
{
/**
* Assign template vars related to page content.
*
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();

$this->ajax = 1;

if (Tools::isSubmit('landing')) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
return Db::getInstance()->delete('doofinder_landing');
}
exit;
}
}
}
103 changes: 103 additions & 0 deletions controllers/front/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Doofinder
* @copyright Doofinder
* @license GPLv3
*/
if (!defined('_PS_VERSION_')) {
exit;
}

use PrestaShop\Module\Doofinder\Src\Entity\DfTools;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConfig;
use PrestaShop\Module\Doofinder\Src\Entity\DoofinderConstants;

class DoofinderConfigModuleFrontController extends ModuleFrontController
{
/**
* Assign template vars related to page content.
*
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();

$this->ajax = 1;

header('Content-Type:application/json; charset=utf-8');

$module = Module::getInstanceByName('doofinder');
$autoinstallerToken = Tools::getValue('token');
if ($autoinstallerToken) {
$redirect = Context::getContext()->shop->getBaseURL(true, false)
. $module->getPathUri() . 'config.php';
$tmpToken = Tools::encrypt($redirect);
if ($tmpToken == $autoinstallerToken) {
$apiToken = Tools::getValue('api_token');
$api_endpoint = Tools::getValue('api_endpoint');
$admin_endpoint = Tools::getValue('admin_endpoint');
if ($apiToken) {
DoofinderConfig::saveApiConfig($apiToken, $api_endpoint, $admin_endpoint);
}
echo json_encode(['success' => true]);
exit;
} else {
header('HTTP/1.1 403 Forbidden', true, 403);
$msgError = 'Forbidden access.'
. ' Token for autoinstaller invalid.';
exit($msgError);
}
}

$languages = [];
$configurations = [];
$currencies = array_keys(DfTools::getAvailableCurrencies());

$display_prices = (bool) Configuration::get('DF_GS_DISPLAY_PRICES');
$prices_with_taxes = (bool) Configuration::get('DF_GS_PRICES_USE_TAX');

foreach (Language::getLanguages(true, $this->context->shop->id) as $lang) {
$lang = Tools::strtoupper($lang['iso_code']);
$currency = DfTools::getCurrencyForLanguage($lang);

$languages[] = $lang;
$configurations[$lang] = [
'language' => $lang,
'currency' => Tools::strtoupper($currency->iso_code),
'prices' => $display_prices,
'taxes' => $prices_with_taxes,
];
}

$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
$shop = $this->context->shop;
$base = (($force_ssl) ? 'https://' . $shop->domain_ssl : 'http://' . $shop->domain);

$cfg = [
'platform' => [
'name' => 'Prestashop',
'version' => _PS_VERSION_,
],
'module' => [
'version' => DoofinderConstants::VERSION,
'feed' => $base . $shop->getBaseURI() . 'modules/doofinder/feed.php',
'options' => [
'language' => $languages,
'currency' => $currencies,
],
'configuration' => $configurations,
],
];

$this->ajaxRender(DfTools::jsonEncode($cfg));
}
}
Loading

0 comments on commit bfa5473

Please sign in to comment.