Welcome Guest, Not a member yet? Register   Sign In
Shopping Cart not working properly
#1

[eluser]YellowShadow[/eluser]
Hey Guys,

I'm trying to add items to the shopping cart but it will only add the first 6 items to the cart. The rest don't seem to get added.

I've checked the arrays and they have the required id, qty, price, and name. What am I doing wrong?

Here is the code:
Code:
public function ShowKit($id)
    {
        $query = $this->EngineKitsModel->GetKitParts($id);
        $data['kitInfo'] = $query;
        
        $cartArray = array();
        
        $i = 0;
        
        foreach ($query->result() as $row)
        {
            $i++;
            $partArray = array(
                'id' => $row->altpart,
                'price' => $row->price,
                'name' => $row->altpart,
            );
            
            $cartArray[] = $partArray;
        }
        
        $this->session->unset_userdata('products');
        $this->session->unset_userdata('kitCount');
        
        $this->session->set_userdata('products', $cartArray);
        $this->session->set_userdata('kitCount', $i);
        
        $data['main_content'] = 'showkit';
        
        $this->load->view('includes/template', $data);
    }
    
    public function AddKitToCart()
    {
        $cartArray = $this->session->userdata('products');
        $kitCount = $this->session->userdata('kitCount');
        
        for ($i = 0; $i < $kitCount; $i++)
        {
            $qtyNum = $i + 1;
            
            $partArray = $cartArray[$i];
            $partArray['qty'] = $this->input->post('qty'.$qtyNum);
            
            $this->cart->insert($partArray);
        }
        
        $this->session->unset_userdata('products');
        $this->session->unset_userdata('kitCount');
        
        $data['main_content'] = 'addedtocart';
        $this->load->view('includes/template', $data);
    }

In the first function the array is created without the qty field. This is because when the showkit view is shown, users will get to 'review' what is going into their shopping cart and make qty changes. The second function is called when the user clicks submit on the showkit form. This then goes through the array and adds the appropriate qtys.

I'm using the session class to hold the array.

Any ideas?

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB