title: Codeigniter add a Discount item
body: <p>Hi I have a cart in Codeigniter that works well. I tried to look for a discount/coupon handling but can't.</p>
  
  <p>This is my cart code:</p>
  
  <pre><code>public function addToCart($id){
  
      $this-&gt;load-&gt;model('products_model');
  
      $products = $this-&gt;products_model-&gt;getItemDetail($id);
  
      foreach ($products as $product) {
          $insert = array(
              'id' =&gt; $product-&gt;id,
              'name' =&gt; $product-&gt;name,
              'qty' =&gt; '1',
              'price' =&gt; $product-&gt;item_eur,
              'image' =&gt; $product-&gt;image,
              'options' =&gt; array(
                  'info' =&gt; $product-&gt;cart_description,
                  'qty_description' =&gt; $product-&gt;qty_description
                  )
              );
          $this-&gt;cart-&gt;insert($insert);
      }
  
      $last = end($this-&gt;cart-&gt;contents());
      echo $last['rowid'];
  }
  </code></pre>
  
  <p>I thought of making a Coupon Code read from the DB and insert a discount as an item in the cart:</p>
  
  <pre><code>public function addCoupon(){
      $this-&gt;load-&gt;model('products_model');
      $res = $this-&gt;products_model-&gt;getCoupon($_POST['value']);
      if($res){
          foreach($res as $result){
              $coupon = array(
                  'id' =&gt; $result-&gt;id,
                  'name' =&gt; $result-&gt;name,
                  'qty' =&gt; '1',
                  'price' =&gt; $result-&gt;discount,
                  'options' =&gt; array(
                      'info' =&gt; 'coupon',
                      'qty_description' =&gt; ''
                      )
                  );
              $this-&gt;cart-&gt;insert($coupon);
          }
          echo '1';
      }else{
          $this-&gt;lang-&gt;load('products');
          echo $this-&gt;lang-&gt;line('cart_notok');
      }
  }
  </code></pre>
  
  <p>Where the DB is </p>
  
  <pre><code>[name:type] (example)
  id:int (1)
  name: varchar ('Discount of 20€')
  code: varchar ('AFD1234')
  discount: decimal (-20)
  </code></pre>
  
  <p><em><strong>[Edit]</em></strong></p>
  
  <p>And the model:</p>
  
  <pre><code>public function getCoupon($code){
  
      $results = $this-&gt;db-&gt;get_where('coupons', array('code' =&gt; $code));
      return $results-&gt;result();
  
  }
  </code></pre>
  
  <p>The item gets added to the cart but if the <code>'price' =&gt; $result-&gt;discount</code> is set to <code>-20</code> or a percentage it gets set as +20€ and not -20€.</p>
  
  <p>Any way to do this?</p>