Skip to content

Commit

Permalink
Merge pull request #1419 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests
 - MAGETWO-71539: Send different base currency in Google analytics #10508
  • Loading branch information
ishakhsuvarov authored Aug 16, 2017
2 parents f2314aa + 1d74769 commit d19e900
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
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
18 changes: 10 additions & 8 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->getOrderCurrencyCode() . "');";
foreach ($order->getAllVisibleItems() as $item) {
$result[] = sprintf(
"ga('ec:addProduct', {
Expand All @@ -130,7 +131,7 @@ public function getOrdersTrackingCode()
});",
$this->escapeJs($item->getSku()),
$this->escapeJs($item->getName()),
$item->getBasePrice(),
$item->getPrice(),
$item->getQtyOrdered()
);
}
Expand All @@ -145,9 +146,9 @@ public function getOrdersTrackingCode()
});",
$order->getIncrementId(),
$this->escapeJs($this->_storeManager->getStore()->getFrontendName()),
$order->getBaseGrandTotal(),
$order->getBaseTaxAmount(),
$order->getBaseShippingAmount()
$order->getGrandTotal(),
$order->getTaxAmount(),
$order->getShippingAmount()
);

$result[] = "ga('send', 'pageview');";
Expand Down Expand Up @@ -236,17 +237,18 @@ public function getOrdersTrackingData()
$result['products'][] = [
'id' => $this->escapeJs($item->getSku()),
'name' => $this->escapeJs($item->getName()),
'price' => $item->getBasePrice(),
'price' => $item->getPrice(),
'quantity' => $item->getQtyOrdered(),
];
}
$result['orders'][] = [
'id' => $order->getIncrementId(),
'affiliation' => $this->escapeJs($this->_storeManager->getStore()->getFrontendName()),
'revenue' => $order->getBaseGrandTotal(),
'tax' => $order->getBaseTaxAmount(),
'shipping' => $order->getBaseShippingAmount(),
'revenue' => $order->getGrandTotal(),
'tax' => $order->getTaxAmount(),
'shipping' => $order->getShippingAmount(),
];
$result['currency'] = $order->getOrderCurrencyCode();
}
return $result;
}
Expand Down
13 changes: 8 additions & 5 deletions 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 @@ -202,17 +204,18 @@ protected function createOrderMock($orderItemCount = 1)
->getMock();
$orderItemMock->expects($this->once())->method('getSku')->willReturn('sku' . $i);
$orderItemMock->expects($this->once())->method('getName')->willReturn('testName' . $i);
$orderItemMock->expects($this->once())->method('getBasePrice')->willReturn($i . '.00');
$orderItemMock->expects($this->once())->method('getPrice')->willReturn($i . '.00');
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i + 1);
$orderItems[] = $orderItemMock;
}

$orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
$orderMock->expects($this->once())->method('getIncrementId')->willReturn(100);
$orderMock->expects($this->once())->method('getAllVisibleItems')->willReturn($orderItems);
$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('getGrandTotal')->willReturn(10);
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2);
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn($orderItemCount);
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->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

0 comments on commit d19e900

Please sign in to comment.