Skip to content

Commit 43352eb

Browse files
committed
Different approach as Google analytics snippet on checkout success doesn't return default currency as base currency
1 parent 980582e commit 43352eb

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

app/code/Magento/GoogleAnalytics/Block/Ga.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function getOrdersTrackingCode()
120120
$result[] = "ga('require', 'ec', 'ec.js');";
121121

122122
foreach ($collection as $order) {
123-
$result[] = "ga('set', 'currencyCode', '" . $order->getBaseCurrencyCode() . "');";
123+
$result[] = "ga('set', 'currencyCode', '" . $order->getOrderCurrencyCode() . "');";
124124
foreach ($order->getAllVisibleItems() as $item) {
125125
$result[] = sprintf(
126126
"ga('ec:addProduct', {
@@ -131,7 +131,7 @@ public function getOrdersTrackingCode()
131131
});",
132132
$this->escapeJs($item->getSku()),
133133
$this->escapeJs($item->getName()),
134-
$item->getBasePrice(),
134+
$item->getPrice(),
135135
$item->getQtyOrdered()
136136
);
137137
}
@@ -146,9 +146,9 @@ public function getOrdersTrackingCode()
146146
});",
147147
$order->getIncrementId(),
148148
$this->escapeJs($this->_storeManager->getStore()->getFrontendName()),
149-
$order->getBaseGrandTotal(),
150-
$order->getBaseTaxAmount(),
151-
$order->getBaseShippingAmount()
149+
$order->getGrandTotal(),
150+
$order->getTaxAmount(),
151+
$order->getShippingAmount()
152152
);
153153

154154
$result[] = "ga('send', 'pageview');";
@@ -233,18 +233,18 @@ public function getOrdersTrackingData()
233233
$result['products'][] = [
234234
'id' => $this->escapeJs($item->getSku()),
235235
'name' => $this->escapeJs($item->getName()),
236-
'price' => $item->getBasePrice(),
236+
'price' => $item->getPrice(),
237237
'quantity' => $item->getQtyOrdered(),
238238
];
239239
}
240240
$result['orders'][] = [
241241
'id' => $order->getIncrementId(),
242242
'affiliation' => $this->escapeJs($this->_storeManager->getStore()->getFrontendName()),
243-
'revenue' => $order->getBaseGrandTotal(),
244-
'tax' => $order->getBaseTaxAmount(),
245-
'shipping' => $order->getBaseShippingAmount(),
243+
'revenue' => $order->getGrandTotal(),
244+
'tax' => $order->getTaxAmount(),
245+
'shipping' => $order->getShippingAmount(),
246246
];
247-
$result['currency'] = $order->getBaseCurrencyCode();
247+
$result['currency'] = $order->getOrderCurrencyCode();
248248
}
249249
return $result;
250250
}

app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,18 @@ protected function createOrderMock($orderItemCount = 1)
204204
->getMock();
205205
$orderItemMock->expects($this->once())->method('getSku')->willReturn('sku' . $i);
206206
$orderItemMock->expects($this->once())->method('getName')->willReturn('testName' . $i);
207-
$orderItemMock->expects($this->once())->method('getBasePrice')->willReturn($i . '.00');
207+
$orderItemMock->expects($this->once())->method('getPrice')->willReturn($i . '.00');
208208
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i + 1);
209209
$orderItems[] = $orderItemMock;
210210
}
211211

212212
$orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
213213
$orderMock->expects($this->once())->method('getIncrementId')->willReturn(100);
214214
$orderMock->expects($this->once())->method('getAllVisibleItems')->willReturn($orderItems);
215-
$orderMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(10);
216-
$orderMock->expects($this->once())->method('getBaseTaxAmount')->willReturn(2);
217-
$orderMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($orderItemCount);
218-
$orderMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
215+
$orderMock->expects($this->once())->method('getGrandTotal')->willReturn(10);
216+
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2);
217+
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn($orderItemCount);
218+
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn('USD');
219219
return $orderMock;
220220
}
221221

0 commit comments

Comments
 (0)