diff --git a/.gitignore b/.gitignore index bae558e0e5b9a..94c3bf76a2bd1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /.metadata /.project /.settings +/.vscode atlassian* /nbproject /robots.txt diff --git a/app/code/Magento/GoogleAnalytics/Block/Ga.php b/app/code/Magento/GoogleAnalytics/Block/Ga.php index ed918a5348b37..e3621b6afb3b9 100644 --- a/app/code/Magento/GoogleAnalytics/Block/Ga.php +++ b/app/code/Magento/GoogleAnalytics/Block/Ga.php @@ -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', { @@ -130,7 +131,7 @@ public function getOrdersTrackingCode() });", $this->escapeJs($item->getSku()), $this->escapeJs($item->getName()), - $item->getBasePrice(), + $item->getPrice(), $item->getQtyOrdered() ); } @@ -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');"; @@ -232,17 +233,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; } diff --git a/app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php b/app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php index 4e1030c0f4dcd..642049f6d15f7 100644 --- a/app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php +++ b/app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php @@ -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', @@ -165,7 +166,8 @@ public function testOrderTrackingData() 'price' => 0.00, 'quantity' => 1 ] - ] + ], + 'currency' => 'USD' ]; $this->gaBlock->setOrderIds([1, 2]); @@ -202,7 +204,7 @@ 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; } @@ -210,9 +212,10 @@ protected function createOrderMock($orderItemCount = 1) $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; } diff --git a/app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js b/app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js index ab00f81410287..42f2745060026 100644 --- a/app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js +++ b/app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js @@ -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) {