Skip to content

Commit

Permalink
Added support for PrestaShop v8
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Minciotti authored and Lorenzo Minciotti committed Jun 14, 2024
1 parent 705a0f9 commit 8c16759
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
15 changes: 10 additions & 5 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ services:
public: true

novanta.sendinblue.adapter.link:
alias: 'Novanta\Sendinblue\Adapter\LinkAdapter'

Novanta\Sendinblue\Adapter\LinkAdapter:
class: 'Novanta\Sendinblue\Adapter\LinkAdapter'


novanta.sendinblue.resttracker:
alias: 'Novanta\Sendinblue\Service\RestTracker'

Novanta\Sendinblue\Service\RestTracker:
class: 'Novanta\Sendinblue\Service\RestTracker'
arguments:
- '@prestashop.adapter.legacy.configuration'
- '@prestashop.adapter.data_provider.currency'
- '@novanta.sendinblue.adapter.link'


- '@PrestaShop\PrestaShop\Adapter\Configuration'
- '@PrestaShop\PrestaShop\Adapter\Currency\CurrencyDataProvider'
- '@Novanta\Sendinblue\Adapter\LinkAdapter'
8 changes: 4 additions & 4 deletions sendinblueresttracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function hookActionOrderHistoryAddAfter(array $params)
$order = new Order($order_history->id_order);
if ($order) {
$customer = $order->getCustomer();
$eventdata = $this->get('novanta.sendinblue.resttracker')->getOrderEventData($order);
$this->get('novanta.sendinblue.resttracker')->trackEvent($customer, 'order_status_update', $eventdata);
$eventdata = $this->get('Novanta\Sendinblue\Service\RestTracker')->getOrderEventData($order);
$this->get('Novanta\Sendinblue\Service\RestTracker')->trackEvent($customer, 'order_status_update', $eventdata);
}
}

Expand All @@ -74,8 +74,8 @@ public function hookDisplayHeader(array $params)
if ($this->isFirstCheckoutStep()) {
$customer = $this->context->customer;

$eventdata = $this->get('novanta.sendinblue.resttracker')->getCartEventData($this->context->cart);
$this->get('novanta.sendinblue.resttracker')->trackEvent($customer, 'initiate_checkout', $eventdata);
$eventdata = $this->get('Novanta\Sendinblue\Service\RestTracker')->getCartEventData($this->context->cart);
$this->get('Novanta\Sendinblue\Service\RestTracker')->trackEvent($customer, 'initiate_checkout', $eventdata);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Service/RestTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use GuzzleHttp\Exception\ClientException;
use Novanta\Sendinblue\Adapter\LinkAdapter;
use Order;
use PrestaShop\PrestaShop\Adapter\Entity\PrestaShopLogger;

use PrestaShop\PrestaShop\Adapter\Presenter\Cart\CartPresenter;
use PrestaShop\PrestaShop\Core\ConfigurationInterface;
use PrestaShop\PrestaShop\Core\Currency\CurrencyDataProviderInterface;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function __construct(
$this->automation_key = $this->configuration->get('Sendin_marketingAutomationKey');

$this->client = new Client([
'base_url' => 'https://in-automate.brevo.com/api/v2/',
'base_uri' => 'https://in-automate.brevo.com/api/v2/',
'defaults' => [
'headers' => [
'Accept' => 'application/json',
Expand All @@ -83,8 +83,8 @@ public function identify(\Customer $customer)
]);

return $response->getStatusCode() == 204;
} catch (ClientException $e) {
PrestaShopLogger::addLog(sprintf('Brevo - Unable to identify user, API call fail - %s', $e->getMessage()), 3, $e->getCode());
} catch (\Exception $e) {
\PrestaShopLogger::addLog(sprintf('Brevo - Unable to identify user, API call fail - %s', $e->getMessage()), 3, $e->getCode());

return false;
}
Expand All @@ -106,8 +106,8 @@ public function trackEvent(\Customer $customer, $event, $eventdata = null)
]);

return $response->getStatusCode() == 204;
} catch (ClientException $e) {
PrestaShopLogger::addLog(sprintf('Brevo - Unable to track event %s: API call fail - %s', $event, $e->getMessage()), 3, $e->getCode());
} catch (\Exception $e) {
\PrestaShopLogger::addLog(sprintf('Brevo - Unable to track event %s: API call fail - %s', $event, $e->getMessage()), 3, $e->getCode());

return false;
}
Expand All @@ -128,8 +128,8 @@ public function trackLink(\Customer $customer, $link)
]);

return $response->getStatusCode() == 204;
} catch (ClientException $e) {
PrestaShopLogger::addLog(sprintf('Brevo - Unable to track link %s: API call fail - %s', $link, $e->getMessage()), 3, $e->getCode());
} catch (\Exception $e) {
\PrestaShopLogger::addLog(sprintf('Brevo - Unable to track link %s: API call fail - %s', $link, $e->getMessage()), 3, $e->getCode());

return false;
}
Expand All @@ -150,8 +150,8 @@ public function trackPage(\Customer $customer, $page)
]);

return $response->getStatusCode() == 204;
} catch (ClientException $e) {
PrestaShopLogger::addLog(sprintf('Brevo - Unable to track page %s: API call fail - %s', $page, $e->getMessage()), 3, $e->getCode());
} catch (\Exception $e) {
\PrestaShopLogger::addLog(sprintf('Brevo - Unable to track page %s: API call fail - %s', $page, $e->getMessage()), 3, $e->getCode());

return false;
}
Expand Down

0 comments on commit 8c16759

Please sign in to comment.