Skip to content

Commit

Permalink
Fix webhook and add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Jun 17, 2024
1 parent d7c2723 commit 0a65040
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
26 changes: 21 additions & 5 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.16';
$this->version = '2.0.17';
$this->author = 'Ecomail';
$this->need_instance = 0;
$this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_];
Expand Down Expand Up @@ -729,7 +729,11 @@ public function hookActionValidateOrder(array $params): void
);
}

$this->getAPI()->createTransaction($params['order']);
$result = $this->getAPI()->createTransaction($params['order']);

if (isset($result->errors)) {
PrestaShopLogger::addLog('Ecomail failed: ' . json_encode($result), 1, null, 'Transaction', null, true);
}
}

public function hookActionCartSave(array $params): void
Expand Down Expand Up @@ -874,13 +878,21 @@ public function syncCustomers(string $listId, int $offset = 0, bool $forceHttp =
if ($offset === 0) {
$firstCustomer = array_shift($customersToImport);

$this->getAPI()->subscribeToList($listId, $firstCustomer);
$result = $this->getAPI()->subscribeToList($listId, $firstCustomer);

if (isset($result->errors)) {
PrestaShopLogger::addLog('Ecomail failed: ' . json_encode($result), 1, null, 'subscribeToList', null, true);
}
}

PrestaShopLogger::addLog('Customers processed - ready to import');

if (count($customersToImport) > 0) {
$this->getAPI()->bulkSubscribeToList($listId, $customersToImport);
$result = $this->getAPI()->bulkSubscribeToList($listId, $customersToImport);

if (isset($result->errors)) {
PrestaShopLogger::addLog('Ecomail failed: ' . json_encode($result), 1, null, 'bulkSubscribeToList', null, true);
}
}

if (count($allCustomers['customers']) === 3000) {
Expand Down Expand Up @@ -951,7 +963,11 @@ public function syncOrders(int $offset = 0, bool $forceHttp = false): void
PrestaShopLogger::addLog('Orders processed - ready to import');

if (count($ordersToImport) > 0) {
$this->getAPI()->bulkOrders($ordersToImport);
$result = $this->getAPI()->bulkOrders($ordersToImport);

if (isset($result->errors)) {
PrestaShopLogger::addLog('Ecomail failed: ' . json_encode($result), 1, null, 'bulkOrders', null, true);
}
}

if (count($allOrders['orders']) === 1000) {
Expand Down
5 changes: 3 additions & 2 deletions ecomailemailmarketing/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

require dirname(__FILE__) . '/../../config/config.inc.php';

if (!defined('_PS_VERSION_')) {
exit;
}

require dirname(__FILE__) . '/../../config/config.inc.php';

$requestJson = Tools::file_get_contents('php://input');

if ($requestJson) {
Expand Down

0 comments on commit 0a65040

Please sign in to comment.