ruusvuu Posted March 5, 2007 Share Posted March 5, 2007 I added a new session called discount_code. print_r($_SESSION) shows that $_SESSION['discount_code'] has a value, but if I try to echo $_SESSION['discount_code'] it is empty. I am doing this in includes/classes/shopping_cart.php. Thanks for any help Link to comment Share on other sites More sharing options...
Nullachtfuffzehn Posted March 5, 2007 Share Posted March 5, 2007 I added a new session called discount_code. print_r($_SESSION) shows that $_SESSION['discount_code'] has a value, but if I try to echo $_SESSION['discount_code'] it is empty. I am doing this in includes/classes/shopping_cart.php. Thanks for any help Can you post the code in a codebox so we can check it out? Your description so far lets us walking in the fog, cause we can't follow it. Link to comment Share on other sites More sharing options...
ruusvuu Posted March 5, 2007 Author Share Posted March 5, 2007 Can you post the code in a codebox so we can check it out? Your description so far lets us walking in the fog, cause we can't follow it. if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); $discount_code = $_SESSION['discount_code']; $sql = "SELECT expires_date FROM specials WHERE discount_code = '$discount_code'"; echo $sql; $row = mysql_fetch_array(mysql_query($sql)); if($row['expires_date'] >= date('Y-m-d')){ $ovp = '.80';//percentage of total price } else { $ovp = '1'; } 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); $newovp = $attribute_price['options_values_price'] * $ovp; if ($attribute_price['price_prefix'] == '+') { $this->total += $qty * tep_add_tax($newovp, $products_tax); } else { $this->total -= $qty * tep_add_tax($newovp, $products_tax); } } } Link to comment Share on other sites More sharing options...
Nullachtfuffzehn Posted March 5, 2007 Share Posted March 5, 2007 In my experience the request of superglobals within classes ain't working properly. So you might to try to to submit the superglobal to the class within the function call. Could solve your problem. Link to comment Share on other sites More sharing options...
Guest Posted March 5, 2007 Share Posted March 5, 2007 the session array is accessible within classes/member functions and basically works there shouldn't be a problem. But what place do you setup the session and how? Link to comment Share on other sites More sharing options...
ruusvuu Posted March 6, 2007 Author Share Posted March 6, 2007 the session array is accessible within classes/member functions and basically works there shouldn't be a problem. But what place do you setup the session and how? require('includes/application_top.php'); if($_POST['discount_code']){ $_SESSION['discount_code'] = $_POST['discount_code']; } else { $_SESSION['discount_code'] = $_SESSION['discount_code']; } That's in /catalog/product_info.php Link to comment Share on other sites More sharing options...
ruusvuu Posted March 6, 2007 Author Share Posted March 6, 2007 I thought it would be helpful to post the $_SDESSION array: Array ( [cart] => shoppingcart Object ( [contents] => Array ( [61{1}3] => Array ( [qty] => 1 [attributes] => Array ( [1] => 3 ) ) ) [total] => 0 [weight] => 0 [cartID] => 83099 [content_type] => [specials] => ) [language] => english [languages_id] => 1 [currency] => USD [navigation] => navigationhistory Object ( [path] => Array ( [0] => Array ( => index.php [mode] => NONSSL [get] => Array ( ) [post] => Array ( ) ) [1] => Array ( => products_new.php [mode] => NONSSL [get] => Array ( [action] => buy_now [products_id] => 61 ) [post] => Array ( ) ) [2] => Array ( => product_info.php [mode] => NONSSL [get] => Array ( [products_id] => 61 [action] => add_product ) [post] => Array ( [id] => Array ( [1] => 3 ) [discount_code] => sp1 [products_id] => 61 [x] => 58 [y] => 11 ) ) [3] => Array ( => shopping_cart.php [mode] => NONSSL [get] => Array ( ) [post] => Array ( ) ) ) [snapshot] => Array ( ) ) [discount_code] => [customer_id] => 3 [customer_default_address_id] => 3 [customer_first_name] => Richard [customer_country_id] => 222 [customer_zone_id] => 0 [new_products_id_in_cart] => 61 Link to comment Share on other sites More sharing options...
Guest Posted March 7, 2007 Share Posted March 7, 2007 require('includes/application_top.php'); if($_POST['discount_code']){ $_SESSION['discount_code'] = $_POST['discount_code']; } else { $_SESSION['discount_code'] = $_SESSION['discount_code']; } That's in /catalog/product_info.php I don't know the flow of execution with your scipts ie what page is loaded first but you need to properly test/assign varialbles. What is the point of this: $_SESSION['discount_code'] = $_SESSION['discount_code']; and how comes the dump has 2 instances of discount_code. One populated passed with the post array the other isnt passed with the get array. So your if statement will execute the else clause which will clear the session. Instead of this you should use the osc tep_register... functions. Link to comment Share on other sites More sharing options...
ruusvuu Posted March 11, 2007 Author Share Posted March 11, 2007 I don't know the flow of execution with your scipts ie what page is loaded first but you need to properly test/assign varialbles. What is the point of this:$_SESSION['discount_code'] = $_SESSION['discount_code']; and how comes the dump has 2 instances of discount_code. One populated passed with the post array the other isnt passed with the get array. So your if statement will execute the else clause which will clear the session. Instead of this you should use the osc tep_register... functions. Thanks. Could you assist me in the proper usage of tep_register...? Link to comment Share on other sites More sharing options...
Guest Posted March 11, 2007 Share Posted March 11, 2007 there're many examples with the default osc files. search for tep_session_register Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.