Codeigniter购物车无法添加项目 [英] Codeigniter Cart cannot add items

查看:69
本文介绍了Codeigniter购物车无法添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图用购物车创建一个应用程序,当我尝试添加商品时,它无法正常工作。顺便说一句,我已经有一个有效的购物车应用程序,这就是为什么我想知道为什么它无法正常工作的原因。我几乎复制了工作中的所有内容。这是代码

So i'm trying to create an application with cart and when i tried adding the item, it's not working. By the way i already have a working cart application that's why i'm wondering why it's not working. I almost copied everything from the working one. here's the code

购物车控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cart extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->library('cart');
}

public function add_to_cart(){

    $id = $this->uri->segment(3);
    if($this->cart->contents()){
        foreach ($this->cart->contents() as $item){
            if ($item['id']==$id){
                $data = array('rowid'=>$item['rowid'],
                    'qty'=>++$item['qty']);
                $process = $this->cart->update($data);
            }
            else{
                $data = array(
                    'id'=>$id,
                    'qty'=>1,                       
                    'name' => $this->get_data->get_value('product_name','products','product_id', $id),
                    'price' => $this->get_data->get_value('product_price','products','product_id', $id)
                    );
                $process = $this->cart->insert($data);
            }
        }
    }
    else{
        $data = array('id'=>$id,
                    'qty' =>1,
                    'name' => $this->get_data->get_value('product_name','products','product_id', $id),
                    'price' => $this->get_data->get_value('product_price','products','product_id', $id),
                    );
                    $process = $this->cart->insert($data);
    }


    if($process){
        $this->session->set_flashdata('success', 'Successful');
        redirect('products');
    }
    else{
        $this->session->set_flashdata('failed', 'Failed');
        redirect('products');
        //var_dump($process);
    }
}

这里是按钮

<div class="button pull-right" style="margin-top: 10px;"><a href="<?php echo base_url().'cart/add_to_cart/'.$row->product_id;?>"><span class="glyphicon glyphicon-shopping-cart"></span>Add to Cart</a></div>

我真的看不到问题,我正在使用会话数据库,sess_us_database已经为TRUE 。我尝试使用 var_dump($ process),这是错误的,我尝试了 var_dump($ data)并且数据似乎很好,但是插入部分无法正常工作。有想法吗?

I really can't see the problem, i'm using session database, the sess_us_database is already TRUE. I tried using var_dump($process) and it's false, i tried var_dump($data) and the data seems to be fine but the insert part isn't working. Any idea guys? it would be a big help for me, thank you.

推荐答案

CI默认默认购物车仅允许 alpha-产品名称中的数字,破折号,下划线,冒号或点号,并且如果产品价格为 0 ,那么该产品也不会添加到购物车中。

CI Default cart allows only alpha-numeric, dashes, underscores, colons or periods in Product Name and If Price of product is 0 then also it will not add the product to cart.

请先检查一下。

这篇关于Codeigniter购物车无法添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