diff --git a/Config/Config.php b/Config/Config.php
index 307e07d1..9cfc4780 100644
--- a/Config/Config.php
+++ b/Config/Config.php
@@ -229,6 +229,16 @@ public function getOrderStatesForPurchaseEvent(): array
return explode(',', (string)$this->getModuleConfigValue('order_states_for_purchase_event'));
}
+ /**
+ * Get the maximum transaction value threshold
+ *
+ * @return float
+ */
+ public function getMaxTransactionValue(): float
+ {
+ return (float)$this->getModuleConfigValue('max_transaction_value', 0);
+ }
+
/**
* Return a configuration value
*
diff --git a/DataLayer/Event/Purchase.php b/DataLayer/Event/Purchase.php
index 7cf489a9..da20c839 100644
--- a/DataLayer/Event/Purchase.php
+++ b/DataLayer/Event/Purchase.php
@@ -49,13 +49,17 @@ public function get(): array
return [];
}
+ $orderValue = $this->orderTotals->getValueTotal($order);
+ $valueAdjusted = $this->calculateValueAdjusted($orderValue);
+
return [
'event' => 'purchase',
'ecommerce' => [
'transaction_id' => $order->getIncrementId(),
'affiliation' => $this->config->getStoreName(),
'currency' => $order->getOrderCurrencyCode(),
- 'value' => $this->priceFormatter->format($this->orderTotals->getValueTotal($order)),
+ 'value' => $this->priceFormatter->format($orderValue),
+ 'value_adjusted' => $this->priceFormatter->format($valueAdjusted),
'tax' => $this->priceFormatter->format((float)$order->getTaxAmount()),
'shipping' => $this->priceFormatter->format($this->orderTotals->getShippingTotal($order)),
'coupon' => $order->getCouponCode(),
@@ -107,4 +111,21 @@ private function getDefaultOrderStates(): array
Order::STATE_COMPLETE,
];
}
+
+ /**
+ * Calculate the adjusted transaction value based on the configured maximum
+ *
+ * @param float $orderValue
+ * @return float
+ */
+ private function calculateValueAdjusted(float $orderValue): float
+ {
+ $maxTransactionValue = $this->config->getMaxTransactionValue();
+
+ if ($maxTransactionValue <= 0) {
+ return $orderValue;
+ }
+
+ return min($orderValue, $maxTransactionValue);
+ }
}
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 076a1e5b..45afd32d 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -135,6 +135,14 @@
1
+
+
+ Maximum transaction value for purchase events. When an order value exceeds this amount, the transaction_value_adjusted field will be capped at this value. Leave empty or 0 to disable.
+ validate-number validate-zero-or-greater
+
+ 1
+
+
diff --git a/etc/config.xml b/etc/config.xml
index 5c6d9f0d..97c8ac4c 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -17,6 +17,7 @@
0
new,payment_review,pending_payment,holded,processing,complete
+ 0