Jump to content

Google Analytics v2.3.4 - in PrestaShop 1.7.1.1 (A non well formed numeric value encountered)


Recommended Posts

Kinda disappointed by PrestaShop 1.7, must say....

 

The official Google Analytics modules, latest version, officially developed by PrestaShop crashes on all product pages...

 

Google Analytics
v2.3.4 - by PrestaShop

 

ContextErrorException in ganalytics.php line 539:Notice: A non well formed numeric value encountered

 
  1. in ganalytics.php line 539
  2. at ErrorHandler->handleError('8', 'A non well formed numeric value encountered', '/home/bbooks/public_html/modules/ganalytics/ganalytics.php', '539', array('product' => array('id_shop_default' => '1', 'id_manufacturer' => '1', 'id_supplier' => '1', 'reference' => 'demo_3',  ....etc...

 

 

This errors only happens on PRODUCT PAGES, other pages seem to be fine...

Line 539 in PrestaShop 1.7.1.1, official Google Analytics Module v2.3.4, line 539

'price' => number_format($product['price'], '2')
 
Here is the whole code block:
if ($full)
{
$ga_product = array(
'id' => $product_id,
'name' => Tools::jsonEncode($product['name']),
'category' => Tools::jsonEncode($product['category']),
'brand' => isset($product['manufacturer_name']) ? Tools::jsonEncode($product['manufacturer_name']) : '',
'variant' => Tools::jsonEncode($variant),
'type' => $product_type,
'position' => $index ? $index : '0',
'quantity' => $product_qty,
'list' => Tools::getValue('controller'),
'url' => isset($product['link']) ? urlencode($product['link']) : '',
'price' => number_format($product['price'], '2')
);

 

 

Any ideas guys?

Edited by Bojanstven (see edit history)
  • Like 1
Link to comment
Share on other sites

I figured out what this was all about.

If you use a different currency that does NOT match to standard English decimal mark it is going to crash.

 

In my case currency was RSD and it uses decimal point, like 199,99 RSD instead of usual 199.99 EUR/USD.

Or in case of larger numbers, 2.199,99 RSD as opposed to 2,199.99 EUR/USD

 

Product Price in Presta 1.7 is defined as a string if I'm not mistaking, so that produces an error, since Presta is expecting to find a different string type.

 

Anyways, I temporarily solved it by just removing the last line of code and it works for me with different decimal marks:

'price' => number_format($product['price'], '2')

Should anyone have the same problem, I think this should help. Or edit the string type for the price.

 

Best,

Bojan

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

I had the same problem, number_format take a float as first parameter, and for me, $product['price'] return a string like "22,40 €" !

 

So i solved it by changing the line 589 by

'price' => number_format(floatval(str_replace(',', '.', $product['price'])), '2')

Hope this helps

Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...
On 1/7/2019 at 10:27 AM, mourad1081 said:

Now it has been years...

Yeap.. Prestashop 1.7, recently installed and still same issue.. in different line for me, apparently not related to currency

 

1/1) ContextErrorException

Notice: Undefined index: name

in ganalytics.php line 530 --> 'name' => Tools::jsonEncode($product['name']),

Link to comment
Share on other sites

  • 1 month later...

Hi everyone !

I'm currently experiencing the same issue as Hortiz : when i click on one of my products, i get a PHP error (I enabled the debug mode as it is my "test" website) :

Notice: Undefined index: name

in ganalytics.php line 530 

 

if ($full)
  {
    $ga_product = array(
      'id' => $product_id,
      'name' => Tools::jsonEncode($product['name']), // This is line 530 ///////////////////////////////////////////////////
      'category' => Tools::jsonEncode($product['category']),
      'brand' => isset($product['manufacturer_name']) ? Tools::jsonEncode($product['manufacturer_name']) : '',
      'variant' => Tools::jsonEncode($variant),
      'type' => $product_type,
      'position' => $index ? $index : '0',
      'quantity' => $product_qty,
      'list' => Tools::getValue('controller'),
      'url' => isset($product['link']) ? urlencode($product['link']) : '',
      'price' => number_format($product['price'], '2')
    );
  }

 

Any idea where does this error come from ? 

Thanks for your help !

Link to comment
Share on other sites

  • 5 months later...
  • 7 months later...

Hey,

i have a similar problem here with presta 1.6.1.27 and Google Analytics v2.3.4 


Notice: Undefined index: name in /home/site/domains/site.com/public_html/modules/ganalytics/ganalytics.php on line 530

Notice: Undefined index: category in /home/site/domains/site.com/public_html/modules/ganalytics/ganalytics.php on line 531

Edited by m2ma (see edit history)
Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...