title: PHP help, session error possibily?
body: <p>I am working on an e-commerce site and when the user adds a product to the basket for the first time, I get the following error, </p>
  
  <blockquote>
    <blockquote>
      <p>A PHP Error was encountered</p>
    </blockquote>
    
    <p>Severity: Notice</p>
    
    <p>Message: Undefined index: orderDetails</p>
    
    <p>Filename: libraries/MY_Cart.php</p>
    
    <p>Line Number: 59 A PHP Error was
    encountered</p>
    
    <p>Severity: Warning</p>
    
    <p>Message: Cannot modify header
    information - headers already sent by
    (output started at
    /var/www/vhosts/akulaliving.com/httpdocs/CI-1.7.3/libraries/Exceptions.php:166)</p>
    
    <p>Filename: libraries/Session.php</p>
    
    <p>Line Number: 662</p>
  </blockquote>
  
  <p>The adds a product to the basket with the following code, </p>
  
  <pre><code>if ($this-&gt;input-&gt;post('btnAddToBag'))
          {
  
              $derivativeId = $this-&gt;input-&gt;post('selDerivative-1');
              $quantity = $this-&gt;input-&gt;post('selQuantity');
              $derivative = $this-&gt;Product_model-&gt;GetProducts(array('pdId' =&gt; $derivativeId), 'small');
  
              // Add item to shopping bag.
              $attributes = $this-&gt;Product_model-&gt;GetProductDerivatives(array('pdId' =&gt; $derivativeId));
              $this-&gt;Checkout_model-&gt;AddProduct($derivative, $attributes, $quantity);
              $this-&gt;data['message'] = 'Item added to Shopping Bag.';
  
              // Update Delivery Price
              $this-&gt;Checkout_model-&gt;updateDelivery(49);
  
              //get the bag details
              $this-&gt;data['items'] = $this-&gt;Checkout_model-&gt;GetProducts();        
          }
  </code></pre>
  
  <p>The model function that gets called is this, </p>
  
  <pre><code>function AddProduct($derivative, $attributes, $quantity)
  {
      $data = array(
         'id'         =&gt; $derivative-&gt;pdId,
         'qty'        =&gt; $quantity,
         'price'      =&gt; ($derivative-&gt;productSavingType == 'none' ? $derivative-&gt;productPrice : $derivative-&gt;productSavingPrice),
         'name'       =&gt; $derivative-&gt;productTitle,
         'attributes' =&gt; $attributes['attributeValues'],
         'refNo'      =&gt; $derivative-&gt;pdRefNo,
         'productId'  =&gt; $derivative-&gt;productId,
         'set'        =&gt; $derivative-&gt;productIsSet,
         'hasImage'   =&gt; $derivative-&gt;hasImage,
         'imageUrl'   =&gt; $derivative-&gt;imageUrl,
         'imageAlt'   =&gt; $derivative-&gt;imageAlt,
         'stockLevel' =&gt; $derivative-&gt;pdStockLevel,
         'leadTime'   =&gt; $derivative-&gt;pdLeadTime
      );
  
      $data['nonDiscountedPrice'] = $data['price'];
      if ($derivative-&gt;productSavingType == 'end-of-season')
      {
          $data['nonDiscountedPrice'] = $derivative-&gt;productPrice;
      }
  
      $this-&gt;cart-&gt;insert($data);
  }
  </code></pre>
  
  <p>the code the error is complaining about is the following, </p>
  
  <pre><code>function _insert($items=array())
  {
      if (isset($items['options']) AND count($items['options']) &gt; 0)
      {
          $rowid = md5($items['id'].implode('', $items['options']));
      }
      else
      {
          $rowid = md5($items['id']);
      }
  
      if (isset($this-&gt;_cart_contents[$rowid]))
      {
          if (!isset($items['qty']))
          {
              return FALSE;
          }
  
          // Already Exists, we need to update the total for this item
          $new_qty = $items['qty'];
          $items['qty'] = $items['qty'] + $this-&gt;_cart_contents[$rowid]['qty'];
  
          $items['rowid'] = $rowid;
  
          if ($this-&gt;_update($items))
          {
              return TRUE;
          }
          return FALSE;
      }
  
      // Doesn't exist, we need to insert this item.
      if (parent::_insert($items))
      {
          // Update our total.
          if (isset($this-&gt;_cart_contents[$rowid]))
          {
              $this-&gt;real_total_items += $this-&gt;_cart_contents[$rowid]['qty'];
              if ($this-&gt;_cart_contents['orderDetails']['discount'] &gt; 0)
              {
                  $this-&gt;_cart_contents[$rowid]['price'] = $this-&gt;_cart_contents[$rowid]['nonDiscountedPrice'];
                  $this-&gt;_save_cart();
              }
          }
          return TRUE;
      }
      return FALSE;
  }
  </code></pre>