doumuyu0837 2014-09-15 07:04
浏览 12

代码点火器购物车类无法存储更多然后在项目上

I am using codeigniter cart class, when I insert new product to it, overrides existing products below I my code and output please guide me what's wrong with my code. live test URL is http://outlets.pk/outlets/items_controller/add_to_cart/12/2 http://outlets.pk/outlets/items_controller/add_to_cart/11/2 http://outlets.pk/outlets/items_controller/add_to_cart/id/qty

What I am doing: if we change id then items must be increase in cart.

its properly working on localhost but when I move it on Live hosting it behave unexpectedly.

Problem:
items_controller/add_to_cart URL is used to add item into cart but when I insert new item into cart and then try to access on other action it returns empty array.

SESSIONS are Not working on shared hosting server.

This is my functions:

public function add_to_cart($product_id,$qty){
        $result=$this->items_model->get_items_id($product_id);
        $cart_item=$this->items_model->is_exist($this->cart->contents(),$product_id);
        if($cart_item!=NULL){

            $this->cart->update(array(

                'rowid'=> $cart_item['rowid'],
                'qty'=> $cart_item['qty']+$qty,
            ));
        }
        else{
            $this->cart->insert(array(
                'id'=> $result[0]['product_id'],
                'name'=> $result[0]['product_name'],
                'qty'=> $qty,
                'price'=>$result[0]['product_price'],
                'product_sku'=>$result[0]['product_sku']
            ));
        }

        $this->randerCart();


    }

Is_exist function code:

public function is_exist($cart_content,$id){
    foreach($cart_content as $c_i){

        if($c_i['id']===$id){

            return $c_i;
        }
    }
    return NULL;
}

Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 关于php中URL传递GET全局变量的问题
    • ¥15 怎么改成循环输入删除(语言-c语言)
    • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
    • ¥15 pyqt5tools安装失败
    • ¥15 mmdetection
    • ¥15 nginx代理报502的错误
    • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
    • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
    • ¥100 描述一下元器件的基本功能,pcba板的基本原理
    • ¥15 STM32无法向设备写入固件