From c91a1f5e34c2d22b69a7d5a51b6ff7af34168597 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 30 Jul 2026 14:00:01 +0000 Subject: [PATCH] Add shipping method and base currency data to order_created webhook AdPage calculates per-order profit (COGS, carrier rate, payment fees) from the order_created payload. Two things were missing to do that exactly: - the chosen shipping method, so the real carrier rate can be applied - shipping/order totals excl. tax and in the store base currency, so multi-currency shops don't mix currencies in the profit calculation Adds to ecommerce: shipping_method, shipping_method_code, shipping_excl_tax, base_shipping_excl_tax, base_value, base_tax, base_currency and payment_type. Purely additive - shipping, value, tax, items, transaction_id and all other existing keys keep their current name, meaning and value so live tracking implementations are unaffected. Resolution is wrapped in a try/catch so a failure here can never break the webhook. Bumps the package version to 1.7.0 so the plugin_version in the payload tells AdPage whether the new fields are available. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01FtDTszbhPXRNU49GjSuiPD --- DataLayer/Event/PurchaseWebhookEvent.php | 18 ++++++++++++++++++ composer.json | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index a424c0e7..42e8a25b 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -102,6 +102,24 @@ public function purchase(OrderInterface $order) ] ]; + // Additional shipping, base currency and payment data used by AdPage to + // calculate the actual profit (COGS, carrier rate, payment fees) per order. + // Purely additive: existing keys keep their name, meaning and value. + try { + $data['ecommerce'] += [ + 'shipping_method' => $order->getShippingDescription() ?? '', + 'shipping_method_code' => $order->getShippingMethod() ?? '', + 'shipping_excl_tax' => $this->priceFormatter->format((float)$order->getShippingAmount()), + 'base_shipping_excl_tax' => $this->priceFormatter->format((float)$order->getBaseShippingAmount()), + 'base_value' => $this->priceFormatter->format((float)$order->getBaseGrandTotal()), + 'base_tax' => $this->priceFormatter->format((float)$order->getBaseTaxAmount()), + 'base_currency' => $order->getBaseCurrencyCode() ?? '', + 'payment_type' => $order->getPayment() ? (string)$order->getPayment()->getMethod() : '' + ]; + } catch (\Exception $e) { + $this->debugger->debug('PurchaseWebhookEvent::purchase(): could not resolve shipping/base data: ' . $e->getMessage()); + } + try { $data['user_data'] = [ "customer_id" => $order->getCustomerId() ?? '', diff --git a/composer.json b/composer.json index e0eb4be4..21b4288c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tagginggroup/gtm", - "version": "1.6.0", + "version": "1.7.0", "license": "OSL-3.0", "type": "magento2-module", "description": "AdPage tagging integration for Magento 2",