Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New variable


maxemus

Recommended Posts

Hello,

I can't seem to get this correct. It would be fantastic if someone could lend a hand. this is what I'm trying to do.

I would like to store the current category in a session. I'm trying to filter a Category search with an sql statement and need to store refer to the $current_category_id. the problem is when reloading the index.php it clears the $current_category_id. So I'm thinking Store the $current_category_id in a session var,

something like

--create a session var--

when the $category_ctegory_id is set do something like

if ($current_category_id =! 0 and $current_category_id =! NULL){

create and store a new temp var from $current_category_id in a session;

}

 

I haven't worked with sessions successfully yet. Could someone give me a hand.

Thanks so very much.

Link to comment
Share on other sites

 if (tep_not_null($current_category_id) && !tep_session_is_registered('first_cat')){
tep_session_register('first_cat');
$first_cat = $current_category_id; }


//call it:
echo $_SESSION['first_cat'];

I have not got a clue on what you want to do with it though. This will store the first category_id as a session variable.

 

Have fun

 

edit:

for storing the last known cat_id into the session:

if (tep_session_is_registered('last_cat')) tep_session_unregister('last_cat');

if (tep_not_null($current_category_id)){
tep_session_register('last_cat');
$last_cat = $current_category_id; }


//call it:
echo $_SESSION['last_cat'];

Link to comment
Share on other sites

Thanks

 

two things where would I put this in order to capture the current category id

and

will this capture the current id if the current category is 0

 

this is what I'm trying to do

 

// Alphabetical Search - begin

if (isset($_GET['alpha'])) {

$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.products_name like '" . $_GET['alpha'] . "%' and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . $_SESSION['first_cat'] ."'";

// show the products in a given categorie

 

the $_SESSION['first_cat'] should give me the # of the last browsed category so I can isolate the search to the to that category.

Link to comment
Share on other sites

// Alphabetical Search - begin

if (isset($_GET['alpha'])) {

$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.products_name like '" . $_GET['alpha'] . "%' and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . $_SESSION['first_cat'] ."'";

// show the products in a given categorie

 

the $_SESSION['first_cat'] should give me the # of the last browsed category so I can isolate the search to the to that category.

then use:

if (tep_not_null($current_category_id)){
if (tep_session_is_registered('last_cat')) tep_session_unregister('last_cat');
tep_session_register('last_cat');
$last_cat = $current_category_id; }

 

 

also: add (int) to your query (security check to make sure only a number is inserted into your DB:

$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.products_name like '" . $_GET['alpha'] . "%' and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$_SESSION['last_cat'] ."'";

 

then one more thing, this session does not always have to exist, if a customer never visits a page with a category_id that includes the code to save it, $_SESSION['last_cat'] will return NULL and thus only results without category id will be the result.

Link to comment
Share on other sites

thank you very much

I modified it a bit because it was still changing it back to 0

this keeps it in registered in a session

 

if (tep_session_is_registered('last_cat'));

 

if (tep_not_null($current_category_id)){

tep_session_register('last_cat');

$last_cat = $current_category_id; }

 

//call it:

echo (int)$_SESSION['last_cat'];

 

Thanks so very much it acts just like I want it to now. I'm not sure If I need to unregister the session.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...