Welcome Guest, Not a member yet? Register   Sign In
Shop Cart based on cookie
#1

[eluser]penta997[/eluser]
Hi. I've made a shop carts. It works when I add a item to cart, but when I'm try delete items, it doesnt work. Is there possibility to call 2 function in the same time?
This im my controller:
Code:
function addCards($segment=1, $price='')
           {

            $id= mysql_real_escape_string(HTMLSpecialChars(addslashes($segment)));
            setcookie("cookie[$id]", 1, time()+3600*2, '/', '', '0');
            //echo 'value2 '.$value2.'- value1 '.$value1.'= value '.$value;
            redirect('koszyk/actual_price');
            
          }



function actual_price()
{
  $zakupy = 0;
  if (isset($_COOKIE['cookie']))
   {
   foreach ($_COOKIE['cookie'] as $name => $value)
   {


   $query = $this->Kategorie_model->get_books_by_ID(mysql_real_escape_string(HTMLSpecialChars(addslashes($name))));
    if($query->num_rows >0)
    {
    foreach($query->result() as $item)
    {
    $cena = $item->BOOK_Price;
    }
    $zakupy += $cena*$value;
   }
}
}

else
{
     $zakupy = 0;
}
  
  
  return number_format($zakupy,2, '.', '');

}



function actual_qty()
{
      $ilosc = 0;
  
  if (isset($_COOKIE['cookie']))
   {
   foreach ($_COOKIE['cookie'] as $name => $value)
   {
       $ilosc +=$value;
   }
}



  else
  {
      $ilosc = 0;
  }

  return $ilosc;

}




function order_product()
{
            $widok['left'] = $this->get_category();
             $widok['right'] = $this->get_bestseller();
            $widok['zakupy'] = $this->actual_price();
             $widok['licznik'] = $this->actual_qty();
             $widok['tytul'] = 'Twoj koszyk';
             $pozycja = 0;

             $widok['center'] ='
            <table class="basket">
              <tr>
              <th>Pozycja</th>
              <th style="text-align: center;">Nazwa</th>
              <th>Ilość</th><th>Cena brutto</th><th>Wartość</th>
              <th>Usuń</th>
              </tr>';

     if (isset($_COOKIE['cookie']))
     {
        foreach ($_COOKIE['cookie'] as $name => $value)
        {
                $pozycja++;
                $query = $this->Kategorie_model->get_books_by_ID($name);
                $widok['center'] .= $this->load->view('Ksiegarnia/order_product_view', array('data' => $query,'pozycja' =>$pozycja,'ilosc'=>$value),True);
                
        }

     }

     else
     {
          $widok['center'] .= $this->load->view('Ksiegarnia/order_product_view_empty', '',True);

     }
     $widok['center'] .='</table>&lt;/form&gt;';

     $this->load->view('Ksiegarnia/index_logged',$widok);
}




function change_qty()
{
$id= mysql_real_escape_string(HTMLSpecialChars(addslashes($this->uri->segment(3))));
$ilosc = mysql_real_escape_string(HTMLSpecialChars(addslashes($this->input->post('produkt_'.$id))));


if($ilosc > 0 AND is_numeric($ilosc))
  {
    
            

            if(isset($ilosc) and is_numeric($ilosc))
            {
                setcookie("cookie[$id]", "$ilosc", time()+3600*2, '/', '', '0');
            }
            redirect('koszyk/actual_price');
            
        
      
  }
else
  {
  redirect('koszyk/order_product');
  }
}


      function deleteCards($segment = 1)
       {




              $id= mysql_real_escape_string(HTMLSpecialChars(addslashes($segment)));
              setcookie("cookie[$id]", NULL, time()-172800, '/', '', '0');
             redirect($_SERVER['HTTP_REFERER']);
              
              
       }
#2

[eluser]skunkbad[/eluser]
Why are you doing this? If you want a shopping cart that uses cookies, just extend the existing Cart class. I extended the Cart class in my Community Cart application. It uses $_SESSION, but you could do something similar for cookies. $_SESSION actually uses a cookie as an identifier, and stores the cart contents on the server.




Theme © iAndrew 2016 - Forum software by © MyBB