title: PS 1.6 Module trigger event on Ajax Add to cart
body: <p>I've been studying how PrestaShop modules work lately and it would be great if someone could point me in the right direction.
  I want to trigger an event (javascript method to be exact, let's call it "MyShop") that would get all the product details in it.
  I have some older code but either it was working with older version of PS either it's only for normal add to cart and not ajax. 
  The issue is that it doesn't even get triggered at all after pressing "add to cart" button, it's actually a piece of code from Google Analytics module. </p>
  
  <p>Here is a piece of modified code from my module's main .php file that is supposed to get triggered on the add to cart, it's using "hookActionCartSave()" but I am not sure if that is still available in 1.6 or got replaced by something else or whether it just simply doesn't work with ajax and I should look elsewhere? </p>
  
  <pre><code> /**
           * hook save cart event to implement addtocart and remove from cart functionality
           */
          public function hookActionCartSave()
          {
              if (!isset($this-&gt;context-&gt;cart))
                  return;
  
              $cart = array(
                            'controller' =&gt; Tools::getValue('controller'),
                            'addAction' =&gt; Tools::getValue('add') ? 'add' : '',
                            'removeAction' =&gt; Tools::getValue('delete') ? 'delete' : '',
                            'extraAction' =&gt; Tools::getValue('op'),
                            'qty' =&gt; (int)Tools::getValue('qty', 1)
                            );
  
              $cart_products = $this-&gt;context-&gt;cart-&gt;getProducts();
  
              if (isset($cart_products) &amp;&amp; count($cart_products))
                  foreach ($cart_products as $cart_product)
                  if ($cart_product['id_product'] == Tools::getValue('id_product'))
                      $add_product = $cart_product;
  
              if ($cart['removeAction'] == 'delete')
              {
                  $add_product_object = new Product((int)Tools::getValue('id_product'), true, (int)Configuration::get('PS_LANG_DEFAULT'));
                  if (Validate::isLoadedObject($add_product_object))
                  {
                      $add_product['name'] = $add_product_object-&gt;name;
                      $add_product['manufacturer_name'] = $add_product_object-&gt;manufacturer_name;
                      $add_product['category'] = $add_product_object-&gt;category;
                      $add_product['reference'] = $add_product_object-&gt;reference;
                      $add_product['link_rewrite'] = $add_product_object-&gt;link_rewrite;
                      $add_product['link'] = $add_product_object-&gt;link_rewrite;
                      $add_product['price'] = $add_product_object-&gt;price;
                      $add_product['ean13'] = $add_product_object-&gt;ean13;
                      $add_product['id_product'] = Tools::getValue('id_product');
                      $add_product['id_category_default'] = $add_product_object-&gt;id_category_default;
                      $add_product['out_of_stock'] = $add_product_object-&gt;out_of_stock;
                      $add_product = Product::getProductProperties((int)Configuration::get('PS_LANG_DEFAULT'), $add_product);
                  }
              }
  
              if (isset($add_product) &amp;&amp; !in_array((int)Tools::getValue('id_product'), self::$products))
              {
                  self::$products[] = (int)Tools::getValue('id_product');
                  $ga_products = $this-&gt;wrapProduct($add_product, $cart, 0, true);
                  if (array_key_exists('id_product_attribute', $ga_products) &amp;&amp; $ga_products['id_product_attribute'] != '' &amp;&amp; $ga_products['id_product_attribute'] != 0)
                      $id_product = $ga_products['id_product_attribute'];
                  else
                      $id_product = Tools::getValue('id_product');
                  if (isset($this-&gt;context-&gt;cookie-&gt;MyShop_cart))
                      $MyShop_cart = unserialize($this-&gt;context-&gt;cookie-&gt;MyShop_cart);
                  else
                      $MyShop_cart = array();
                  if ($cart['removeAction'] == 'delete')
                      $ga_products['quantity'] = -1;
                  elseif ($cart['extraAction'] == 'down')
                  {
                      if (array_key_exists($id_product, $MyShop_cart))
                          $ga_products['quantity'] = $MyShop_cart[$id_product]['quantity'] - $cart['qty'];
                      else
                          $ga_products['quantity'] = $cart['qty'] * -1;
                  }
                  elseif (Tools::getValue('step') &lt;= 0) // Sometimes cartsave is called in checkout
                  {
                      if (array_key_exists($id_product, $MyShop_cart))
                          $ga_products['quantity'] = $MyShop_cart[$id_product]['quantity'] + $cart['qty'];
                  }
                  $MyShop_cart[$id_product] = $ga_products;
                  $this-&gt;context-&gt;cookie-&gt;MyShop_cart = serialize($MyShop_cart);
  
                  $this-&gt;didCartChange = 1;
              }
          }
  </code></pre>
  
  <p>I know that regarding what I am looking for a lot is handled in blockcart/ajax-cart.js and controllers/front/CartController.php but I am not precisely sure where or what to look for and this way I was hoping someone will lead me to a proper direction or save me some time on searching.</p>
  
  <p>I also assume that regarding the javascript potion I have to modify the template itself, this is a piece of code from my module's header.tpl:</p>
  
  <pre><code>var MyShop_blockcart_log = function(json) {
      var products = json.products;
      var product;
      var ps = [];
      var p;
  
      for(var i=0; i&lt;products.length; i++) {
          product = products[i];
          p = {};
  
          p.id = product.id;
          p.link = product.link;
          p.imageUrl = product.id_image.replace("medium_default", "large_default");
          p.quantity = product.quantity;
          p.name = product.name;
          p.price = "{$currency-&gt;sign} " + (parseInt(product.price_float) / product.quantity).toFixed(2);
  
  
          ps.push(p);
      }
  
      MyShop("log", "product", "cart", ps);
  }
  </code></pre>
  
  <p>That code does not cause any errors, it just doesn't get triggered after adding products to the cart and it should.
  Do I have to bind it to the add to cart button via my header.tpl file for example? And if yes then how could I do it?</p>
  
  <p>Thanks in advance, 
  Cheers.</p>