title: Codeigniter cart - add ketchup on pizza
body: <p>I'm building pizzeria app in CI using cart library.
  For some products (pizza, salad...) there is an option to add ingredients.
  This is what I have:</p>
  
  <p>Add_to _cart buton</p>
  
  <pre><code>&lt;button class="but_add_cart"
          data-qty="1" 
          data-productid="&lt;?php echo $food_item-&gt;item_id; ?&gt;" 
          data-productname="&lt;?php echo $food_item-&gt;item_name; ?&gt;" 
          data-productprice="&lt;?php echo $food_item-&gt;item_price; ?&gt;"
          data-adds="&lt;?php echo $food_item-&gt;item_price; ?&gt;
  </code></pre>
  
  <p>With jquery I'm calling ajax</p>
  
  <pre><code>$('.but_add_cart').click(function(){
  
          allVals = []
  
          $('#chk :checked').each(function() {
             allVals.push($(this).val());
           });
          // here I'm getting all ingredients from checkboxes and push to array
  
          var product_id = $(this).data("productid");
          var description = $(this).data("description");
          var product_name = $(this).data("productname");
          var product_price = $(this).data("productprice");
          var product_qty = $(this).data("qty");
  
  
          if(product_id != '' &amp;&amp; product_id &gt; 0) 
              {
                  $.ajax({
                  url:"&lt;?php echo base_url(); ?&gt;menu/add",
                  type:"POST",
                  async: true,
                  data:{product_id:product_id, description:description, product_name:product_name, product_qty:product_qty, product_price:product_price, allVals:allVals},
                  success:function(data)
                      {
                          $('#cart_details').html(data);
  
                      }
                  });
  
              } 
          else
              {
                  alert("Please Enter quantity");
              }
  });
  </code></pre>
  
  <p>and add function is:</p>
  
  <pre><code>function add()
      {
          $data = array(
              "id"  =&gt; $_POST["product_id"],
              "qty"  =&gt; $_POST["product_qty"],
              "price"  =&gt; $_POST["product_price"],
              "name"  =&gt; $_POST["product_name"],
              "description"  =&gt; $_POST["description"],
              "allVals"  =&gt; $_POST["allVals"]
          );
  
              print_r($data);
  
              //$this-&gt;cart-&gt;insert($data);
              //echo $this-&gt;view();
  
      }
  </code></pre>
  
  <p>from print_r I have this array</p>
  
  <pre><code>Array
  (
      [id] =&gt; 1
      [qty] =&gt; 1
      [price] =&gt; 19.90
      [name] =&gt; Pepperoni Pizza
      [description] =&gt; Extra-virgin olive oil, garlic, mozzarella cheese
      [allVals] =&gt; Array
          (
              [0] =&gt; 2
              [1] =&gt; 3
              [2] =&gt; 4
              [3] =&gt; 6
          )
  )
  </code></pre>
  
  <p>Now, in the cart, I want to group Pepperoni pizza with ingredients (2, 3, 4, 6) as one item. If I add one more Pepperoni pizza but with different ingredients, it should be separate item in the cart. I tried to add some random number to rowid but it gives me some error.</p>
  
  <p>Also, every ingredients coast so I have to add these prices to subtotal price for each item in the basket.</p>
  
  <p>I know problem is quite complex but I would like to know if my approach is good or there is a better way to to do this?</p>