Skip to content

Commit af7e3cc

Browse files
committed
Added Include Shipping In Purchase Value option
1 parent cd5c53f commit af7e3cc

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Model/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Config
4747
* Events config
4848
*/
4949
public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/purchase/tax_enabled';
50+
public const XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED = 'mfgoogletagmanager/events/purchase/shipping_enabled';
5051

5152
/**
5253
* Customer data protection regulation config
@@ -190,6 +191,15 @@ public function isPurchaseTaxEnabled(string $storeId = null): bool
190191
return (bool)$this->getConfig(self::XML_PATH_EVENTS_PURCHASE_TAX_ENABLED, $storeId);
191192
}
192193

194+
/**
195+
* @param string|null $storeId
196+
* @return bool
197+
*/
198+
public function isPurchaseShippingEnabled(string $storeId = null): bool
199+
{
200+
return (bool)$this->getConfig(self::XML_PATH_EVENTS_PURCHASE_SHIPPING_ENABLED, $storeId);
201+
}
202+
193203
/**
194204
* Retrieve Magento product attribute
195205
*

Model/DataLayer/Purchase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ protected function getOrderValue($order): float
9090
$orderValue -= $order->getTaxAmount();
9191
}
9292

93+
if (!$this->config->isPurchaseShippingEnabled()) {
94+
$orderValue -= $order->getShippingAmount();
95+
}
96+
9397
return $this->formatPrice($orderValue);
9498
}
9599
}

etc/adminhtml/system.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,14 @@ To create a new secret, navigate in the
350350
<label>Events</label>
351351
<group id="purchase" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
352352
<label>Purchase</label>
353+
<field id="shipping_enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
354+
<label>Include Shipping In Purchase Value</label>
355+
<comment>If enabled, shipping amount will be included into purchase value (the monetary value of the event).</comment>
356+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
357+
</field>
353358
<field id="tax_enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
354-
<label>Include Tax</label>
355-
<comment>If enabled, tax will be sent to Google Tag Manager and GA4.</comment>
359+
<label>Include Tax In Purchase Value</label>
360+
<comment>If enabled, TAX price amount will be included into purchase value (the monetary value of the event).</comment>
356361
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
357362
</field>
358363
</group>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
</attributes>
6565
<events>
6666
<purchase>
67+
<shipping_enabled>1</shipping_enabled>
6768
<tax_enabled>1</tax_enabled>
6869
</purchase>
6970
</events>

0 commit comments

Comments
 (0)