Skip to content

Commit 3a74dfb

Browse files
committed
10304-send-revenue-without-taxes
1 parent 084180c commit 3a74dfb

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Model/Config.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class Config
4343
public const XML_PATH_ATTRIBUTES_BRAND = 'mfgoogletagmanager/attributes/brand';
4444
public const XML_PATH_ATTRIBUTES_CATEGORIES = 'mfgoogletagmanager/attributes/categories';
4545

46+
/**
47+
* Events config
48+
*/
49+
public const XML_PATH_EVENTS_PURCHASE_TAX_ENABLED = 'mfgoogletagmanager/events/purchase/tax_enabled';
50+
4651
/**
4752
* Customer data protection regulation config
4853
*/
@@ -176,6 +181,15 @@ public function getMeasurementId(string $storeId = null): string
176181
return trim((string)$this->getConfig(self::XML_PATH_ANALYTICS_MEASUREMENT_ID, $storeId));
177182
}
178183

184+
/**
185+
* @param string|null $storeId
186+
* @return bool
187+
*/
188+
public function isPurchaseTaxEnabled(string $storeId = null): bool
189+
{
190+
return (bool)$this->getConfig(self::XML_PATH_EVENTS_PURCHASE_TAX_ENABLED, $storeId);
191+
}
192+
179193
/**
180194
* Retrieve Magento product attribute
181195
*

Model/DataLayer/Purchase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,18 @@ public function get(Order $order, string $requester = ''): array
7777

7878
return [];
7979
}
80+
81+
/**
82+
* @param array $data
83+
* @return array
84+
*/
85+
protected function eventWrap(array $data): array
86+
{
87+
$data = parent::eventWrap($data);
88+
if (!$this->config->isPurchaseTaxEnabled()) {
89+
unset($data['ecommerce']['tax']);
90+
}
91+
92+
return $data;
93+
}
8094
}

etc/adminhtml/system.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,17 @@ To create a new secret, navigate in the
346346
<comment><![CDATA[<strong class="colorRed">Warning!</strong> Enabling this option may cause the performance impact.]]></comment>
347347
</field>
348348
</group>
349+
<group id="events" translate="label" type="text" sortOrder="62" showInDefault="1" showInWebsite="1" showInStore="1">
350+
<label>Events</label>
351+
<group id="purchase" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
352+
<label>Purchase</label>
353+
<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.</comment>
356+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
357+
</field>
358+
</group>
359+
</group>
349360
<group id="page_speed_optimization" translate="label" type="text" sortOrder="65" showInDefault="1" showInWebsite="1" showInStore="1">
350361
<label>Page Speed Optimization</label>
351362
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">

etc/config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<brand/>
6363
<categories/>
6464
</attributes>
65+
<events>
66+
<purchase>
67+
<tax_enabled>1</tax_enabled>
68+
</purchase>
69+
</events>
6570
<page_speed_optimization>
6671
<enabled>0</enabled>
6772
</page_speed_optimization>

0 commit comments

Comments
 (0)