Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ################### |
| 2 | Shopping Cart Class |
| 3 | ################### |
| 4 | |
| 5 | The Cart Class permits items to be added to a session that stays active |
| 6 | while a user is browsing your site. These items can be retrieved and |
| 7 | displayed in a standard "shopping cart" format, allowing the user to |
| 8 | update the quantity or remove items from the cart. |
| 9 | |
Andrey Andreev | e3d66af | 2015-01-19 14:51:37 +0200 | [diff] [blame] | 10 | .. important:: The Cart library is DEPRECATED and should not be used. |
Andrey Andreev | 21c3c22 | 2014-12-04 12:10:00 +0200 | [diff] [blame] | 11 | It is currently only kept for backwards compatibility. |
| 12 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 13 | Please note that the Cart Class ONLY provides the core "cart" |
| 14 | functionality. It does not provide shipping, credit card authorization, |
| 15 | or other processing components. |
| 16 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 17 | .. contents:: |
| 18 | :local: |
| 19 | |
| 20 | .. raw:: html |
| 21 | |
| 22 | <div class="custom-index container"></div> |
| 23 | |
| 24 | ******************** |
| 25 | Using the Cart Class |
| 26 | ******************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | |
| 28 | Initializing the Shopping Cart Class |
| 29 | ==================================== |
| 30 | |
| 31 | .. important:: The Cart class utilizes CodeIgniter's :doc:`Session |
| 32 | Class <sessions>` to save the cart information to a database, so |
| 33 | before using the Cart class you must set up a database table as |
| 34 | indicated in the :doc:`Session Documentation <sessions>`, and set the |
| 35 | session preferences in your application/config/config.php file to |
| 36 | utilize a database. |
| 37 | |
| 38 | To initialize the Shopping Cart Class in your controller constructor, |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 39 | use the ``$this->load->library()`` method:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 40 | |
| 41 | $this->load->library('cart'); |
| 42 | |
| 43 | Once loaded, the Cart object will be available using:: |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 44 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 45 | $this->cart |
| 46 | |
| 47 | .. note:: The Cart Class will load and initialize the Session Class |
| 48 | automatically, so unless you are using sessions elsewhere in your |
| 49 | application, you do not need to load the Session class. |
| 50 | |
| 51 | Adding an Item to The Cart |
| 52 | ========================== |
| 53 | |
| 54 | To add an item to the shopping cart, simply pass an array with the |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 55 | product information to the ``$this->cart->insert()`` method, as shown |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 56 | below:: |
| 57 | |
| 58 | $data = array( |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 59 | 'id' => 'sku_123ABC', |
| 60 | 'qty' => 1, |
| 61 | 'price' => 39.95, |
| 62 | 'name' => 'T-Shirt', |
| 63 | 'options' => array('Size' => 'L', 'Color' => 'Red') |
| 64 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 65 | |
| 66 | $this->cart->insert($data); |
| 67 | |
| 68 | .. important:: The first four array indexes above (id, qty, price, and |
| 69 | name) are **required**. If you omit any of them the data will not be |
| 70 | saved to the cart. The fifth index (options) is optional. It is intended |
| 71 | to be used in cases where your product has options associated with it. |
| 72 | Use an array for options, as shown above. |
| 73 | |
| 74 | The five reserved indexes are: |
| 75 | |
| 76 | - **id** - Each product in your store must have a unique identifier. |
| 77 | Typically this will be an "sku" or other such identifier. |
| 78 | - **qty** - The quantity being purchased. |
| 79 | - **price** - The price of the item. |
| 80 | - **name** - The name of the item. |
| 81 | - **options** - Any additional attributes that are needed to identify |
| 82 | the product. These must be passed via an array. |
| 83 | |
| 84 | In addition to the five indexes above, there are two reserved words: |
| 85 | rowid and subtotal. These are used internally by the Cart class, so |
| 86 | please do NOT use those words as index names when inserting data into |
| 87 | the cart. |
| 88 | |
| 89 | Your array may contain additional data. Anything you include in your |
| 90 | array will be stored in the session. However, it is best to standardize |
| 91 | your data among all your products in order to make displaying the |
| 92 | information in a table easier. |
| 93 | |
Ahmad Anbar | 576439f | 2014-02-13 06:16:31 +0200 | [diff] [blame] | 94 | :: |
| 95 | |
| 96 | $data = array( |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 97 | 'id' => 'sku_123ABC', |
| 98 | 'qty' => 1, |
| 99 | 'price' => 39.95, |
| 100 | 'name' => 'T-Shirt', |
| 101 | 'coupon' => 'XMAS-50OFF' |
| 102 | ); |
Ahmad Anbar | 576439f | 2014-02-13 06:16:31 +0200 | [diff] [blame] | 103 | |
| 104 | $this->cart->insert($data); |
| 105 | |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 106 | The ``insert()`` method will return the $rowid if you successfully insert a |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 107 | single item. |
| 108 | |
| 109 | Adding Multiple Items to The Cart |
| 110 | ================================= |
| 111 | |
| 112 | By using a multi-dimensional array, as shown below, it is possible to |
| 113 | add multiple products to the cart in one action. This is useful in cases |
| 114 | where you wish to allow people to select from among several items on the |
| 115 | same page. |
| 116 | |
| 117 | :: |
| 118 | |
| 119 | $data = array( |
Andrey Andreev | 81f0367 | 2014-02-13 17:57:41 +0200 | [diff] [blame] | 120 | array( |
| 121 | 'id' => 'sku_123ABC', |
| 122 | 'qty' => 1, |
| 123 | 'price' => 39.95, |
| 124 | 'name' => 'T-Shirt', |
| 125 | 'options' => array('Size' => 'L', 'Color' => 'Red') |
| 126 | ), |
| 127 | array( |
| 128 | 'id' => 'sku_567ZYX', |
| 129 | 'qty' => 1, |
| 130 | 'price' => 9.95, |
| 131 | 'name' => 'Coffee Mug' |
| 132 | ), |
| 133 | array( |
| 134 | 'id' => 'sku_965QRS', |
| 135 | 'qty' => 1, |
| 136 | 'price' => 29.95, |
| 137 | 'name' => 'Shot Glass' |
| 138 | ) |
| 139 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 140 | |
| 141 | $this->cart->insert($data); |
| 142 | |
| 143 | Displaying the Cart |
| 144 | =================== |
| 145 | |
| 146 | To display the cart you will create a :doc:`view |
| 147 | file </general/views>` with code similar to the one shown below. |
| 148 | |
| 149 | Please note that this example uses the :doc:`form |
| 150 | helper </helpers/form_helper>`. |
| 151 | |
| 152 | :: |
| 153 | |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 154 | <?php echo form_open('path/to/controller/update/method'); ?> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 155 | |
| 156 | <table cellpadding="6" cellspacing="1" style="width:100%" border="0"> |
| 157 | |
| 158 | <tr> |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 159 | <th>QTY</th> |
| 160 | <th>Item Description</th> |
| 161 | <th style="text-align:right">Item Price</th> |
| 162 | <th style="text-align:right">Sub-Total</th> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 163 | </tr> |
| 164 | |
| 165 | <?php $i = 1; ?> |
| 166 | |
| 167 | <?php foreach ($this->cart->contents() as $items): ?> |
| 168 | |
| 169 | <?php echo form_hidden($i.'[rowid]', $items['rowid']); ?> |
| 170 | |
| 171 | <tr> |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 172 | <td><?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td> |
| 173 | <td> |
| 174 | <?php echo $items['name']; ?> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 175 | |
| 176 | <?php if ($this->cart->has_options($items['rowid']) == TRUE): ?> |
| 177 | |
| 178 | <p> |
| 179 | <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?> |
| 180 | |
| 181 | <strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br /> |
| 182 | |
| 183 | <?php endforeach; ?> |
| 184 | </p> |
| 185 | |
| 186 | <?php endif; ?> |
| 187 | |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 188 | </td> |
| 189 | <td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td> |
| 190 | <td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 191 | </tr> |
| 192 | |
| 193 | <?php $i++; ?> |
| 194 | |
| 195 | <?php endforeach; ?> |
| 196 | |
| 197 | <tr> |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 198 | <td colspan="2">Â </td> |
| 199 | <td class="right"><strong>Total</strong></td> |
| 200 | <td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 201 | </tr> |
| 202 | |
| 203 | </table> |
| 204 | |
| 205 | <p><?php echo form_submit('', 'Update your Cart'); ?></p> |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 206 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 207 | Updating The Cart |
| 208 | ================= |
| 209 | |
| 210 | To update the information in your cart, you must pass an array |
Ahmad Anbar | 2702a3b | 2014-03-14 16:53:44 +0200 | [diff] [blame] | 211 | containing the Row ID and one or more pre-defined properties to the |
| 212 | ``$this->cart->update()`` method. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 213 | |
| 214 | .. note:: If the quantity is set to zero, the item will be removed from |
| 215 | the cart. |
| 216 | |
| 217 | :: |
| 218 | |
| 219 | $data = array( |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 220 | 'rowid' => 'b99ccdf16028f015540f341130b6d8ec', |
| 221 | 'qty' => 3 |
| 222 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 223 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 224 | $this->cart->update($data); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 225 | |
| 226 | // Or a multi-dimensional array |
| 227 | |
| 228 | $data = array( |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 229 | array( |
| 230 | 'rowid' => 'b99ccdf16028f015540f341130b6d8ec', |
| 231 | 'qty' => 3 |
| 232 | ), |
| 233 | array( |
| 234 | 'rowid' => 'xw82g9q3r495893iajdh473990rikw23', |
| 235 | 'qty' => 4 |
| 236 | ), |
| 237 | array( |
| 238 | 'rowid' => 'fh4kdkkkaoe30njgoe92rkdkkobec333', |
| 239 | 'qty' => 2 |
| 240 | ) |
| 241 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 242 | |
Derek Jones | 97f283d | 2011-10-05 16:17:25 -0500 | [diff] [blame] | 243 | $this->cart->update($data); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 244 | |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 245 | You may also update any property you have previously defined when |
| 246 | inserting the item such as options, price or other custom fields. |
Ahmad Anbar | da2bdf2 | 2014-02-13 12:59:18 +0200 | [diff] [blame] | 247 | |
| 248 | :: |
Ahmad Anbar | c09b953 | 2014-02-13 13:05:41 +0200 | [diff] [blame] | 249 | |
Ahmad Anbar | da2bdf2 | 2014-02-13 12:59:18 +0200 | [diff] [blame] | 250 | $data = array( |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 251 | 'rowid' => 'b99ccdf16028f015540f341130b6d8ec', |
| 252 | 'qty' => 1, |
| 253 | 'price' => 49.95, |
| 254 | 'coupon' => NULL |
| 255 | ); |
Ahmad Anbar | da2bdf2 | 2014-02-13 12:59:18 +0200 | [diff] [blame] | 256 | |
| 257 | $this->cart->update($data); |
| 258 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 259 | What is a Row ID? |
| 260 | ***************** |
| 261 | |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 262 | The row ID is a unique identifier that is generated by the cart code |
| 263 | when an item is added to the cart. The reason a unique ID is created |
| 264 | is so that identical products with different options can be managed |
| 265 | by the cart. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 266 | |
| 267 | For example, let's say someone buys two identical t-shirts (same product |
| 268 | ID), but in different sizes. The product ID (and other attributes) will |
| 269 | be identical for both sizes because it's the same shirt. The only |
| 270 | difference will be the size. The cart must therefore have a means of |
| 271 | identifying this difference so that the two sizes of shirts can be |
| 272 | managed independently. It does so by creating a unique "row ID" based on |
| 273 | the product ID and any options associated with it. |
| 274 | |
| 275 | In nearly all cases, updating the cart will be something the user does |
| 276 | via the "view cart" page, so as a developer, it is unlikely that you |
Andrey Andreev | ba231aa | 2014-01-20 16:43:41 +0200 | [diff] [blame] | 277 | will ever have to concern yourself with the "row ID", other than making |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 278 | sure your "view cart" page contains this information in a hidden form |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 279 | field, and making sure it gets passed to the ``update()`` method when |
| 280 | the update form is submitted. Please examine the construction of the |
| 281 | "view cart" page above for more information. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 282 | |
| 283 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 284 | *************** |
| 285 | Class Reference |
| 286 | *************** |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 287 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 288 | .. php:class:: CI_Cart |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 289 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 290 | .. attribute:: $product_id_rules = '\.a-z0-9_-' |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 291 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 292 | These are the regular expression rules that we use to validate the product |
| 293 | ID - alpha-numeric, dashes, underscores, or periods by default |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 294 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 295 | .. attribute:: $product_name_rules = '\w \-\.\:' |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 296 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 297 | These are the regular expression rules that we use to validate the product ID and product name - alpha-numeric, dashes, underscores, colons or periods by |
| 298 | default |
Andrew Seymour | f75ec11 | 2011-12-14 09:36:39 +0000 | [diff] [blame] | 299 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 300 | .. attribute:: $product_name_safe = TRUE |
Andrew Seymour | f75ec11 | 2011-12-14 09:36:39 +0000 | [diff] [blame] | 301 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 302 | Whether or not to only allow safe product names. Default TRUE. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 303 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 304 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 305 | .. php:method:: insert([$items = array()]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 306 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 307 | :param array $items: Items to insert into the cart |
| 308 | :returns: TRUE on success, FALSE on failure |
| 309 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 310 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 311 | Insert items into the cart and save it to the session table. Returns TRUE |
| 312 | on success and FALSE on failure. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 313 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 314 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 315 | .. php:method:: update([$items = array()]) |
Andrey Andreev | cdeee66 | 2012-10-25 17:29:52 +0300 | [diff] [blame] | 316 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 317 | :param array $items: Items to update in the cart |
| 318 | :returns: TRUE on success, FALSE on failure |
| 319 | :rtype: bool |
Andrey Andreev | cdeee66 | 2012-10-25 17:29:52 +0300 | [diff] [blame] | 320 | |
Ahmad Anbar | 7d16de6 | 2014-02-13 01:45:27 +0200 | [diff] [blame] | 321 | This method permits changing the properties of a given item. |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 322 | Typically it is called from the "view cart" page if a user makes changes |
Ahmad Anbar | 7d16de6 | 2014-02-13 01:45:27 +0200 | [diff] [blame] | 323 | to the quantity before checkout. That array must contain the rowid |
Ahmad Anbar | 4321cb0 | 2014-03-14 15:21:13 +0200 | [diff] [blame] | 324 | for each item. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 325 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 326 | .. php:method:: remove($rowid) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 327 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 328 | :param int $rowid: ID of the item to remove from the cart |
| 329 | :returns: TRUE on success, FALSE on failure |
| 330 | :rtype: bool |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 331 | |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 332 | Allows you to remove an item from the shopping cart by passing it the |
| 333 | ``$rowid``. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 334 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 335 | .. php:method:: total() |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 336 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 337 | :returns: Total amount |
| 338 | :rtype: int |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 339 | |
| 340 | Displays the total amount in the cart. |
| 341 | |
| 342 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 343 | .. php:method:: total_items() |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 344 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 345 | :returns: Total amount of items in the cart |
| 346 | :rtype: int |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 347 | |
| 348 | Displays the total number of items in the cart. |
| 349 | |
| 350 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 351 | .. php:method:: contents([$newest_first = FALSE]) |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 352 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 353 | :param bool $newest_first: Whether to order the array with newest items first |
| 354 | :returns: An array of cart contents |
| 355 | :rtype: array |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 356 | |
| 357 | Returns an array containing everything in the cart. You can sort the |
| 358 | order by which the array is returned by passing it TRUE where the contents |
| 359 | will be sorted from newest to oldest, otherwise it is sorted from oldest |
| 360 | to newest. |
| 361 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 362 | .. php:method:: get_item($row_id) |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 363 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 364 | :param int $row_id: Row ID to retrieve |
| 365 | :returns: Array of item data |
| 366 | :rtype: array |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 367 | |
| 368 | Returns an array containing data for the item matching the specified row |
| 369 | ID, or FALSE if no such item exists. |
| 370 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 371 | .. php:method:: has_options($row_id = '') |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 372 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 373 | :param int $row_id: Row ID to inspect |
| 374 | :returns: TRUE if options exist, FALSE otherwise |
| 375 | :rtype: bool |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 376 | |
| 377 | Returns TRUE (boolean) if a particular row in the cart contains options. |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 378 | This method is designed to be used in a loop with ``contents()``, since |
Andrey Andreev | 0bd390c | 2014-02-13 14:26:50 +0200 | [diff] [blame] | 379 | you must pass the rowid to this method, as shown in the Displaying |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 380 | the Cart example above. |
| 381 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 382 | .. php:method:: product_options([$row_id = '']) |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 383 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 384 | :param int $row_id: Row ID |
| 385 | :returns: Array of product options |
| 386 | :rtype: array |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 387 | |
| 388 | Returns an array of options for a particular product. This method is |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 389 | designed to be used in a loop with ``contents()``, since you |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 390 | must pass the rowid to this method, as shown in the Displaying the |
| 391 | Cart example above. |
| 392 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 393 | .. php:method:: destroy() |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 394 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 395 | :rtype: void |
Derek Jones | 82b34e6 | 2013-07-21 23:07:20 -0700 | [diff] [blame] | 396 | |
| 397 | Permits you to destroy the cart. This method will likely be called |
| 398 | when you are finished processing the customer's order. |