diff --git a/Observer/OrderCreateWebhook.php b/Observer/OrderCreateWebhook.php index 3f29ba75f4c363e83678127831c854b5535a817f..010bec58a5c95ac532a9fe8a411eb88f3175279a 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 6d6b43ab5ed0c9aef4898fd58d98c9eb3f74b592..01b769506d701c5ff7f621936d9569a8061665d7 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; } }