簡體   English   中英

如何在Payign付款網關的Codeigniter中獲取購物車值

[英]how to get cart values in codeigniter for paypal payment gateway

我被困在在codeigniter上集成貝寶支付網關我正在使用當前庫https://github.com/romaldyminaya/ci_paypal

由於該庫僅包含這些商品的靜態值,但是我需要從購物車中獲取這些商品,因此如何將它們添加到$ this-> paypal-> add('T-shirt',2.99,6 );

我的控制器功能:

    public function do_purchase(){

    $config['business']             = 'babar.seller@gmail.com';
        $config['cpp_header_image']     = ''; //Image header url [750 pixels wide by 90 pixels high]
        $config['return']               = 'http://localhost/final-project/index.php/mysite/modify_payment';
        $config['cancel_return']        = 'http://final-project/mysite/canceled.php';
        $config['notify_url']           = 'process_payment.php'; //IPN Post
        $config['production']           = FALSE; //Its false by default and will use sandbox
        $config["invoice"]              = random_string('numeric',8); //The invoice id

        $this->load->library('paypal',$config);

        #$this->paypal->add(<name>,<price>,<quantity>[Default 1],<code>[Optional]);

        $this->paypal->add('T-shirt',2.99,6); //First item
        $this->paypal->add('Pants',40);       //Second item
        $this->paypal->add('Blowse',10,10,'B-199-26'); //Third item with code


        $this->paypal->pay(); //Proccess the payment

    }

    public function modify_payment(){


        $received_data = print_r($this->input->post(),TRUE);
        echo "<pre>".$received_data."<pre>";

                $this->load->view('mysite/modify_payment',$received_data);

        }

public function cart()

    {
        $cart = $this->cart->contents();
        //print_r($cart);
        //die;
      //$data['user_id']=$this->mainmodel->get_user_i($user_id);    

        $this->load->view('mysite/cart');
        $this->load->view('mysite/include/footer');


    }

購物車視圖:

    <?php $i = 1; ?>

<?php foreach ($this->cart->contents() as $items): ?>

    <?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
    <tr>
<td>         <input name="qty[<?php echo $items['rowid'];?>]" id="qty" type="text" value="<?php echo $items['qty']?>" class="input" />
</td>
      <td>
        <?php echo $items['name']; ?>

            <?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>

                <p>
                    <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>

                        <strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />

                    <?php endforeach; ?>
                </p>

            <?php endif; ?>
function add($item_name = '',$item_amount = NULL,$item_qty = NULL,$item_number = NULL){
        $this->config['item_name_'.$this->item]     = $item_name;
        $this->config['amount_'.$this->item]        = $item_amount;
        $this->config['quantity_'.$this->item]      = $item_qty;
        $this->config['item_number_'.$this->item]   = $item_number;
        $this->item++;
    }   

我所做的是有一個貝寶庫類來處理添加項,而只是對某些產品進行了硬編碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM