Skip to content

Commit 1f23f4a

Browse files
committed
ACP2E-1880: fix static and unit tests errors
1 parent 5931901 commit 1f23f4a

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function getPageName()
8282
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set
8383
* @link https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#gaObjectMethods
8484
* @deprecated 100.2.0 please use getPageTrackingData method
85+
* @see getPageTrackingData method
8586
*/
8687
public function getPageTrackingCode($accountId)
8788
{
@@ -103,6 +104,7 @@ public function getPageTrackingCode($accountId)
103104
*
104105
* @return string|void
105106
* @deprecated 100.2.0 please use getOrdersTrackingData method
107+
* @see getOrdersTrackingData method
106108
*/
107109
public function getOrdersTrackingCode()
108110
{
@@ -124,12 +126,12 @@ public function getOrdersTrackingCode()
124126
"ga('ec:addProduct', {
125127
'id': '%s',
126128
'name': '%s',
127-
'price': '%f',
129+
'price': %.2f,
128130
'quantity': %d
129131
});",
130132
$this->escapeJsQuote($item->getSku()),
131133
$this->escapeJsQuote($item->getName()),
132-
$item->getPrice(),
134+
round($item->getPrice(), 2),
133135
$item->getQtyOrdered()
134136
);
135137
}
@@ -138,15 +140,15 @@ public function getOrdersTrackingCode()
138140
"ga('ec:setAction', 'purchase', {
139141
'id': '%s',
140142
'affiliation': '%s',
141-
'revenue': '%f',
142-
'tax': '%f',
143-
'shipping': '%f'
143+
'revenue': %.2f,
144+
'tax': %.2f,
145+
'shipping': %.2f
144146
});",
145147
$order->getIncrementId(),
146148
$this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
147-
$order->getGrandTotal(),
148-
$order->getTaxAmount(),
149-
$order->getShippingAmount()
149+
round($order->getGrandTotal(), 2),
150+
round($order->getTaxAmount(), 2),
151+
round($order->getShippingAmount(), 2)
150152
);
151153

152154
$result[] = "ga('send', 'pageview');";
@@ -235,16 +237,16 @@ public function getOrdersTrackingData()
235237
$result['products'][] = [
236238
'id' => $this->escapeJsQuote($item->getSku()),
237239
'name' => $this->escapeJsQuote($item->getName()),
238-
'price' => (float)$item->getPrice(),
240+
'price' => round((float)$item->getPrice(), 2),
239241
'quantity' => (int)$item->getQtyOrdered(),
240242
];
241243
}
242244
$result['orders'][] = [
243245
'id' => $order->getIncrementId(),
244246
'affiliation' => $this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
245-
'revenue' => (float)$order->getGrandTotal(),
246-
'tax' => (float)$order->getTaxAmount(),
247-
'shipping' => (float)$order->getShippingAmount(),
247+
'revenue' => round((float)$order->getGrandTotal(), 2),
248+
'tax' => round((float)$order->getTaxAmount(), 2),
249+
'shipping' => round((float)$order->getShippingAmount(), 2)
248250
];
249251
$result['currency'] = $order->getOrderCurrencyCode();
250252
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ public function testOrderTrackingCode()
115115
ga('ec:addProduct', {
116116
'id': 'sku0',
117117
'name': 'testName0',
118-
'price': '0.00',
118+
'price': 0.00,
119119
'quantity': 1
120120
});
121121
ga('ec:setAction', 'purchase', {
122122
'id': '100',
123123
'affiliation': 'test',
124-
'revenue': '10',
125-
'tax': '2',
126-
'shipping': '1'
124+
'revenue': 10.00,
125+
'tax': 2.00,
126+
'shipping': 1.00
127127
});
128128
ga('send', 'pageview');";
129129

@@ -163,8 +163,8 @@ public function testOrderTrackingData()
163163
[
164164
'id' => 100,
165165
'affiliation' => 'test',
166-
'revenue' => 10,
167-
'tax' => 2,
166+
'revenue' => 10.00,
167+
'tax' => 2.00,
168168
'shipping' => 1
169169
]
170170
],
@@ -213,7 +213,7 @@ protected function createOrderMock($orderItemCount = 1)
213213
->getMockForAbstractClass();
214214
$orderItemMock->expects($this->once())->method('getSku')->willReturn('sku' . $i);
215215
$orderItemMock->expects($this->once())->method('getName')->willReturn('testName' . $i);
216-
$orderItemMock->expects($this->once())->method('getPrice')->willReturn($i . '.00');
216+
$orderItemMock->expects($this->once())->method('getPrice')->willReturn(round((float)($i . '.0000'), 2));
217217
$orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn($i + 1);
218218
$orderItems[] = $orderItemMock;
219219
}
@@ -223,9 +223,9 @@ protected function createOrderMock($orderItemCount = 1)
223223
->getMock();
224224
$orderMock->expects($this->once())->method('getIncrementId')->willReturn(100);
225225
$orderMock->expects($this->once())->method('getAllVisibleItems')->willReturn($orderItems);
226-
$orderMock->expects($this->once())->method('getGrandTotal')->willReturn(10);
227-
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2);
228-
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn($orderItemCount);
226+
$orderMock->expects($this->once())->method('getGrandTotal')->willReturn(10.00);
227+
$orderMock->expects($this->once())->method('getTaxAmount')->willReturn(2.00);
228+
$orderMock->expects($this->once())->method('getShippingAmount')->willReturn(round((float)$orderItemCount, 2));
229229
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn('USD');
230230
return $orderMock;
231231
}

0 commit comments

Comments
 (0)