title: Manually add a product to cart using ajax in opencart
body: <p>I need to add a product to the cart once the user click a button by using my own function.</p>
  
  <p>The button code:</p>
  
  <pre><code> &lt;input type="button" value="Add to cart" onclick="addItemsToCart(83); " class="button btn-success"  id="addToCartButton1"/&gt;
  
   &lt;input type="button" value="Add to cart" onclick="addItemsToCart(84); " class="button btn-success"  id="addToCartButton2"/&gt;
  </code></pre>
  
  <p><strong>addItemsToCartFunction</strong>:</p>
  
  <pre><code>function addItemsToCart(option_value_id){
  
          $.ajax({
          url: 'index.php?route=checkout/cart/add',
          type: 'post',
          data: 'product_id=' + 92+ '&amp;quantity=' + 1, //need to change this
          dataType: 'json',
          success: function(json) {
              $('.success, .warning, .attention, .information, .error').remove();
  
              if (json['redirect']) {
                  location = json['redirect'];
              }
  
              if (json['success']) {
                  $('#notification').html('&lt;div class="success" style="display: none;"&gt;' + json['success'] + '&lt;img src="catalog/view/theme/default/image/close.png" alt="" class="close" /&gt;&lt;/div&gt;');
  
                  $('.success').fadeIn('slow');
  
                  $('#cart-total').html(json['total']);
  
                  $('html, body').animate({ scrollTop: 0 }, 'slow'); 
              }   
          }
      });
  
      }
  </code></pre>
  
  <p>This is working properly.</p>
  
  <p>But This product has a option called 'custom'.</p>
  
  <p>option details according to the database:</p>
  
  <pre><code>option id: 17
  option values ids 83 and 84.
  </code></pre>
  
  <p>I have passed the option value as a parameter to the function addItemsToCart.</p>
  
  <p>Now I need to pass that option and value to the data section. That means I need to change this line. </p>
  
  <pre><code>data: 'product_id=' + 92+ '&amp;quantity=' + 1,
  </code></pre>
  
  <p>How to do this?</p>