Jump to content
Bojanstven

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
On 7/23/2017 at 11:50 PM, ssuchanowski said:

+1

 

Really no one fixed this so far? It's has been months..

Now it has been years...

Share this post


Link to post
Share on other sites
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']),

Share this post


Link to post
Share on other sites

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 !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More