Skip to content

Commit

Permalink
Merge pull request #4 from Ecomailcz/michael-tweaks
Browse files Browse the repository at this point in the history
Updated readme, new installation page, better translations
  • Loading branch information
michaelbranny authored Mar 8, 2023
2 parents 62f57c8 + d3830e8 commit 59529d9
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 207 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ https://github.com/Ecomailcz/Prestashop-1.6/releases/download/2.0/ecomailemailma

Help on how to use the module can be found here:

https://support.ecomail.cz/hc/cs/articles/209707269-Prestashop-plugin-1-6
CZ:
https://support.ecomail.cz/cs/articles/66911-prestashop-plugin-1-5-1-7

EN:
https://support.ecomail.app/en/articles/6983944-integrate-with-prestashop
89 changes: 89 additions & 0 deletions ecomailemailmarketing/controllers/front/ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* 2007-2023 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2023 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class EcomailemailmarketingAjaxModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$this->ajax = true;
parent::initContent();
}

public function displayAjaxSaveApi()
{
$apikey = Tools::getValue('apikey');

if (!$this->isApiKeyValid($apikey)) {
echo json_encode(['error' => 'Invalid API key']);
exit;
}

echo json_encode($this->saveApi($apikey));
exit;
}

public function saveApi(string $apikey): bool
{
Configuration::updateValue('ECOMAIL_API_KEY', $apikey);

return true;
}

protected function isApiKeyValid(string $apiKey): bool
{
$ch = curl_init();

curl_setopt(
$ch,
CURLOPT_URL,
'https://api2.ecomailapp.cz/account',
);
curl_setopt(
$ch,
CURLOPT_RETURNTRANSFER,
true
);
curl_setopt(
$ch,
CURLOPT_HEADER,
false
);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
'Key: ' . $apiKey,
]
);

$response = curl_exec($ch);
curl_close($ch);

$response = (array) json_decode($response);

return !(isset($response['message']) && $response['message'] === 'Wrong api key');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

Expand Down
31 changes: 31 additions & 0 deletions ecomailemailmarketing/controllers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
48 changes: 25 additions & 23 deletions ecomailemailmarketing/ecomailemailmarketing.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
$this->module_key = '3c90ebaffe6722aece11c7a66bc18bec';
$this->name = 'ecomailemailmarketing';
$this->tab = 'emailing';
$this->version = '2.0.0';
$this->version = '2.0.2';
$this->author = 'Ecomail';
$this->need_instance = 0;
$this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => '8.0.1'];
Expand All @@ -39,7 +39,7 @@ public function __construct()
parent::__construct();

$this->displayName = $this->l('Ecomail email marketing');
$this->description = $this->l('Connection of the e-shop to Ecomail.');
$this->description = $this->l('Grow your business with an effective email marketing strategy. Ecomail will boost your sales immediately and save you precious time.');

$this->confirmUninstall = $this->l('Do you really want to uninstall Ecomail?');
}
Expand Down Expand Up @@ -116,6 +116,7 @@ public function setHooks(): bool
$this->registerHook('actionCartSave') &&
$this->registerHook('actionCustomerAccountUpdate') &&
$this->registerHook('actionSubmitCustomerAddressForm') &&
$this->registerHook('displayBackOfficeHeader') &&
$this->registerHook('addWebserviceResources');
}

Expand Down Expand Up @@ -440,25 +441,20 @@ public function displayForm(): string
],
];
} else {
$fields_form[0]['form'] = [
'legend' => [
'title' => $this->l('Ecomail configuration'),
],
'input' => [
[
'type' => 'text',
'label' => $this->l('Enter your API key'),
'name' => 'api_key',
'rows' => 20,
'required' => true,
'desc' => $this->l('Once your API key is loaded correctly, you will select a list of contacts for your e-shop.'),
],
],
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
],
];
$this->context->smarty->assign(
[
'api_key_input' => (Configuration::get($this->name . '_api_key') ? Configuration::get($this->name . '_api_key') : null),
]
);

$ajax_link = $this->context->link->getModuleLink('ecomailemailmarketing', 'ajax', []);
Media::addJsDef(
[
'ajax_link' => $ajax_link,
]
);

return $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
}

$helper = new HelperForm();
Expand Down Expand Up @@ -838,11 +834,10 @@ public function syncCustomers(string $listId): void
public function requestGet(string $url, string $event): ?array
{
$ch = curl_init();
$display = '?display=full';
$display = '?display=full&output_format=JSON';
$url = $url . $event . $display;

$headers = [
'output_format:JSON',
'Authorization: Basic ' . base64_encode(Configuration::get('ECOMAIL_WEBSERVICE_KEY') . ':'),
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Expand Down Expand Up @@ -981,4 +976,11 @@ public function hookAddWebserviceResources(array $params): bool
{
return true;
}

public function hookDisplayBackOfficeHeader()
{
if (Tools::getValue('configure') == $this->name) {
$this->context->controller->addJS($this->_path . 'views/js/save.js');
}
}
}
4 changes: 2 additions & 2 deletions ecomailemailmarketing/lib/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function subscribeToList(string $listId, array $customerData)
return $this->call(
sprintf(
'lists/%d/subscribe',
$listId
urlencode($listId)
),
'POST',
[
Expand Down Expand Up @@ -151,7 +151,7 @@ public function bulkSubscribeToList(string $listId, array $data)
return $this->call(
sprintf(
'lists/%d/subscribe-bulk',
$listId
urlencode($listId)
),
'POST',
[
Expand Down
Loading

0 comments on commit 59529d9

Please sign in to comment.