diff options
author | Matthieu Aubry <matt@piwik.org> | 2014-11-07 09:14:16 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2014-11-07 09:14:16 +0300 |
commit | 4ab8054b8bdd3f8a1f831b0d1a25ec8c6c754563 (patch) | |
tree | 81500cac0ddeec857cbf44c02c507ef0efbba453 /libs/PiwikTracker/PiwikTracker.php | |
parent | 34d0b74bb147290b7f09e09ddb0551d1bb80c517 (diff) | |
parent | 72163b22570fff1f275e992f0740e8c13ecb323d (diff) |
Merge pull request #6610 from piwik/64352.9.0-b7
Fix wrong database values when float representation is not set to English standard
Diffstat (limited to 'libs/PiwikTracker/PiwikTracker.php')
-rw-r--r-- | libs/PiwikTracker/PiwikTracker.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/libs/PiwikTracker/PiwikTracker.php b/libs/PiwikTracker/PiwikTracker.php index 051cb74745..39eb82b6bd 100644 --- a/libs/PiwikTracker/PiwikTracker.php +++ b/libs/PiwikTracker/PiwikTracker.php @@ -646,6 +646,9 @@ class PiwikTracker if (empty($sku)) { throw new Exception("You must specify a SKU for the Ecommerce item"); } + + $price = $this->forceDotAsSeparatorForDecimalPoint($price); + $this->ecommerceItems[$sku] = array($sku, $name, $category, $price, $quantity); } @@ -747,7 +750,9 @@ class PiwikTracker $this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_CATEGORY] = array('_pkc', $category); if (!empty($price)) { - $this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_PRICE] = array('_pkp', (float)$price); + $price = (float) $price; + $price = $this->forceDotAsSeparatorForDecimalPoint($price); + $this->pageCustomVar[self::CVAR_INDEX_ECOMMERCE_ITEM_PRICE] = array('_pkp', $price); } // On a category page, do not record "Product name not defined" @@ -764,6 +769,22 @@ class PiwikTracker } /** + * Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435 + * If for instance a German locale is used it would be a comma otherwise. + * + * @param float|string $value + * @return string + */ + private function forceDotAsSeparatorForDecimalPoint($value) + { + if (null === $value || false === $value) { + return $value; + } + + return str_replace(',', '.', $value); + } + + /** * Returns URL used to track Ecommerce Cart updates * Calling this function will reinitializes the property ecommerceItems to empty array * so items will have to be added again via addEcommerceItem() @@ -807,18 +828,23 @@ class PiwikTracker $url = $this->getRequest($this->idSite); $url .= '&idgoal=0'; if (!empty($grandTotal)) { + $grandTotal = $this->forceDotAsSeparatorForDecimalPoint($grandTotal); $url .= '&revenue=' . $grandTotal; } if (!empty($subTotal)) { + $subTotal = $this->forceDotAsSeparatorForDecimalPoint($subTotal); $url .= '&ec_st=' . $subTotal; } if (!empty($tax)) { + $tax = $this->forceDotAsSeparatorForDecimalPoint($tax); $url .= '&ec_tx=' . $tax; } if (!empty($shipping)) { + $shipping = $this->forceDotAsSeparatorForDecimalPoint($shipping); $url .= '&ec_sh=' . $shipping; } if (!empty($discount)) { + $discount = $this->forceDotAsSeparatorForDecimalPoint($discount); $url .= '&ec_dt=' . $discount; } if (!empty($this->ecommerceItems)) { @@ -876,7 +902,8 @@ class PiwikTracker $url .= '&e_n=' . urlencode($name); } if(strlen($value) > 0) { - $url .= '&e_v=' . $value; + $value = $this->forceDotAsSeparatorForDecimalPoint($value); + $url .= '&e_v=' . $value; } return $url; } @@ -982,7 +1009,8 @@ class PiwikTracker $url = $this->getRequest($this->idSite); $url .= '&idgoal=' . $idGoal; if (!empty($revenue)) { - $url .= '&revenue=' . $revenue; + $revenue = $this->forceDotAsSeparatorForDecimalPoint($revenue); + $url .= '&revenue=' . $revenue; } return $url; } |