From 82b34e6c10fa80e1b3a0d03c41d084e5ff121403 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 21 Jul 2013 23:07:20 -0700 Subject: Update Cart lib docs --- user_guide_src/source/libraries/cart.rst | 152 +++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 47 deletions(-) (limited to 'user_guide_src/source/libraries/cart.rst') diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst index 716e94bcb..ad1955d27 100644 --- a/user_guide_src/source/libraries/cart.rst +++ b/user_guide_src/source/libraries/cart.rst @@ -11,7 +11,16 @@ Please note that the Cart Class ONLY provides the core "cart" functionality. It does not provide shipping, credit card authorization, or other processing components. -.. contents:: Page Contents +.. contents:: + :local: + +.. raw:: html + +
+ +******************** +Using the Cart Class +******************** Initializing the Shopping Cart Class ==================================== @@ -29,7 +38,7 @@ use the $this->load->library function:: $this->load->library('cart'); Once loaded, the Cart object will be available using:: - + $this->cart .. note:: The Cart Class will load and initialize the Session Class @@ -179,7 +188,7 @@ helper `.

- + Updating The Cart ================= @@ -197,7 +206,7 @@ function: 'qty' => 3 ); - $this->cart->update($data); + $this->cart->update($data); // Or a multi-dimensional array @@ -243,66 +252,115 @@ update form is submitted. Please examine the construction of the "view cart" page above for more information. -Function Reference -================== +*************** +Class Reference +*************** + +.. class:: CI_Cart + + .. attribute:: $product_id_rules = '\.a-z0-9_-' + + These are the regular expression rules that we use to validate the product + ID - alpha-numeric, dashes, underscores, or periods by default + + .. attribute:: $product_name_rules = '\w \-\.\:' + + 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 + default + + .. attribute:: $product_name_safe = TRUE + + Whether or not to only allow safe product names. Default TRUE. + + + .. method:: insert([$items = array()]) + + :param array $items: the items to insert into the cart + :returns: bool + + Insert items into the cart and save it to the session table. Returns TRUE + on success and FALSE on failure. + + + .. method:: update([$items = array()]) + + :param array $items: the items to update in the cart + :returns: bool + + This method permits the quantity of a given item to be changed. + Typically it is called from the "view cart" page if a user makes changes + to the quantity before checkout. That array must contain the product ID + and quantity for each item. + + + .. method:: remove($rowid) + + :param int $rowid: the ID of the item to remove from the cart + :returns: bool + + Allows you to remove an item from the shopping cart by passing it the + ``$rowid``. + + + .. method:: total() + + :returns: int + + Displays the total amount in the cart. + + + .. method:: total_items() + + :returns: int + + Displays the total number of items in the cart. -$this->cart->insert(); -********************** -Permits you to add items to the shopping cart, as outlined above. + .. method:: contents([$newest_first = FALSE]) -$this->cart->update(); -********************** + :param bool $newest_first: order the array with newest first? + :returns: array -Permits you to update items in the shopping cart, as outlined above. + Returns an array containing everything in the cart. You can sort the + order by which the array is returned by passing it TRUE where the contents + will be sorted from newest to oldest, otherwise it is sorted from oldest + to newest. -$this->cart->remove(rowid); -*************************** -Allows you to remove an item from the shopping cart by passing it the rowid. + .. method:: get_item($row_id) -$this->cart->total(); -********************* + :param int $row_id: the row ID to retrieve + :returns: array -Displays the total amount in the cart. + Returns an array containing data for the item matching the specified row + ID, or FALSE if no such item exists. -$this->cart->total_items(); -*************************** -Displays the total number of items in the cart. + .. method:: has_options($row_id = '') -$this->cart->contents(boolean); -******************************* + :param int $row_id: the row ID to inspect + :returns: bool -Returns an array containing everything in the cart. You can sort the order, -by which this is returned by passing it "true" where the contents will be sorted -from newest to oldest, by leaving this function blank, you'll automatically just get -first added to the basket to last added to the basket. + Returns TRUE (boolean) if a particular row in the cart contains options. + This method is designed to be used in a loop with :meth:contents:, since + you must pass the rowid to this function, as shown in the Displaying + the Cart example above. -$this->cart->get_item($row_id); -******************************* -Returns an array containing data for the item matching the specified row ID, -or FALSE if no such item exists. + .. method:: product_options([$row_id = '']) -$this->cart->has_options($row_id); -********************************** + :param int $row_id: the row ID + :returns: array -Returns TRUE (boolean) if a particular row in the cart contains options. -This function is designed to be used in a loop with -$this->cart->contents(), since you must pass the rowid to this function, -as shown in the Displaying the Cart example above. + Returns an array of options for a particular product. This method is + designed to be used in a loop with :meth:contents:, since you + must pass the rowid to this method, as shown in the Displaying the + Cart example above. -$this->cart->product_options($row_id); -************************************** -Returns an array of options for a particular product. This function is -designed to be used in a loop with $this->cart->contents(), since you -must pass the rowid to this function, as shown in the Displaying the -Cart example above. + .. method:: destroy() -$this->cart->destroy(); -*********************** + :returns: void -Permits you to destroy the cart. This function will likely be called -when you are finished processing the customer's order. + Permits you to destroy the cart. This method will likely be called + when you are finished processing the customer's order. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ba231aab2b26279f536a52bf4ccdb4af0d191570 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Jan 2014 16:43:41 +0200 Subject: [ci skip] Replace incorrect usage of 'then', where it should be 'than' --- user_guide_src/source/libraries/cart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source/libraries/cart.rst') diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst index ad1955d27..0c8c0a601 100644 --- a/user_guide_src/source/libraries/cart.rst +++ b/user_guide_src/source/libraries/cart.rst @@ -245,7 +245,7 @@ the product ID and any options associated with it. In nearly all cases, updating the cart will be something the user does via the "view cart" page, so as a developer, it is unlikely that you -will ever have to concern yourself with the "row ID", other then making +will ever have to concern yourself with the "row ID", other than making sure your "view cart" page contains this information in a hidden form field, and making sure it gets passed to the update function when the update form is submitted. Please examine the construction of the "view -- cgit v1.2.3-24-g4f1b From 28c2c975b118016d07212ed8e7c22ff280309f82 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 04:27:48 +0200 Subject: [ci skip] Add return types to library docs --- user_guide_src/source/libraries/cart.rst | 53 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'user_guide_src/source/libraries/cart.rst') diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst index 0c8c0a601..fb92c280a 100644 --- a/user_guide_src/source/libraries/cart.rst +++ b/user_guide_src/source/libraries/cart.rst @@ -275,8 +275,9 @@ Class Reference .. method:: insert([$items = array()]) - :param array $items: the items to insert into the cart - :returns: bool + :param array $items: Items to insert into the cart + :returns: TRUE on success, FALSE on failure + :rtype: bool Insert items into the cart and save it to the session table. Returns TRUE on success and FALSE on failure. @@ -284,83 +285,85 @@ Class Reference .. method:: update([$items = array()]) - :param array $items: the items to update in the cart - :returns: bool + :param array $items: Items to update in the cart + :returns: TRUE on success, FALSE on failure + :rtype: bool This method permits the quantity of a given item to be changed. Typically it is called from the "view cart" page if a user makes changes to the quantity before checkout. That array must contain the product ID and quantity for each item. - .. method:: remove($rowid) - :param int $rowid: the ID of the item to remove from the cart - :returns: bool + :param int $rowid: ID of the item to remove from the cart + :returns: TRUE on success, FALSE on failure + :rtype: bool Allows you to remove an item from the shopping cart by passing it the ``$rowid``. - .. method:: total() - :returns: int + :returns: Total amount + :rtype: int Displays the total amount in the cart. .. method:: total_items() - :returns: int + :returns: Total amount of items in the cart + :rtype: int Displays the total number of items in the cart. .. method:: contents([$newest_first = FALSE]) - :param bool $newest_first: order the array with newest first? - :returns: array + :param bool $newest_first: Whether to order the array with newest items first + :returns: An array of cart contents + :rtype: array Returns an array containing everything in the cart. You can sort the order by which the array is returned by passing it TRUE where the contents will be sorted from newest to oldest, otherwise it is sorted from oldest to newest. - .. method:: get_item($row_id) - :param int $row_id: the row ID to retrieve - :returns: array + :param int $row_id: Row ID to retrieve + :returns: Array of item data + :rtype: array Returns an array containing data for the item matching the specified row ID, or FALSE if no such item exists. - .. method:: has_options($row_id = '') - :param int $row_id: the row ID to inspect - :returns: bool + :param int $row_id: Row ID to inspect + :returns: TRUE if options exist, FALSE otherwise + :rtype: bool Returns TRUE (boolean) if a particular row in the cart contains options. - This method is designed to be used in a loop with :meth:contents:, since + This method is designed to be used in a loop with ``contents()``, since you must pass the rowid to this function, as shown in the Displaying the Cart example above. - .. method:: product_options([$row_id = '']) - :param int $row_id: the row ID - :returns: array + :param int $row_id: Row ID + :returns: Array of product options + :rtype: array Returns an array of options for a particular product. This method is - designed to be used in a loop with :meth:contents:, since you + designed to be used in a loop with ``contents()``, since you must pass the rowid to this method, as shown in the Displaying the Cart example above. - .. method:: destroy() - :returns: void + :rtype: void Permits you to destroy the cart. This method will likely be called when you are finished processing the customer's order. \ No newline at end of file -- cgit v1.2.3-24-g4f1b