Dane koszyka trzymane sa w tablicy z $_SESSION['koszyk'][ID_ELEMENTU] a wartosc poszczegolnej komorki okresla ZAMOWIONA_ILOSC. Np.
<?php $_SESSION['koszyk'][1] = 20; $_SESSION['koszyk'][2] = 10; ?>
Nie wiedzialem za bardzo jak rozwiazac kwestie pobierania danych o towarach bedacych w koszyku wiec getData() i polaczenie ze SQL w niej jest tymczasowe

Oto moja klasa:
<?php class Basket { public $basket; public $sum; public $countItems; public $basketHandler; public function Basket() { $this->__construct(); } public function __construct() { $this->basketHandler = &$_SESSION['koszyk']; } public function addItem($itemID, $itemAmount) { $this->basketHandler[$itemID] += $itemAmount; else $this->basketHandler[$itemID] = $itemAmount; } public function getData() { $this->sum = 0; foreach ($this->basketHandler as $index => $value) $arrayTemp[] = $index; { { $i = 0; { $this->basket[$i]['id'] = $record[0]; $this->basket[$i]['name'] = $record[1]; $this->basket[$i]['amount'] = $this->basketHandler[$record[0]]; $this->basket[$i]['vat'] = $record[3]; $this->basket[$i]['grossPrice'] = number_format(($this->basket[$i]['netPrice'] + $this->basket[$i]['netPrice'] * $this->basket[$i]['vat'] / 100), 2); $this->basket[$i]['netValue'] = number_format(($this->basket[$i]['netPrice'] * $this->basket[$i]['amount']), 2); $this->basket[$i]['grossValue'] = number_format(($this->basket[$i]['grossPrice'] * $this->basket[$i]['amount']), 2); $this->sum += $this->basket[$i]['grossValue']; $i++; } $this->countItems = $i; } } } public function showBasket() { if ($this->countItems() > 0) { $return = "<table border="1">n"; $return .= "<tr><td>Nazwa:</td><td>Cena netto:</td><td>VAT:</td><td>Cena brutto:</td><td>Ilosc:</td><td>Wartosc netto:</td><td>Wartosc brutto:</td></tr>n"; foreach ($this->basket as $index => $value) $return .= "<tr><td>".$this->basket[$index]['name']."</td><td>".$this->basket[$index]['netPrice']."</td><td>".$this->basket[$index]['vat']."</td><td>".$this->basket[$index]['grossPrice']."</td><td>".$this->basket[$index]['amount']."</td><td>".$this->basket[$index]['netValue']."</td><td>".$this->basket[$index]['grossValue']."</td></tr>n"; $return .= "<tr><td colspan="6" style="text-align: right;">Do zaplaty:</td><td>".$this->sum."</td></tr>n"; $return .= "</table>"; return $return; } } public function countItems() { return $return; } public function getSum() { $this->getData(); return $this->sum; } public function emptyBasket() { foreach ($this->basketHandler as $index => $value) } } ?>
Prosze o porady i sugestie co w niej zmienic, co dopisac itp. Z gory serdeczne dzieki!