Skip to content

Commit b856555

Browse files
committed
Fixed merge conflicts
2 parents 77db871 + 677b032 commit b856555

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

Config/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ public function getMaxTransactionValue(): float
239239
return (float)$this->getModuleConfigValue('max_transaction_value', 0);
240240
}
241241

242+
/**
243+
* Check whether to use base currency for purchase data
244+
*
245+
* @return bool
246+
*/
247+
public function useBaseCurrency(): bool
248+
{
249+
return (bool)$this->getModuleConfigValue('use_base_currency', false);
250+
}
251+
242252
/**
243253
* Return a configuration value
244254
*

DataLayer/Event/Purchase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,21 @@ public function get(): array
5252
$orderValue = $this->orderTotals->getValueTotal($order);
5353
$valueAdjusted = $this->calculateValueAdjusted($orderValue);
5454

55+
$currencyCode = $this->config->useBaseCurrency()
56+
? $order->getBaseCurrencyCode()
57+
: $order->getOrderCurrencyCode();
58+
59+
$taxAmount = $this->config->useBaseCurrency()
60+
? (float)$order->getBaseTaxAmount()
61+
: (float)$order->getTaxAmount();
62+
5563
return [
5664
'event' => 'purchase',
5765
'ecommerce' => [
5866
'transaction_id' => $order->getIncrementId(),
5967
'affiliation' => $this->config->getStoreName(),
68+
'currency' => $currencyCode,
69+
'tax' => $this->priceFormatter->format($taxAmount),
6070
'currency' => $order->getOrderCurrencyCode(),
6171
'value' => $this->priceFormatter->format($orderValue),
6272
'value_adjusted' => $this->priceFormatter->format($valueAdjusted),

Util/OrderTotals.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,32 @@
44
namespace Yireo\GoogleTagManager2\Util;
55

66
use Magento\Sales\Api\Data\OrderInterface;
7+
use Yireo\GoogleTagManager2\Config\Config;
78

89
class OrderTotals
910
{
11+
private Config $config;
12+
13+
public function __construct(Config $config)
14+
{
15+
$this->config = $config;
16+
}
17+
1018
public function getValueTotal(OrderInterface $order): float
1119
{
20+
if ($this->config->useBaseCurrency()) {
21+
return (float)$order->getBaseSubtotal() - abs((float)$order->getBaseDiscountAmount());
22+
}
23+
1224
return (float)$order->getSubtotal() - abs((float)$order->getDiscountAmount());
1325
}
1426

1527
public function getShippingTotal(OrderInterface $order): float
1628
{
29+
if ($this->config->useBaseCurrency()) {
30+
return (float)$order->getBaseShippingAmount() - (float)$order->getBaseShippingDiscountAmount();
31+
}
32+
1733
return (float)$order->getShippingAmount() - (float)$order->getShippingDiscountAmount();
1834
}
1935
}

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@
143143
<field id="enabled">1</field>
144144
</depends>
145145
</field>
146+
<field id="use_base_currency" type="select" translate="label" sortOrder="33" showInDefault="1" showInWebsite="1" showInStore="1">
147+
<label>Send Quote and Purchase data in base currency</label>
148+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
149+
<comment>If enabled, purchase data will be sent in base currency. If disabled, purchase data will be sent in store currency.</comment>
150+
<depends>
151+
<field id="enabled">1</field>
152+
</depends>
153+
</field>
146154
</group>
147155
</section>
148156
</system>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<serverside_gtm_url/>
1919
<order_states_for_purchase_event>new,payment_review,pending_payment,holded,processing,complete</order_states_for_purchase_event>
2020
<max_transaction_value>0</max_transaction_value>
21+
<use_base_currency>0</use_base_currency>
2122
</settings>
2223
</googletagmanager2>
2324
</default>

0 commit comments

Comments
 (0)