Skip to content

Commit

Permalink
Merge pull request #130 from mailjet/DE-959-test-and-update-plugin-wi…
Browse files Browse the repository at this point in the history
…th-new-version-of-prestashop

Prepare plugin for Prestashop 8.0.x
  • Loading branch information
oleksandr-mykhailenko authored Feb 23, 2023
2 parents 280e55a + 6e61858 commit 9c79b4b
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 179 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Boost your ROI and increase your merchant revenue with the Mailjet v3 all-in-one
## Plug-in Key Info

* Plug-in languages: English, French, German, Spanish
* PrestaShop Compatibility: PrestaShop v1.5.0 - v1.7.5
* PrestaShop Compatibility: PrestaShop v1.5.0 - v8.0.x
* PHP Compatibility: requires PHP 5.5 or newer
* Mailjet Compatibility: Mailjet account
* Support: https://app.mailjet.com/support/ticket
Expand Down Expand Up @@ -65,6 +65,10 @@ Happy emailing!


## Changelog
= 3.6.0 =
* Support version 8.0.x
* Code cleanup

= 3.5.2 =
* Correct config file for PS version 1.7.*
* Code cleanup
Expand Down
8 changes: 4 additions & 4 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* International Registered Trademark & Property of PrestaShop SA
*/

require_once(realpath(dirname(__FILE__) . '/../../config/config.inc.php'));
require_once(dirname(__DIR__, 2) . '/config/config.inc.php');
if (_PS_VERSION_ < '1.5' || !defined('_PS_ADMIN_DIR_')) {
require_once(realpath(dirname(__FILE__) . '/../../init.php'));
require_once(dirname(__DIR__, 2) . '/init.php');
}

$token_ok = Tools::getAdminToken(
Expand Down Expand Up @@ -65,7 +65,7 @@
$token = Tools::isSubmit('token') ? Tools::getValue('token') : '';

$mj = new Mailjet();
$result = array();
$result = [];

MailJetLog::write(MailJetLog::$file, 'New request sent');

Expand All @@ -81,4 +81,4 @@
MailJetLog::write(MailJetLog::$file, $message);

header('Content-Type: application/json');
die(Tools::jsonEncode($result));
die(json_encode($result));
16 changes: 8 additions & 8 deletions ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
'values' => $bindOrderStates
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 4: /* payment method used */
$res = Db::getInstance()->executeS('SELECT DISTINCT(payment) FROM ' . _DB_PREFIX_ . 'orders');
Expand All @@ -84,7 +84,7 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 8: /* ca */
case 9: /* avg ca */
Expand All @@ -98,7 +98,7 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 19: /* newsletter subscription */
$values = array(
Expand All @@ -111,7 +111,7 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 15: /* gift package */
case 16: /* recycled packaging */
Expand All @@ -130,7 +130,7 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 21: /* origin */
$sql = 'SELECT DISTINCT(conn.http_referer) AS url FROM ' . _DB_PREFIX_ . 'connections conn
Expand All @@ -151,7 +151,7 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
case 27: /* city */
$sql = 'SELECT DISTINCT(TRIM(a.city)) AS city FROM ' . _DB_PREFIX_ . 'address a
Expand All @@ -170,12 +170,12 @@
'values' => $values
);

die(Tools::jsonEncode($bind));
die(json_encode($bind));
/* break; */
default:
$bind = $obj->getBinder(Tools::getValue('ID'));
if ($bind != '') {
$json = Tools::jsonEncode(explode(';', $bind));
$json = json_encode(explode(';', $bind));
die('{"return" : ' . $json . '}');
}
}
Expand Down
14 changes: 7 additions & 7 deletions callback_campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* International Registered Trademark & Property of PrestaShop SA
*/

require_once(realpath(dirname(__FILE__) . '/../../config/config.inc.php'));
require_once(dirname(__DIR__, 2) . '/config/config.inc.php');
if (_PS_VERSION_ < '1.5' || !defined('_PS_ADMIN_DIR_')) {
require_once(realpath(dirname(__FILE__) . '/../../init.php'));
require_once(dirname(__FILE__, 3) . '/init.php');
}


Expand Down Expand Up @@ -101,18 +101,18 @@
$res = $mj_data->data('newsletter', $campaignId, 'HTML', 'text/html', $html, 'PUT', 'LAST')->getResponse();
}

$response = array(
$response = [
'code' => 1,
'continue' => true,
'continue_address' => $data->next_step_url,
);
];
} else {
$response = array(
$response = [
'code' => 0,
'continue' => false,
'exit_url' => 'SOME URL ADDRESS',
);
];
}

header('Content-Type: application/json');
echo Tools::jsonEncode($response);
echo json_encode($response);
13 changes: 9 additions & 4 deletions classes/Segmentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ public function saveFilter($post, $auto_assign = false, $replace_customer = fals
$post['replace_customer'] = $replace_customer_text;
$post['auto_assign'] = $auto_assign_text;
$post['group_name'] = $group_name;
return Tools::jsonEncode($post);
return json_encode($post);
}

