Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.metadata
/.project
/.settings
/.vscode
atlassian*
/nbproject
/robots.txt
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function getOrdersTrackingCode()
$result[] = "ga('require', 'ec', 'ec.js');";

foreach ($collection as $order) {
$result[] = "ga('set', 'currencyCode', '" . $order->getBaseCurrencyCode() . "');";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like BaseCurrencyCode is not exactly the currency code needed here. With the multi-store setup it will always be the same, regardless of different display currency.

foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf(
"ga('ec:addProduct', {
Expand Down Expand Up @@ -243,6 +244,7 @@ public function getOrdersTrackingData()
'tax' => $order->getBaseTaxAmount(),
'shipping' => $order->getBaseShippingAmount(),
];
$result['currency'] = $order->getBaseCurrencyCode();
}
return $result;
}
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function testOrderTrackingCode()
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);

$expectedCode = "ga('require', 'ec', 'ec.js');
ga('set', 'currencyCode', 'USD');
ga('ec:addProduct', {
'id': 'sku0',
'name': 'testName0',
Expand Down Expand Up @@ -165,7 +166,8 @@ public function testOrderTrackingData()
'price' => 0.00,
'quantity' => 1
]
]
],
'currency' => 'USD'
];

$this->gaBlock->setOrderIds([1, 2]);
Expand Down Expand Up @@ -213,6 +215,7 @@ protected function createOrderMock($orderItemCount = 1)
$orderMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(10);
$orderMock->expects($this->once())->method('getBaseTaxAmount')->willReturn(2);
$orderMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($orderItemCount);
$orderMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
return $orderMock;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ define([
if (config.ordersTrackingData) {
ga('require', 'ec', 'ec.js');

ga('set', 'currencyCode', config.ordersTrackingData.currency);

// Collect product data for GA
if (config.ordersTrackingData.products) {
$.each(config.ordersTrackingData.products, function (index, value) {
Expand Down