Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是否可以在codeigniter中更新购物车数量中的所有字段以及其他字段,如大小、品牌和其他价值库_Codeigniter_Continuous Integration_Cart - Fatal编程技术网

我是否可以在codeigniter中更新购物车数量中的所有字段以及其他字段,如大小、品牌和其他价值库

我是否可以在codeigniter中更新购物车数量中的所有字段以及其他字段,如大小、品牌和其他价值库,codeigniter,continuous-integration,cart,Codeigniter,Continuous Integration,Cart,我是否可以在CodeIgniter中更新购物车数量中的所有字段以及大小、品牌和其他价值库等其他字段 这是我的控制器 function update_cart(){ foreach($_POST['cart'] as $id => $cart) { $price = $cart['price']; $amount = $price * $cart['qty']; $sold_weight = $cart[

我是否可以在CodeIgniter中更新购物车数量中的所有字段以及大小、品牌和其他价值库等其他字段

这是我的控制器

function update_cart(){

    foreach($_POST['cart'] as $id => $cart)
    {           
        $price = $cart['price'];
        $amount = $price * $cart['qty'];
        $sold_weight = $cart['sold_weight'];

        $data = $this->cart_model->update_cart($cart['rowid'], $cart['qty'], $sold_weight, $price,  $amount);
         print_r($data); die();

    }
    $this->session->set_flashdata('success','Cart is update.');
    redirect('carts/view_cart');
}
这是我的模态

function update_cart ($rowid, $qty, $sold_weight, $price, $amount) 
{
    $data = array(
        'rowid'   => $rowid,
        'qty'     => $qty,
        'sold_weight' => $sold_weight,
        'price'   => $price,
        'amount'   => $amount
    );

    $this->cart->update($data);
}
我还更新了购物车的售出重量

类MY_Cart扩展CI_Cart { //回音“嗨”;die()

}

function __construct()
{
    // parent::CI_Cart();
     parent::__construct();
}



function update_all($items = array())
{
    // Was any cart data passed?
    if ( ! is_array($items) OR count($items) == 0)
    {
        return false;
    }

    // You can either update a single product using a one-dimensional array,
    // or multiple products using a multi-dimensional one.  The way we
    // determine the array type is by looking for a required array key named "rowid".
    // If it's not found we assume it's a multi-dimensional array
    if (isset($items['rowid']))
    {
        $this->_update_item($items);
    }
    else
    {
        foreach($items as $item)
        {
            $this->_update_item($item);
        }
    }

    $this->_save_cart();
}

/*
 * Function: _update_item
 * Param: Array with a rowid and information about the item to be updated
 *             such as qty, name, price, custom fields.
 */
function _update_item($item)
{
    foreach($item as $key => $value)
    {
        //don't allow them to change the rowid
        if($key == 'rowid')
        {
            continue;
        }

        //do some processing if qty is
        //updated since it has strict requirements
        if($key == "qty")
        {
            // Prep the quantity
            $item['qty'] = preg_replace('/([^0-9])/i', '', $item['qty']);

            // Is the quantity a number?
            if ( ! is_numeric($item['qty']))
            {
                continue;
            }

            // Is the new quantity different than what is already saved in the cart?
            // If it's the same there's nothing to do
            if ($this->_cart_contents[$item['rowid']]['qty'] == $item['qty'])
            {
                continue;
            }

            // Is the quantity zero?  If so we will remove the item from the cart.
            // If the quantity is greater than zero we are updating
            if ($item['qty'] == 0)
            {
                unset($this->_cart_contents[$item['rowid']]);
                continue;
            }
        }

        $this->_cart_contents[$item['rowid']][$key] = $value;
    }
}