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