title: Add products on shopping cart
body: <p>Friends, I am developing an e-commerce website (using Codeigniter).</p>
  
  <p>After the customer fill out the amount of products and click "Buy", only products with the field "quantity" are to be filled in cart. Can you help me?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;form&gt;
  &lt;ul class="products-list"&gt;
      &lt;li class="product"&gt;
          &lt;input type="hidden" class="product_id" value="1"&gt;
          &lt;span class="product-name"&gt;Product 1&lt;/span&gt;
          &lt;span class="product-value"&gt;$ 100&lt;/span&gt; 
          &lt;span&gt;Qnt. &lt;input type="text" class="quantity"&gt;&lt;/span&gt; 
      &lt;/li&gt;
          &lt;li class="product"&gt;
          &lt;input type="hidden" class="product_id" value="2"&gt;
          &lt;span class="product-name"&gt;Product 2&lt;/span&gt;
          &lt;span class="product-value"&gt;$ 100&lt;/span&gt; 
          &lt;span&gt;Qnt. &lt;input type="text" class="quantity"&gt;&lt;/span&gt; 
      &lt;/li&gt;
  &lt;/ul&gt;
  &lt;button&gt;Buy&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><hr/>
  <strong>jQuery:</strong></p>
  
  <pre><code>$.ajax({
      url: '/cart/add/'+product_id+'/'+quantity,
      type: 'GET',
      success: function( data ){
          if ( data != false ) {
              window.location.reload();
          }
      }
  });
  </code></pre>
  
  <p><hr/>
  <strong>My PHP Code:</strong></p>
  
  <pre><code>public function addItem( $product_id, $quantity){ 
      $product = $this-&gt;Produto_model-&gt;getById($product_id); 
      $this-&gt;carrinho-&gt;setItem($product, $quantity); 
      echo json_encode($this-&gt;carrinho); 
  }  
  </code></pre>