1 | <?php |
---|
2 | /** |
---|
3 | * Cart.inc.php |
---|
4 | * code by strangecode :: www.strangecode.com :: this document contains copyrighted information |
---|
5 | * |
---|
6 | * Class description goes here... |
---|
7 | * |
---|
8 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
9 | * @version 1.0 |
---|
10 | * |
---|
11 | * Example of use: |
---|
12 | --------------------------------------------------------------------- |
---|
13 | ... |
---|
14 | --------------------------------------------------------------------- |
---|
15 | */ |
---|
16 | class Cart { |
---|
17 | |
---|
18 | // Namespace of this instance. |
---|
19 | var $_ns; |
---|
20 | |
---|
21 | // Configuration parameters for this object. |
---|
22 | var $_params = array( |
---|
23 | ); |
---|
24 | |
---|
25 | /** |
---|
26 | * Cart constructor. |
---|
27 | */ |
---|
28 | function Cart($namespace='') |
---|
29 | { |
---|
30 | $app =& App::getInstance(); |
---|
31 | |
---|
32 | $this->_ns = $namespace; |
---|
33 | |
---|
34 | // Initialize. |
---|
35 | if (!isset($_SESSION['_cart'][$this->_ns])) { |
---|
36 | $this->clear(); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * Set the params of this object. |
---|
42 | * |
---|
43 | * @param array $params Array of param keys and values to set. |
---|
44 | */ |
---|
45 | function setParam($params=null) |
---|
46 | { |
---|
47 | if (isset($params) && is_array($params)) { |
---|
48 | // Merge new parameters with old overriding only those passed. |
---|
49 | $this->_params = array_merge($this->_params, $params); |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Return the value of a parameter, if it exists. |
---|
55 | * |
---|
56 | * @access public |
---|
57 | * @param string $param Which parameter to return. |
---|
58 | * @return mixed Configured parameter value. |
---|
59 | */ |
---|
60 | function getParam($param) |
---|
61 | { |
---|
62 | $app =& App::getInstance(); |
---|
63 | |
---|
64 | if (isset($this->_params[$param])) { |
---|
65 | return $this->_params[$param]; |
---|
66 | } else { |
---|
67 | $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); |
---|
68 | return null; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * |
---|
74 | * |
---|
75 | * @access public |
---|
76 | * @param |
---|
77 | * @return |
---|
78 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
79 | * @version 1.0 |
---|
80 | * @since 11 Mar 2008 18:59:37 |
---|
81 | */ |
---|
82 | function add($item_id, $quantity=1) |
---|
83 | { |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | /* |
---|
88 | * |
---|
89 | * |
---|
90 | * @access public |
---|
91 | * @param |
---|
92 | * @return |
---|
93 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
94 | * @version 1.0 |
---|
95 | * @since 11 Mar 2008 18:59:48 |
---|
96 | */ |
---|
97 | function remove($item_id) |
---|
98 | { |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * |
---|
104 | * |
---|
105 | * @access public |
---|
106 | * @param |
---|
107 | * @return |
---|
108 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
109 | * @version 1.0 |
---|
110 | * @since 11 Mar 2008 18:59:55 |
---|
111 | */ |
---|
112 | function getList() |
---|
113 | { |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | /* |
---|
118 | * |
---|
119 | * |
---|
120 | * @access public |
---|
121 | * @param |
---|
122 | * @return |
---|
123 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
124 | * @version 1.0 |
---|
125 | * @since 11 Mar 2008 19:00:12 |
---|
126 | */ |
---|
127 | function getTotal() |
---|
128 | { |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * Resets the $_SESSION cart array. This should be executed with the same consideration |
---|
134 | * as $auth->clear(), such as when logging out. |
---|
135 | */ |
---|
136 | function clear() |
---|
137 | { |
---|
138 | $_SESSION['_cart'][$this->_ns] = array( |
---|
139 | 'items' => array(), |
---|
140 | ); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | ?> |
---|