From 8c167596bbce7e08148b4c94506711893f74c967 Mon Sep 17 00:00:00 2001 From: Lorenzo Minciotti Date: Fri, 14 Jun 2024 14:52:27 +0200 Subject: [PATCH] Added support for PrestaShop v8 --- config/common.yml | 15 ++++++++++----- sendinblueresttracker.php | 8 ++++---- src/Service/RestTracker.php | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/config/common.yml b/config/common.yml index 1fe0452..4c4fb6f 100644 --- a/config/common.yml +++ b/config/common.yml @@ -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' - - \ No newline at end of file + - '@PrestaShop\PrestaShop\Adapter\Configuration' + - '@PrestaShop\PrestaShop\Adapter\Currency\CurrencyDataProvider' + - '@Novanta\Sendinblue\Adapter\LinkAdapter' \ No newline at end of file diff --git a/sendinblueresttracker.php b/sendinblueresttracker.php index 0232890..7f2731e 100644 --- a/sendinblueresttracker.php +++ b/sendinblueresttracker.php @@ -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); } } @@ -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); } } } diff --git a/src/Service/RestTracker.php b/src/Service/RestTracker.php index e546ba4..dd97775 100644 --- a/src/Service/RestTracker.php +++ b/src/Service/RestTracker.php @@ -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; @@ -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', @@ -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; } @@ -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; } @@ -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; } @@ -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; }