count = 0; if (sizeof($globalObjects)) { foreach($globalObjects as $k=>$v) { $this->$k = $v; } } TidalDebug::noticetrace("Created Cart_Item object", false, $tblDef); $this->_tbldef = $tblDef; $this->_prepareSQL(); } function inc() { $this->count++; return "-=-".$this->count."-=-"; } /** * Defines the sql queries to be used by this class * * @access private * @return void */ function _prepareSQL() { // defined queries $dbr = Tidal::getShorthandTableDefinitions($this->_tbldef); TidalDebug::noticetrace("Preparing categories custom sql's",false,array(get_class($this), $this->_tbldef, $dbr)); $queryData = array( 'getOrder' => 'SELECT * FROM module_cart_orders WHERE cartId = ?', // INT cartId 'getCartId' => 'SELECT cartId FROM module_cart_orders WHERE transactionId = ?', // STRING transactionId 'getRecentOrders' => array( 'mysql' => 'SELECT * FROM module_cart_orders WHERE (TO_DAYS(NOW()) - TO_DAYS(datePlaced)) <= ? ORDER BY ? ?', // STRING numberOfDays, STRING fieldName, STRING [ASC|DESC] ), 'getRecentSuccessfulOrders' => array( 'mysql' => 'SELECT * FROM module_cart_orders WHERE complete = 1 AND (TO_DAYS(NOW()) - TO_DAYS(datePlaced)) <= ? ORDER BY ? ?', // STRING numberOfDays, STRING fieldName, STRING [ASC|DESC] ), ); $this->_buildSQL($queryData); } /** * Check to see if the cart contains any products * * @access public * @param void * @return boolean Does the cart contain any Cart_Items? */ function isEmpty() { if ( ! sizeof($this->_cartItems) ) { return true; } return false; } /** * Check this object to ensure that all elements exist so the order can be stored to the database * or a transaction be carried out. * * @access public * @param * @return boolean Is the cart OK to store/continue */ function readyToStore() { } /** * Check for the quantity of a specific product in the cart. * * @access public * @param int searchProductId The productId we want to check for * @return int The quantity of the product in the cart */ function getQuantity( $searchProductId ) { foreach ( $this->_cartItems AS $productId=>$cartItem ) { if ( $searchProductId == $productId ) { return $cartItem->getQuantity(); } } return false; } function _getItems() { } /** * Add a product to the cart. When an attempt to add a new product is submitted, check * to see if the product already exists in the cart. If it does, change the quantity. * * @access public ( Called by Cart_drv::form_handler() ) * @param int productId The unique identifier for the product according to the ProductCatalogue * @param int quantity The number of products to add to the cart. * @return */ function addItem($productId, $quantity = 1) { if (!$this->getQuantity($productId)) { // The product doesn't exist in the cart $cartItem = new Cart_Item($this->tblDef, $this->globalObjects, $productId, $quantity); $this->_cartItems[$productId] = $cartItem; TidalDebug::noticetrace("Added item to cart",false,array('itemid'=>$productId,'totalitems'=>sizeof($this->_cartItems))); } else { // The product is already in the cart as a Cart_Item // we need to update the quantity $this->_cartItems[$productId]->setQuantity($quantity); TidalDebug::noticetrace("Updated item quantity",false,array('itemid'=>$productId,'totalitems'=>sizeof($this->_cartItems))); } TidalDebug::noticetrace("Cart after addition...",false,array('itemid'=>$productId,'totalitems'=>sizeof($this->_cartItems), $this->inc(), 'cartitems'=>$this->_cartItems)); } /** * Remove a product from the cart. Because only one instance of each product can exist in the cart * at one time, the productId is used to mark the product for removal. * * @access public ( Called by Cart_drv::form_handler() ) * @param int productId The unique identifier for the product marked for removal * @return */ function removeItem($productId) { } /** * Change the number of units for a specific product as its stored in the Cart object * * @access public ( Called by Cart_drv::form_handler() ) * @param int productId The unique identifier for the product to change the quantity of * @param int newQuantity The new quantity to store for the product * @return int The change in quantity < 0 for removal, > 0 for additions */ function changeQuantity($productId, $newQuantity) { } /** * Prepare the cart for output to the browser according to a template * * @access public * @param int templateId The id of the template as stored in the database * @param string path The path of the template to use (if no template in database) * @return string The HTML to output the cart */ function outputFromTemplate($templateId, $path = null) { } /** * Calculate the total value of the cart * * @access public * */ function calculateTotal() { foreach ( $this->_cartItems AS $cartItem ) { } } function getValue() { } function countItems() { } /** * THIS IS NOT USED ... THERES IS NO REASON FOR IT... THE ONLY FORM HANDLER SHOULD BE IN THE DRIVER FILE!!! */ function form_handler() { $liveCart = TidalSession::get('Cart_Order'); switch ( strtoupper($_POST['frmAction']) ) { case 'BUY': default: foreach ( $_POST AS $key=>$quantity ) { if ( preg_match('/product_id_/', $key) ) { $productId = str_replace('product_id_', '', trim($key)); $liveCart->addItem($productId, $quantity); } } // header('Location: '.$GLOBALS['PHP_SELF'].($_SERVER['QUERY_STRING'] ? '?'.$_SERVER['QUERY_STRING'] : '') ); // exit; break; } TidalDebug::noticetrace('Cart Contents after form handler', false, $liveCart); } } ?>