Bardzo wielka prośba o pomoc. Ponieważ ta aplikacja musi do jutra dzialać :/ Problem polega na tym ze w momencie kiedy zmieniam ilosc sztuk w koszyku, rzecz dotyczy malego sklepu, to raz cookie mi sie nadpisuje z iloscia i wyswietla dobra wartosc a raz mi sie nie nadpisuje....
kontroler:
//zmienia ilosc i nadpisuje cookie
function zmien_ilosc()
{
$id= mysql_real_escape_string(HTMLSpecialChars(addslashes($this->uri->segment(3))));
$ilosc = mysql_real_escape_string(HTMLSpecialChars(addslashes($this->input->post('produkt_'.$id))));
$shop_count = $this->db->query("select BOOK_Count from books where BOOK_ID = $id")->row()->BOOK_Count;
if($ilosc > 0 AND is_numeric($ilosc) AND $ilosc <= $shop_count)
{
if(isset($ilosc) and is_numeric($ilosc))
{
setcookie("cookie[$id]", "$ilosc", time()+3600*2, '/', '', '0');
}
redirect('site/order_product');
}
else
{
echo '<script type="text/javascript">alert("Nie ma tylu produkuktow");</script>';
echo '<META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url().'/site/order_product">';
}
}
//wyswietla dane z koszyka
function order_product()
{
$widok['left'] = $this->get_category();
$widok['right'] = $this->get_bestseller();
$widok['zakupy'] = $this->sum_all();
$widok['licznik'] = $this->counter();
$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></br><a href="'.site_url('site/order_details').'">Złóż zamówienie</a>';
$this->load->view('Ksiegarnia/index_logged',$widok);
}
widok wyswietlajacy dane:
<?php foreach($data->result() as $item)
{
echo
form_open('site/zmien_ilosc/'.$item->BOOK_ID).
'<tr>
<td>'.$pozycja.'</td>
<td>'.$item->BOOK_Title.'</td>
<td><input type ="text" class ="tekst" name="produkt_'.$item->BOOK_ID.'" value="'.$ilosc.'"/>
<input type="submit" class="sub" value = "Zmien"/>
</td>';
if($item->BOOK_IsPromo == 0)
{
echo
'<td>'.number_format($item->BOOK_Price,2, '.', '').'zł</td>
<td>'.number_format($item->BOOK_Price*$ilosc,2, '.', '').'zł</td><td>'.anchor('koszyk/deleteCards/'.$item->BOOK_ID,'X').'</td>';
}
else
{
echo
'<td>'.number_format($item->BOOK_Price-$item->BOOK_PromoValue,2, '.', '').'zł</td>
<td>'.number_format(($item->BOOK_Price-$item->BOOK_PromoValue)*$ilosc,2, '.', '').'zł</td><td>'.anchor('koszyk/deleteCards/'.$item->BOOK_ID,'X').'</td>';
}
'</tr>'
.form_close();
}
?>