2020
2121namespace PrestaShop \Module \Ps_Googleanalytics \Hooks ;
2222
23+ use Configuration ;
24+ use Context ;
2325use PrestaShop \Module \Ps_Googleanalytics \Handler \GanalyticsDataHandler ;
2426use PrestaShop \Module \Ps_Googleanalytics \Wrapper \ProductWrapper ;
27+ use Product ;
28+ use Ps_Googleanalytics ;
29+ use Tools ;
30+ use Validate ;
2531
2632class HookActionCartSave implements HookInterface
2733{
2834 private $ module ;
2935
3036 /**
31- * @var \ Context
37+ * @var Context
3238 */
3339 private $ context ;
3440
35- public function __construct (\ Ps_Googleanalytics $ module , \ Context $ context )
41+ public function __construct (Ps_Googleanalytics $ module , Context $ context )
3642 {
3743 $ this ->module = $ module ;
3844 $ this ->context = $ context ;
@@ -49,30 +55,30 @@ public function run()
4955 return ;
5056 }
5157
52- if (!\ Tools::getIsset ('id_product ' )) {
58+ if (!Tools::getIsset ('id_product ' )) {
5359 return ;
5460 }
5561
5662 $ cart = [
57- 'controller ' => \ Tools::getValue ('controller ' ),
58- 'addAction ' => \ Tools::getValue ('add ' ) ? 'add ' : '' ,
59- 'removeAction ' => \ Tools::getValue ('delete ' ) ? 'delete ' : '' ,
60- 'extraAction ' => \ Tools::getValue ('op ' ),
61- 'qty ' => (int ) \ Tools::getValue ('qty ' , 1 ),
63+ 'controller ' => Tools::getValue ('controller ' ),
64+ 'addAction ' => Tools::getValue ('add ' ) ? 'add ' : '' ,
65+ 'removeAction ' => Tools::getValue ('delete ' ) ? 'delete ' : '' ,
66+ 'extraAction ' => Tools::getValue ('op ' ),
67+ 'qty ' => (int ) Tools::getValue ('qty ' , 1 ),
6268 ];
6369
6470 $ cartProducts = $ this ->context ->cart ->getProducts ();
6571 if (!empty ($ cartProducts )) {
6672 foreach ($ cartProducts as $ cartProduct ) {
67- if ($ cartProduct ['id_product ' ] == \ Tools::getValue ('id_product ' )) {
73+ if ($ cartProduct ['id_product ' ] == Tools::getValue ('id_product ' )) {
6874 $ addProduct = $ cartProduct ;
6975 }
7076 }
7177 }
7278
7379 if ($ cart ['removeAction ' ] == 'delete ' ) {
74- $ addProductObject = new \ Product ((int ) \ Tools::getValue ('id_product ' ), true , (int ) \ Configuration::get ('PS_LANG_DEFAULT ' ));
75- if (\ Validate::isLoadedObject ($ addProductObject )) {
80+ $ addProductObject = new Product ((int ) Tools::getValue ('id_product ' ), true , (int ) Configuration::get ('PS_LANG_DEFAULT ' ));
81+ if (Validate::isLoadedObject ($ addProductObject )) {
7682 $ addProduct ['name ' ] = $ addProductObject ->name ;
7783 $ addProduct ['manufacturer_name ' ] = $ addProductObject ->manufacturer_name ;
7884 $ addProduct ['category ' ] = $ addProductObject ->category ;
@@ -81,29 +87,29 @@ public function run()
8187 $ addProduct ['link ' ] = $ addProductObject ->link_rewrite ;
8288 $ addProduct ['price ' ] = $ addProductObject ->price ;
8389 $ addProduct ['ean13 ' ] = $ addProductObject ->ean13 ;
84- $ addProduct ['id_product ' ] = \ Tools::getValue ('id_product ' );
90+ $ addProduct ['id_product ' ] = Tools::getValue ('id_product ' );
8591 $ addProduct ['id_category_default ' ] = $ addProductObject ->id_category_default ;
8692 $ addProduct ['out_of_stock ' ] = $ addProductObject ->out_of_stock ;
8793 $ addProduct ['minimal_quantity ' ] = 1 ;
8894 $ addProduct ['unit_price_ratio ' ] = 0 ;
89- $ addProduct = \ Product::getProductProperties ((int ) \ Configuration::get ('PS_LANG_DEFAULT ' ), $ addProduct );
95+ $ addProduct = Product::getProductProperties ((int ) Configuration::get ('PS_LANG_DEFAULT ' ), $ addProduct );
9096 }
9197 }
9298
93- if (isset ($ addProduct ) && !in_array ((int ) \ Tools::getValue ('id_product ' ), $ this ->module ->products )) {
99+ if (isset ($ addProduct ) && !in_array ((int ) Tools::getValue ('id_product ' ), $ this ->module ->products )) {
94100 $ ganalyticsDataHandler = new GanalyticsDataHandler (
95101 $ this ->context ->cart ->id ,
96102 $ this ->context ->shop ->id
97103 );
98104
99- $ this ->module ->products [] = (int ) \ Tools::getValue ('id_product ' );
105+ $ this ->module ->products [] = (int ) Tools::getValue ('id_product ' );
100106 $ productWrapper = new ProductWrapper ($ this ->context );
101107 $ gaProducts = $ productWrapper ->wrapProduct ($ addProduct , $ cart , 0 , true );
102108
103109 if (array_key_exists ('id_product_attribute ' , $ gaProducts ) && $ gaProducts ['id_product_attribute ' ] != '' && $ gaProducts ['id_product_attribute ' ] != 0 ) {
104110 $ productId = $ gaProducts ['id_product_attribute ' ];
105111 } else {
106- $ productId = \ Tools::getValue ('id_product ' );
112+ $ productId = Tools::getValue ('id_product ' );
107113 }
108114
109115 $ gaCart = $ ganalyticsDataHandler ->manageData ('' , 'R ' );
@@ -116,7 +122,7 @@ public function run()
116122 } else {
117123 $ gaProducts ['quantity ' ] = $ cart ['qty ' ] * -1 ;
118124 }
119- } elseif (\ Tools::getValue ('step ' ) <= 0 ) { // Sometimes cartsave is called in checkout
125+ } elseif (Tools::getValue ('step ' ) <= 0 ) { // Sometimes cartsave is called in checkout
120126 if (array_key_exists ($ productId , $ gaCart )) {
121127 $ gaProducts ['quantity ' ] = $ gaCart [$ productId ]['quantity ' ] + $ cart ['qty ' ];
122128 }
0 commit comments