@@ -320,13 +320,15 @@ public function hookdisplayFooter()
320320 if (isset ($ this ->context ->cookie ->ga_cart )) {
321321 $ this ->filterable = 0 ;
322322
323- $ gacarts = Tools::jsonDecode ($ this ->context ->cookie ->ga_cart );
324- foreach ($ gacarts as $ gacart ) {
325- if ($ gacart ['quantity ' ] > 0 ) {
326- $ ga_scripts .= 'MBG.addToCart( ' .Tools::jsonEncode ($ gacart ).'); ' ;
327- } elseif ($ gacart ['quantity ' ] < 0 ) {
328- $ gacart ['quantity ' ] = abs ($ gacart ['quantity ' ]);
329- $ ga_scripts .= 'MBG.removeFromCart( ' .Tools::jsonEncode ($ gacart ).'); ' ;
323+ $ gacarts = json_decode ($ this ->context ->cookie ->ga_cart );
324+ if (is_array ($ gacarts ) {
325+ foreach ($ gacarts as $ gacart ) {
326+ if ($ gacart ['quantity ' ] > 0 ) {
327+ $ ga_scripts .= 'MBG.addToCart( ' .json_encode ($ gacart ).'); ' ;
328+ } elseif ($ gacart ['quantity ' ] < 0 ) {
329+ $ gacart ['quantity ' ] = abs ($ gacart ['quantity ' ]);
330+ $ ga_scripts .= 'MBG.removeFromCart( ' .json_encode ($ gacart ).'); ' ;
331+ }
330332 }
331333 }
332334 unset($ this ->context ->cookie ->ga_cart );
@@ -517,10 +519,10 @@ public function addTransaction($products, $order)
517519
518520 $ js = '' ;
519521 foreach ($ products as $ product ) {
520- $ js .= 'MBG.add( ' .Tools:: jsonEncode ($ product ).'); ' ;
522+ $ js .= 'MBG.add( ' .json_encode ($ product ).'); ' ;
521523 }
522524
523- return $ js .'MBG.addTransaction( ' .Tools:: jsonEncode ($ order ).'); ' ;
525+ return $ js .'MBG.addTransaction( ' .json_encode ($ order ).'); ' ;
524526 }
525527
526528 /**
@@ -534,7 +536,7 @@ public function addProductImpression($products)
534536
535537 $ js = '' ;
536538 foreach ($ products as $ product ) {
537- $ js .= 'MBG.add( ' .Tools:: jsonEncode ($ product ).",'',true); " ;
539+ $ js .= 'MBG.add( ' .json_encode ($ product ).",'',true); " ;
538540 }
539541
540542 return $ js ;
@@ -548,7 +550,7 @@ public function addProductClick($products)
548550
549551 $ js = '' ;
550552 foreach ($ products as $ product ) {
551- $ js .= 'MBG.addProductClick( ' .Tools:: jsonEncode ($ product ).'); ' ;
553+ $ js .= 'MBG.addProductClick( ' .json_encode ($ product ).'); ' ;
552554 }
553555
554556 return $ js ;
@@ -562,7 +564,7 @@ public function addProductClickByHttpReferal($products)
562564
563565 $ js = '' ;
564566 foreach ($ products as $ product ) {
565- $ js .= 'MBG.addProductClickByHttpReferal( ' .Tools:: jsonEncode ($ product ).'); ' ;
567+ $ js .= 'MBG.addProductClickByHttpReferal( ' .json_encode ($ product ).'); ' ;
566568 }
567569
568570 return $ js ;
@@ -579,7 +581,7 @@ public function addProductFromCheckout($products)
579581
580582 $ js = '' ;
581583 foreach ($ products as $ product ) {
582- $ js .= 'MBG.add( ' .Tools:: jsonEncode ($ product ).'); ' ;
584+ $ js .= 'MBG.add( ' .json_encode ($ product ).'); ' ;
583585 }
584586
585587 return $ js ;
@@ -595,7 +597,7 @@ public function hookdisplayFooterProduct($params)
595597 {
596598 // Add product view
597599 $ ga_product = $ this ->wrapProduct ((array )$ params ['product ' ], null , 0 , true );
598- $ js = 'MBG.addProductDetailView( ' .Tools:: jsonEncode ($ ga_product ).'); ' ;
600+ $ js = 'MBG.addProductDetailView( ' .json_encode ($ ga_product ).'); ' ;
599601
600602 if (isset ($ _SERVER ['HTTP_REFERER ' ]) && strpos ($ _SERVER ['HTTP_REFERER ' ], $ _SERVER ['HTTP_HOST ' ]) > 0 ) {
601603 $ js .= $ this ->addProductClickByHttpReferal (array ($ ga_product ));
@@ -679,7 +681,7 @@ public function hookdisplayBackOfficeHeader()
679681 $ transaction = $ this ->wrapOrder ($ row ['id_order ' ]);
680682 if (!empty ($ transaction )) {
681683 Db::getInstance ()->execute ('UPDATE ` ' ._DB_PREFIX_ .'ganalytics` SET date_add = NOW(), sent = 1 WHERE id_order = ' .(int )$ row ['id_order ' ].' AND id_shop = \'' .(int )$ this ->context ->shop ->id .'\'' );
682- $ transaction = Tools:: jsonEncode ($ transaction );
684+ $ transaction = json_encode ($ transaction );
683685 $ ga_scripts .= 'MBG.addTransaction( ' .$ transaction .'); ' ;
684686 }
685687 }
@@ -702,14 +704,14 @@ public function hookactionProductCancel($params)
702704 foreach ($ qty_refunded as $ orderdetail_id => $ qty ) {
703705 // Display GA refund product
704706 $ order_detail = new OrderDetail ($ orderdetail_id );
705- $ ga_scripts .= 'MBG.add( ' .Tools:: jsonEncode (
707+ $ ga_scripts .= 'MBG.add( ' .json_encode (
706708 array (
707709 'id ' => empty ($ order_detail ->product_attribute_id )?$ order_detail ->product_id :$ order_detail ->product_id .'- ' .$ order_detail ->product_attribute_id ,
708710 'quantity ' => $ qty )
709711 )
710712 .'); ' ;
711713 }
712- $ this ->context ->cookie ->ga_admin_refund = $ ga_scripts .'MBG.refundByProduct( ' .Tools:: jsonEncode (array ('id ' => $ params ['order ' ]->id )).'); ' ;
714+ $ this ->context ->cookie ->ga_admin_refund = $ ga_scripts .'MBG.refundByProduct( ' .json_encode (array ('id ' => $ params ['order ' ]->id )).'); ' ;
713715 }
714716
715717 /**
@@ -771,7 +773,7 @@ public function hookactionCartSave()
771773 }
772774
773775 if (isset ($ this ->context ->cookie ->ga_cart )) {
774- $ gacart = Tools:: jsonDecode ($ this ->context ->cookie ->ga_cart );
776+ $ gacart = json_decode ($ this ->context ->cookie ->ga_cart );
775777 } else {
776778 $ gacart = array ();
777779 }
@@ -791,7 +793,7 @@ public function hookactionCartSave()
791793 }
792794
793795 $ gacart [$ id_product ] = $ ga_products ;
794- $ this ->context ->cookie ->ga_cart = Tools:: jsonEncode ($ gacart );
796+ $ this ->context ->cookie ->ga_cart = json_encode ($ gacart );
795797 }
796798 }
797799
0 commit comments