Skip to content

Commit 042d199

Browse files
committed
ACP2E-1880: adapt for decimal quantity and allow several decimals on price
1 parent 8446b68 commit 042d199

File tree

1 file changed

+9
-6
lines changed
  • app/code/Magento/GoogleAnalytics/Block

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,20 @@ public function getOrdersTrackingCode()
122122
foreach ($collection as $order) {
123123
$result[] = "ga('set', 'currencyCode', '" . $order->getOrderCurrencyCode() . "');";
124124
foreach ($order->getAllVisibleItems() as $item) {
125+
$quantity = (float)$item->getQtyOrdered();
126+
$quantity = fmod($quantity, 1) !== 0.00 ? $quantity : (int)$quantity;
127+
$format = fmod($quantity, 1) !== 0.00 ? '%.2f' : '%d';
125128
$result[] = sprintf(
126129
"ga('ec:addProduct', {
127130
'id': '%s',
128131
'name': '%s',
129132
'price': %.2f,
130-
'quantity': %d
133+
'quantity': $format
131134
});",
132135
$this->escapeJsQuote($item->getSku()),
133136
$this->escapeJsQuote($item->getName()),
134-
round($item->getPrice(), 2),
135-
$item->getQtyOrdered()
137+
(float)$item->getPrice(),
138+
$quantity
136139
);
137140
}
138141

@@ -146,9 +149,9 @@ public function getOrdersTrackingCode()
146149
});",
147150
$order->getIncrementId(),
148151
$this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()),
149-
round($order->getGrandTotal(), 2),
150-
round($order->getTaxAmount(), 2),
151-
round($order->getShippingAmount(), 2)
152+
(float)$order->getGrandTotal(),
153+
(float)$order->getTaxAmount(),
154+
(float)$order->getShippingAmount(),
152155
);
153156

154157
$result[] = "ga('send', 'pageview');";

0 commit comments

Comments
 (0)