title: Codeigniter: how to get cart value for paypal payment
body: <pre><code>&lt;?php echo form_open('member/update_cart'); ?&gt;
  
  &lt;script&gt;
  function clear_cart() {
      var result = confirm('Are you sure want to clear all bookings?');
  
      if(result) {
          window.location = "&lt;?php echo base_url(); ?&gt;member/cart_remove/all";
      }else{
          return false; // cancel button
      }
  }
  &lt;/script&gt;
  &lt;table cellpadding="6" cellspacing="1" style="width:100%" border="1"&gt;
  
  &lt;div style="margin:0px auto; width:600px;" &gt;
      &lt;div style="padding-bottom:10px"&gt;
          &lt;h1 align="center"&gt;Your Shopping Cart&lt;/h1&gt;
          &lt;input type="button" value="Continue Shopping" onclick="window.location='&lt;?php echo base_url(); ?&gt;member/book'" /&gt;
      &lt;/div&gt;
      &lt;table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%"&gt;
          &lt;?php if ($cart = $this-&gt;cart-&gt;contents()): ?&gt;
          &lt;tr bgcolor="#FFFFFF" style="font-weight:bold"&gt;
              &lt;th&gt;Item No&lt;/th&gt;
              &lt;th&gt;Book Name&lt;/th&gt;
              &lt;th&gt;Price&lt;/th&gt;
              &lt;th&gt;Quantity&lt;/th&gt;
              &lt;th&gt;Sub-Total&lt;/th&gt;
              &lt;th&gt;Remove&lt;/th&gt;
          &lt;/tr&gt;
          &lt;?php
          echo form_open('cart/update_cart');
          $grand_total = 0; $i = 1;
  
          foreach ($cart as $item):
              echo form_hidden('cart['. $item['id'] .'][id]', $item['id']);
              echo form_hidden('cart['. $item['id'] .'][rowid]', $item['rowid']);
              echo form_hidden('cart['. $item['id'] .'][name]', $item['name']);
              echo form_hidden('cart['. $item['id'] .'][price]', $item['price']);
              echo form_hidden('cart['. $item['id'] .'][qty]', $item['qty']);
          ?&gt;
          &lt;tr bgcolor="#FFFFFF"&gt;
              &lt;td&gt;
                  &lt;?php echo $i++; ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;?php echo $item['name']; ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  $ &lt;?php echo number_format($item['price'],2); ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;?php echo form_input('cart['. $item['id'] .'][qty]', $item['qty'], 'maxlength="3" size="1" style="text-align: right"'); ?&gt;
              &lt;/td&gt;
              &lt;?php $grand_total = $grand_total + $item['subtotal']; ?&gt;
              &lt;td&gt;
                  $ &lt;?php echo number_format($item['subtotal'],2) ?&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;a href="&lt;?php echo base_url(); ?&gt;cart/remove/&lt;?php echo $item['rowid'] ?&gt;" style="color:#000000;"&gt;Remove&lt;/a&gt;
              &lt;/td&gt;
              &lt;?php endforeach; ?&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;b&gt;Grand Total: $&lt;?php echo number_format($grand_total,2); ?&gt;&lt;/b&gt;&lt;/td&gt;
              &lt;td colspan="5" align="right"&gt;&lt;input type="button" value="Clear Cart" onclick="clear_cart()"&gt;
                      &lt;input type="submit" value="Update Cart"&gt;
                      &lt;?php echo form_close(); ?&gt;
  
                      &lt;input type="button" value="Checkout" onclick="window.location='&lt;?php echo base_url(); ?&gt;payment/checking'"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php endif; ?&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the paypal controller code:</p>
  
  <p>
  
  <pre><code>public function __construct(){
      parent::__construct();
      $this-&gt;load-&gt;library('session');
      $this-&gt;load-&gt;library('cart');
      $this-&gt;load-&gt;helper('url');
      $this-&gt;load-&gt;helper('form');
      if (! $this-&gt;session-&gt;userdata('is_logged_in')){
          redirect('main/restricted');
      } else {
      $privilege = $this-&gt;session-&gt;userdata('privilege');
      if ($privilege == 'admin'){
          redirect('main/restricted');
      }
      }
      $this-&gt;load-&gt;helper("string");
  }
  
  public function do_purchase(){
      $config['business']             = 'phptesting2015-facilitator@gmail.com';
      $config['cpp_header_image']     = ''; //Image header url [750 pixels wide by 90 pixels high]
      $config['return']               = 'https://snt.website/ignite_project/payment/notify_purchase';
      $config['cancel_return']        = 'https://snt.website/ignite_project/payment/cancel_purchase';
      $config['notify_url']           = 'process_payment.php'; //IPN Post
      $config['production']           = FALSE; //Its false by default and will use sandbox
      //$config['discount_rate_cart']     = 20; //This means 20% discount
      $config["invoice"]              = random_string('numeric', 8); //The invoice id
  
      $this-&gt;load-&gt;library('paypal',$config);
  
      #$this-&gt;paypal-&gt;add(&lt;name&gt;,&lt;price&gt;,&lt;quantity&gt;[Default 1],&lt;code&gt;[Optional]);
  
      //$this-&gt;paypal-&gt;add('T-shirt',2.99,6); //First item
      //$this-&gt;paypal-&gt;add('Pants',40);     //Second item
      //$this-&gt;paypal-&gt;add('Blowse',10,10,'B-199-26'); //Third item with code
  
      $this-&gt;paypal-&gt;pay(); //Proccess the payment
  }
  
  public function notify_purchase(){
      $received_data = print_r($this-&gt;input-&gt;post(), TRUE);
  
      echo "&lt;pre&gt;".$received_data."&lt;/pre&gt;";
  }
  
  public function cancel_purchase(){
      echo "Cancel Purchase";
  
  }
  
  }
  </code></pre>
  
  <p>I am wondering how would i be able to get the data from the cart, so that i would be able to add the value in paypal so that the user will be able to proceed with the paypal? Please help!</p>