public function deleteFilter($id)
Expand Down Expand Up @@ -1242,15 +1242,20 @@ public function loadFilter($id_filter)
$r['getIndicSelect'] = $this->getIndicSelect($r['id_sourcecondition'], $i, $r['id_fieldcondition']);
$i++;
}
return Tools::jsonEncode($res);
return json_encode($res);
}
return false;
}

/**
* @param $id_filter
* @return string
* @throws PrestaShopDatabaseException
*/
public function loadFilterInfo($id_filter)
{
$res = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'mj_filter` WHERE `id_filter`=' . (int) $id_filter);
$json = Tools::jsonEncode($res);
$json = json_encode($res);
return '{"return" : ' . $json . '}';
}

Expand Down Expand Up @@ -1394,7 +1399,7 @@ public function initLang($id_lang = 0)
}
file_put_contents(
$this->_path . '/translations/translation_cache_' . (int) $id_lang . '.txt',
Tools::jsonEncode($this->trad)
json_encode($this->trad)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/hooks/synchronization/SingleUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HooksSynchronizationSingleUser extends HooksSynchronizationSynchronization
public function subscribe($email, $list_id = null)
{
$api = $this->getApi();
$update_list_id = $list_id ? $list_id : $this->getAlreadyCreatedMasterListId();
$update_list_id = $list_id ?: $this->getAlreadyCreatedMasterListId();
$api->resetRequest();

if (!$update_list_id || empty($update_list_id)) {
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>mailjet</name>
<displayName><![CDATA[Mailjet]]></displayName>
<version><![CDATA[3.5.2]]></version>
<version><![CDATA[3.6.0]]></version>
<description><![CDATA[Create contact lists and client segment groups, drag-n-drop newsletters, define client re-engagement triggers, follow and analyze all email user interaction, minimize negative user engagement events(blocked, unsubs and spam) and optimise deliverability and revenue generation. Get started today with 6000 free emails per month.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[advertising_marketing]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion libraries/MailJet.Data.Api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private function sendRequest($Method, $Uri, $MimeType, $RawData)
break;

case 'JSON':
$RawData = Tools::jsonEncode($RawData);
$RawData = json_encode($RawData);
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, $RawData);
curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
Expand Down
29 changes: 14 additions & 15 deletions libraries/Mailjet.Api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,12 @@ public function data(
break;
case 'DELETE':
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
/* curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); */
$this->_request_post = $params;
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post)))
'Content-Length: ' . strlen(json_encode($this->_request_post)))
);
break;
case 'JSON':
Expand All @@ -314,11 +313,11 @@ public function data(
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST");

$this->_request_post = $params;
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post)))
'Content-Length: ' . strlen(json_encode($this->_request_post)))
);
break;
}
Expand Down Expand Up @@ -613,12 +612,12 @@ private function writeCache($object, $params, $request, $result)
} else {
$cache = $this->_cache;
}
if ($request == 'GET' && $cache != 0) {
if ($request === 'GET' && $cache != 0) {
sort($params);
$file =
$object . '.' . hash('md5', $this->_apiKey . http_build_query($params, '', '')) . '.' . $this->_output;
$data = array('timestamp' => time(), 'result' => $result);
file_put_contents($this->_cache_path . $file, Tools::jsonEncode($data));
file_put_contents($this->_cache_path . $file, json_encode($data));
}
}

Expand Down Expand Up @@ -756,7 +755,7 @@ private function sendRequest($method = FALSE, $params = array(), $request = "GET

curl_setopt($this->_curl_handle, CURLOPT_POST, count($params));
if (isset($params['Action']) && isset($params['ListID'])) {
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($params));
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
} else {
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&'));
Expand All @@ -770,27 +769,27 @@ private function sendRequest($method = FALSE, $params = array(), $request = "GET
break;
case 'DELETE':
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
/* curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, http_build_query($params, '', '&')); */
$this->_request_post = $params;
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post)))
'Content-Length: ' . strlen(json_encode($this->_request_post)))
);
break;
case 'JSON':
if ($is_json_put)
if ($is_json_put) {
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "PUT");
else
} else {
curl_setopt($this->_curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
}

$this->_request_post = $params;
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, Tools::jsonEncode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_POSTFIELDS, json_encode($this->_request_post));
curl_setopt($this->_curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_curl_handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(Tools::jsonEncode($this->_request_post)))
'Content-Length: ' . strlen(json_encode($this->_request_post)))
);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/Mailjet.Overlay.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3511,9 +3511,9 @@ public function deleteContactsList($id)
);
if ($response !== FALSE) {
return true;//($response);
} else {
throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]);
}

throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]);
}

/**
Expand Down
Loading

0 comments on commit 9c79b4b

Please sign in to comment.