1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php class Cart { var $str; var $productsArr;
function Cart($str) { $this->str = $str; if($str!="") $this->productsArr = explode(";", $str); else $this->productsArr = array(); }
function AddProduct($prodId, $quantity = 1) { // product,quantity;product,quantity $count = count($this->productsArr); for($i = 0; $i < $count; $i++) { $prodSp = explode(",", $this->productsArr[$i]); if($prodSp[0] == $prodId) { if($quantity == $prodSp[1]) return; if($quantity == 0) { $prodStr = ""; } else $prodStr = $prodId . "," . $quantity; $this->productsArr[$i] = $prodStr; return; } } $this->productsArr[]=$prodId . "," . $quantity; }
function GetCartStr() { $s = ""; foreach($this->productsArr as $product) { if($product != "") $s.=$product.";"; } return $s; } } ?>
|