From 524ce233f070724f1c97542e4baae10f786a19ad Mon Sep 17 00:00:00 2001
From: "@ChristelLoftus" <christel@bob.co.za>
Date: Thu, 29 Aug 2024 08:14:04 +0200
Subject: [PATCH] Clean identifier url

---
 Observer/OrderCreateWebhook.php | 18 +++++++++++++++++-
 Observer/OrderUpdateWebhook.php | 18 +++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Observer/OrderCreateWebhook.php b/Observer/OrderCreateWebhook.php
index 3f29ba7..010bec5 100644
--- a/Observer/OrderCreateWebhook.php
+++ b/Observer/OrderCreateWebhook.php
@@ -110,6 +110,22 @@ class OrderCreateWebhook implements ObserverInterface
 
     private function getStoreUrl(): string
     {
-        return $this->storeManager->getStore()->getBaseUrl();
+        $url = $this->storeManager->getStore()->getBaseUrl();
+
+        // Remove protocol (http:// or https://)
+        $host = preg_replace('#^https?://#', '', $url);
+
+        // Ensure $host is a string before using it in explode
+        $host = $host ?? '';
+
+        // Remove everything after the host (e.g., paths, query strings)
+        $host = explode('/', $host)[0];
+
+        // If the host starts with 'www.', remove it
+        if (strpos($host, 'www.') === 0) {
+            $host = substr($host, 4);
+        }
+
+        return $host;
     }
 }
diff --git a/Observer/OrderUpdateWebhook.php b/Observer/OrderUpdateWebhook.php
index 6d6b43a..01b7695 100644
--- a/Observer/OrderUpdateWebhook.php
+++ b/Observer/OrderUpdateWebhook.php
@@ -109,6 +109,22 @@ class OrderUpdateWebhook implements ObserverInterface
 
     private function getStoreUrl(): string
     {
-        return $this->storeManager->getStore()->getBaseUrl();
+        $url = $this->storeManager->getStore()->getBaseUrl();
+
+        // Remove protocol (http:// or https://)
+        $host = preg_replace('#^https?://#', '', $url);
+
+        // Ensure $host is a string before using it in explode
+        $host = $host ?? '';
+
+        // Remove everything after the host (e.g., paths, query strings)
+        $host = explode('/', $host)[0];
+
+        // If the host starts with 'www.', remove it
+        if (strpos($host, 'www.') === 0) {
+            $host = substr($host, 4);
+        }
+
+        return $host;
     }
 }
-- 
GitLab