From cdeee661db2438cc65304f704ab4bcebeccb9b7d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 25 Oct 2012 17:29:52 +0300 Subject: Add CI_Cart::get_item() (rel #400) --- system/libraries/Cart.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php index c442f88da..d4b17fa36 100644 --- a/system/libraries/Cart.php +++ b/system/libraries/Cart.php @@ -479,18 +479,35 @@ class CI_Cart { // -------------------------------------------------------------------- + /** + * Get cart item + * + * Returns the details of a specific item in the cart + * + * @param string $row_id + * @return array + */ + public function get_item($row_id) + { + return (in_array($row_id, array('total_items', 'cart_total'), TRUE) OR ! isset($this->_cart_contents[$row_id])) + ? FALSE + : $this->_cart_contents[$row_id]; + } + + // -------------------------------------------------------------------- + /** * Has options * * Returns TRUE if the rowid passed to this function correlates to an item * that has options associated with it. * - * @param mixed + * @param string $row_id = '' * @return bool */ - public function has_options($rowid = '') + public function has_options($row_id = '') { - return (isset($this->_cart_contents[$rowid]['options']) && count($this->_cart_contents[$rowid]['options']) !== 0); + return (isset($this->_cart_contents[$row_id]['options']) && count($this->_cart_contents[$row_id]['options']) !== 0); } // -------------------------------------------------------------------- @@ -500,12 +517,12 @@ class CI_Cart { * * Returns the an array of options, for a particular product row ID * - * @param int + * @param string $row_id = '' * @return array */ - public function product_options($rowid = '') + public function product_options($row_id = '') { - return isset($this->_cart_contents[$rowid]['options']) ? $this->_cart_contents[$rowid]['options'] : array(); + return isset($this->_cart_contents[$row_id]['options']) ? $this->_cart_contents[$row_id]['options'] : array(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b