Guest Posted July 14, 2008 Posted July 14, 2008 Hi I need help in finding a Parse error: syntax error, unexpected $end in /includes/classes/shopping_cart.php on line 636 Here is the code: <?php /* $Id: shopping_cart.php 1739 2007-12-20 00:52:16Z hpdl $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class shoppingCart { var $contents, $total, $weight, $cartID, $content_type; function shoppingCart() { $this->reset(); } function restore_contents() { global $customer_id; if (!tep_session_is_registered('customer_id')) return false; // insert current cart contents in database if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $qty = $this->contents[$products_id]['qty']; $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); if (!tep_db_num_rows($product_query)) { tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')"); if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { // OTF contrib begins //tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . $customer_id . "', '" . $products_id . "', '" . $option . "', '" . $value . "')"); $attr_value = $this->contents[$products_id]['attributes_values'][$option]; tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')"); } } } else { tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $qty . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } } } // reset per-session cart contents, but not the database contents $this->reset(false); /*# auction.lister ######################################## # select auctionid in query, too # # combine productid and auctionid --> prodid[auctionid] # # START- # #########################################################*/ //select also auctionid $products_query = tep_db_query("select products_id, auctionid, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'"); while ($products = tep_db_fetch_array($products_query)) { //if product is an auction if($products['auctionid']!=''){ //conbine ids $myproducts_id = $products['products_id']."[".$products['auctionid']."]"; }else{ //no auction $myproducts_id = $products['products_id']; } $this->contents[$myproducts_id] = array('qty' => $products['customers_basket_quantity'], 'auctionid' => $products['auctionid']); // look for attributes //is auction with attributes? //CLR 020606 update query to pull attribute value_text. This is needed for text attributes. if($products['auctionid']!=''){ $mysql = "select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "' and auctionid = '".tep_db_input($products['auctionid'])."'"; }else{ //normal product from shop $mysql = "select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products['products_id']) . "' and auctionid = '0'"; } $attributes_query = tep_db_query($mysql); while ($attributes = tep_db_fetch_array($attributes_query)) { if($products['auctionid']!=''){ $myproducts_id = $products['products_id']."[".$products['auctionid']."]"; }else{ $myproducts_id = $products['products_id']; } //add attributes to productarray $this->contents[$myproducts_id]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id']; //CLR 020606 if text attribute, then set additional information if ($attributes['products_options_value_id'] == PRODUCTS_OPTIONS_VALUE_TEXT_ID) { $this->contents[$products['products_id']]['attributes_values'][$attributes['products_options_id']] = $attributes['products_options_value_text']; } } /*# auction.lister # # -END # ##################*/ $this->cleanup(); } function reset($reset_database = false) { global $customer_id; $this->contents = array(); $this->total = 0; $this->weight = 0; $this->content_type = false; if (tep_session_is_registered('customer_id') && ($reset_database == true)) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'"); } unset($this->cartID); if (tep_session_is_registered('cartID')) tep_session_unregister('cartID'); } function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) { global $new_products_id_in_cart, $customer_id; /*# auction.lister ############### # save passed products_id tmp # # $old_prod_id = $products_id; # ################################*/ $old_prod_id = $products_id; $products_id_string = tep_get_uprid($products_id, $attributes); $products_id = tep_get_prid($products_id_string); if (is_numeric($products_id) && is_numeric($qty)) { $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); $check_product = tep_db_fetch_array($check_product_query); if (($check_product !== false) && ($check_product['products_status'] == '1')) { if ($notify == true) { $new_products_id_in_cart = $products_id; tep_session_register('new_products_id_in_cart'); } /*# auction.lister ######################## # look if product in cart is an auction # # START- # #########################################*/ //look for tmp saved prodid - if it is an auction if($this->contents[$old_prod_id][auctionid]!=''){ //if it is in cart if ($this->in_cart($old_prod_id)) { //update quantity and attributes $this->update_quantity($old_prod_id, $qty, $attributes); } //tmp saved prodid is not an auction }else{ //look if normal product is in cart if ($this->in_cart($products_id_string)) { //update quantity and attributes $this->update_quantity($products_id_string, $qty, $attributes); } else {//product is not in cart //add a new product to cart $this->contents[$products_id_string] = array('qty' => $qty); // insert into database if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . $qty . "', '" . date('Ymd') . "')"); //add attributes if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { //CLR 020606 check if input was from text box. If so, store additional attribute information //CLR 020708 check if text input is blank, if so do not add to attribute lists //CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input. $attr_value = NULL; $blank_value = FALSE; if (strstr($option, TEXT_PREFIX)) { if (trim($value) == NULL) { $blank_value = TRUE; } else { $option = substr($option, strlen(TEXT_PREFIX)); $attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES); $value = PRODUCTS_OPTIONS_VALUE_TEXT_ID; $this->contents[$products_id]['attributes_values'][$option] = $attr_value; } } if (!$blank_value) { $this->contents[$products_id]['attributes'][$option] = $value; // insert into database //CLR 020606 update db insert to include attribute value_text. This is needed for text attributes. //CLR 030228 add tep_db_input() processing if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id, products_options_value_text) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "', '" . tep_db_input($attr_value) . "')"); } $this->cleanup(); // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure $this->cartID = $this->generate_cart_id(); } /*# auction.lister # # -END # ##################*/ } } } function update_quantity($products_id, $quantity = '', $attributes = '') { global $customer_id; /*# auction.lister ######################## # look if product in cart is an auction # # START- # #########################################*/ //tmp save passed productid $old_prod_id = $products_id; $products_id_string = tep_get_uprid($products_id, $attributes); $products_id = tep_get_prid($products_id_string); //substract auctionid (out of combination --> productid[auctionid]) $myauctionid = substr(strstr($old_prod_id,"["),1,-1); //get clear productid (out of combination --> productid[auctionid]) $myproducts_id = explode("[",$old_prod_id); //look if products are in productsarray (auction and normal products) if (is_numeric($products_id) && (isset($this->contents[$products_id_string]) || isset($this->contents[$old_prod_id])) && is_numeric($quantity)) { //if no auction product if($myauctionid==''){ $this->contents[$products_id] = array('qty' => $quantity); }else{ //if an auction $this->contents[$old_prod_id] = array('qty' => $quantity); //also set auctionid in productsarray $this->contents[$old_prod_id]['auctionid'] = $myauctionid; } // update database if (tep_session_is_registered('customer_id')){ //is not a auction add to database if($myauctionid==''){ if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . $quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } } if (is_array($attributes)) { reset($attributes); while (list($option, $value) = each($attributes)) { //if no auction add attributes if($myauctionid==''){ $this->contents[$products_id_string]['attributes'][$option] = $value; }else{//if auction add attributes on this way $this->contents[$old_prod_id]['attributes'][$option] = $value; } // update database if (tep_session_is_registered('customer_id')){ //is an auction - update db customers basket in this way if($myauctionid!=''){ $mysqlstring = "update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($myproducts_id[0]) . "' and products_options_id = '" . (int)$option . "' and auctionid ='".$myauctionid."'"; //CLR 020606 check if input was from text box. If so, store additional attribute information //CLR 030108 check if text input is blank, if so do not update attribute lists //CLR 030228 add htmlspecialchars processing. This handles quotes and other special chars in the user input. $attr_value = NULL; $blank_value = FALSE; if (strstr($option, TEXT_PREFIX)) { if (trim($value) == NULL) { $blank_value = TRUE; //is a normal product } else { $option = substr($option, strlen(TEXT_PREFIX)); $attr_value = htmlspecialchars(stripslashes($value), ENT_QUOTES); $value = PRODUCTS_OPTIONS_VALUE_TEXT_ID; $this->contents[$products_id]['attributes_values'][$option] = $attr_value; } } /*# auction.lister # # -END # ##################*/ if (!$blank_value) { $this->contents[$products_id]['attributes'][$option] = $value; // update database //CLR 020606 update db insert to include attribute value_text. This is needed for text attributes. //CLR 030228 add tep_db_input() processing if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "', products_options_value_text = '" . tep_db_input($attr_value) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and products_options_id = '" . (int)$option . "'"); } } } } function cleanup() { global $customer_id; reset($this->contents); while (list($key,) = each($this->contents)) { if ($this->contents[$key]['qty'] < 1) { unset($this->contents[$key]); // remove from database if (tep_session_is_registered('customer_id')) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'"); } } } } function count_contents() { // get total number of items in cart $total_items = 0; if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $total_items += $this->get_quantity($products_id); } } return $total_items; } function get_quantity($products_id) { if (isset($this->contents[$products_id])) { return $this->contents[$products_id]['qty']; } else { return 0; } } function in_cart($products_id) { if (isset($this->contents[$products_id])) { return true; } else { return false; } } function remove($products_id) { global $customer_id; //CLR 030228 add call tep_get_uprid to correctly format product ids containing quotes $products_id = tep_get_uprid($products_id, $attributes); unset($this->contents[$products_id]); // remove from database if (tep_session_is_registered('customer_id')) { /*# auction.lister ############################## # remove normal product from customers basket # # normal product --> auctionid==0 # ###############################################*/ tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "' and auction=0"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } // assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure $this->cartID = $this->generate_cart_id(); } function remove_all() { $this->reset(); } function get_product_id_list() { $product_id_list = ''; if (is_array($this->contents)) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { $product_id_list .= ', ' . $products_id; } } return substr($product_id_list, 2); } function calculate() { global $currencies; $this->total = 0; $this->weight = 0; if (!is_array($this->contents)) return 0; reset($this->contents); while (list($products_id, ) = each($this->contents)) { $qty = $this->contents[$products_id]['qty']; // products price /*# auction.lister ########## # get right product price # # START- # ###########################*/ //get auctionid $auctionid = $this->contents[$products_id][auctionid]; //if product is an auction - get right price out of table auction_details if($auctionid!=''){ $sqlquery = "select p.products_id, ad.auction_endprice, p.products_tax_class_id, p.products_weight from products p, auction_list al, auction_details ad, customers c WHERE p.products_id = al.product_id AND c.customers_email_address = ad.buyer_email AND al.auction_id = ad.auction_id AND al.auction_id='".$auctionid."' AND c.customers_id = '".$customer_id."'"; }else{ //normal shopproduct - normal select $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'"); } if ($product = tep_db_fetch_array($product_query)) { $prid = $product['products_id']; $products_tax = tep_get_tax_rate($product['products_tax_class_id']); //if auction if($auctionid!=''){ //auctionprice is incl. tax - so you have to get the price without tax (because in cart it automatically added) $products_price = $product['auction_endprice']/(1+($products_tax/100)); }else{//normalproduct $products_price = $product['products_price']; } /*# auction.lister # # -END # ##################*/ $products_weight = $product['products_weight']; $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'"); if (tep_db_num_rows ($specials_query)) { $specials = tep_db_fetch_array($specials_query); $products_price = $specials['specials_new_products_price']; } $this->total += $currencies->calculate_price($products_price, $products_tax, $qty); $this->weight += ($qty * $products_weight); } // attributes price if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); $attribute_price = tep_db_fetch_array($attribute_price_query); if ($attribute_price['price_prefix'] == '+') { $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty); } else { $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty); } } } } } function attributes_price($products_id) { $attributes_price = 0; if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'"); $attribute_price = tep_db_fetch_array($attribute_price_query); if ($attribute_price['price_prefix'] == '+') { $attributes_price += $attribute_price['options_values_price']; } else { $attributes_price -= $attribute_price['options_values_price']; } } } return $attributes_price; } function get_products() { global $languages_id; if (!is_array($this->contents)) return false; $products_array = array(); reset($this->contents); while (list($products_id, ) = each($this->contents)) { /*# auction.lister #################### # update orderid in auction_details # # START- # #####################################*/ $auctionid = $this->contents[$products_id][auctionid]; //if product is an auction if($auctionid!=''){ //query: also select for auctionid - there might be more than one auction from the same product (same productid) with different prices $sqlquery = "select p.products_id, pd.products_name, p.products_model, p.products_image, ad.auction_endprice, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, auction_details ad, auction_list al where ad.auction_id = al.auction_id AND al.product_id=p.products_id AND p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and al.auction_id = '".$auctionid."' and pd.language_id = '" . (int)$languages_id . "'"; $products_query = tep_db_query($sqlquery); }else{//normal shopproduct - normal select $sqlquery = "select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"; $products_query = tep_db_query($sqlquery); } if ($products = tep_db_fetch_array($products_query)) { $prid = $products['products_id']; //if auction - get right excl. tax price if($auctionid!=''){ $products_price = $products['auction_endprice']/(1+(tep_get_tax_rate($products['products_tax_class_id'])/100)); }else{//normal price - normal shopproduct $products_price = $products['products_price']; $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'"); if (tep_db_num_rows($specials_query)) { $specials = tep_db_fetch_array($specials_query); $products_price = $specials['specials_new_products_price']; } } /*# auction.lister # # -END # ##################*/ /*# auction.lister ################ # add auctionid to productarray # # 'auctionid' => $auctionid, # #################################*/ $products_array[] = array('id' => $products_id, 'auctionid' => $auctionid, 'name' => $products['products_name'], 'model' => $products['products_model'], 'image' => $products['products_image'], 'price' => $products_price, 'quantity' => $this->contents[$products_id]['qty'], 'weight' => $products['products_weight'], 'final_price' => ($products_price + $this->attributes_price($products_id)), 'tax_class_id' => $products['products_tax_class_id'], // OTF contrib begins //'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : '')); 'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''), 'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : '')); // OTF contrib ends } } return $products_array; } function show_total() { $this->calculate(); return $this->total; } function show_weight() { $this->calculate(); return $this->weight; } function generate_cart_id($length = 5) { return tep_create_random_value($length, 'digits'); } function get_content_type() { $this->content_type = false; if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) { reset($this->contents); while (list($products_id, ) = each($this->contents)) { if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list(, $value) = each($this->contents[$products_id]['attributes'])) { $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id"); $virtual_check = tep_db_fetch_array($virtual_check_query); if ($virtual_check['total'] > 0) { switch ($this->content_type) { case 'physical': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'virtual'; break; } } else { switch ($this->content_type) { case 'virtual': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'physical'; break; } } } } else { switch ($this->content_type) { case 'virtual': $this->content_type = 'mixed'; return $this->content_type; break; default: $this->content_type = 'physical'; break; } } } } else { $this->content_type = 'physical'; } return $this->content_type; } function unserialize($broken) { for(reset($broken);$kv=each($broken);) { $key=$kv['key']; if (gettype($this->$key)!="user function") $this->$key=$kv['value']; } } /*# auction.lister ####################### # function - check product if it is a # # combination of prodid and auctionid # # --> then product would be an auction # ########################################*/ function is_auction($products_id){ $myproduct = $this->contents[$products_id]; if($myproduct[auctionid] != ''){ return true; }else{ return false; } } } ?> as I can not see it and have been looking for about 3 - 4 hours now and I need to go to ded after 48 hour of non stop work for clients. Thanks for the help.
germ Posted July 14, 2008 Posted July 14, 2008 I did this several times. You have 115 { in the file. But only 108 } I couldn't find any commented out. They should appear in equal number. Thus the error. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
Guest Posted July 14, 2008 Posted July 14, 2008 I did this several times. You have 115 { in the file. But only 108 } I couldn't find any commented out. They should appear in equal number. Thus the error. Hi Thanks for that tip. I would never of look at it like that I will do as my first look from now on?
Guest Posted July 14, 2008 Posted July 14, 2008 now I am getting: Fatal error: Call to undefined method shoppingCart::reset() in /includes/classes/shopping_cart.php on line 17
Recommended Posts
Archived
This topic is now archived and is closed to further replies.