Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

automatically display product_info when List has only 1 item


joncas

Recommended Posts

Hello

 

I wonder if anyone has figured out a way that whenever a list of products has only 1 item, the product detail is display directly.

 

Otherwise the user gets this 1-item list and has to click on it to show the product.

 

This would be nice, for example, if a category has only 1 item: it would directly display that item without requiring the extra step of clicking on the single item in the list.

 

The catalog/index.php would somehow have to automatically hand over to product_info.php when the query has 1 item,

so instead of

catalog/index.php?cPath=1_12

 

the browser would go to

catalog/product_info.php?cPath=1_12&products_id=132

 

Many thanks!

Robert

Link to comment
Share on other sites

Hello

 

I wonder if anyone has figured out a way that whenever a list of products has only 1 item, the product detail is display directly.

 

Otherwise the user gets this 1-item list and has to click on it to show the product.

 

This would be nice, for example, if a category has only 1 item: it would directly display that item without requiring the extra step of clicking on the single item in the list.

 

The catalog/index.php would somehow have to automatically hand over to product_info.php when the query has 1 item,

so instead of

catalog/index.php?cPath=1_12

 

the browser would go to

catalog/product_info.php?cPath=1_12&products_id=132

 

Many thanks!

Robert

 

Hi Robert..

 

you can do one thing.. use th tep_redirect to redirect to the page if the category has only one product.. the changes will involve in the index.php file.

 

in the index.php file.

you will find the code snippet:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {

just above that add in the following code:

if(tep_get_num_rows(tep_db_query($listing_sql)) == 1)

{

$prods_arr = tep_db_fetch_array(tep_db_query($listing_sql));

$prods_id = $prods_arr['products_id'];

tep_redirect(FILENAME_PRODUCTS_INFO,'products_id='.$prods_id);

}

 

I think that will work the solution out.. if not send me a message across and i will help you out..

Cheers

Hari

Link to comment
Share on other sites

Hi Robert..

 

you can do one thing.. use th tep_redirect to redirect to the page if the category has only one product.. the changes will involve in the index.php file.

 

in the index.php file.

you will find the code snippet:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {

just above that add in the following code:

if(tep_get_num_rows(tep_db_query($listing_sql)) == 1)

{

$prods_arr = tep_db_fetch_array(tep_db_query($listing_sql));

$prods_id = $prods_arr['products_id'];

tep_redirect(FILENAME_PRODUCTS_INFO,'products_id='.$prods_id);

}

 

I think that will work the solution out.. if not send me a message across and i will help you out..

Cheers

Hari

 

Hi Hari !

 

Thank you for your rapid reply!

The patch you suggested seems not to work; it causes an incomplete page.

 

Could one put the redirect more near the top, before it starts building html code, where it says:

 

// the following cPath references come from application_top.php

$category_depth = 'top';

if (isset($cPath) && tep_not_null($cPath)) {

$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");

$cateqories_products = tep_db_fetch_array($categories_products_query);

 

?

 

many thanks in advance!

Robert

Link to comment
Share on other sites

Hi Hari !

 

Thank you for your rapid reply!

The patch you suggested seems not to work; it causes an incomplete page.

 

Could one put the redirect more near the top, before it starts building html code, where it says:

 

// the following cPath references come from application_top.php

$category_depth = 'top';

if (isset($cPath) && tep_not_null($cPath)) {

$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");

$cateqories_products = tep_db_fetch_array($categories_products_query);

 

?

 

many thanks in advance!

Robert

 

Hi Robert

 

thanks for getting back.. ther was a error .. the earlier html tags wont cause the existing tags....

 

replace the following line:

tep_redirect(FILENAME_PRODUCTS_INFO,'products_id='.$prods_id);

with:

tep_redirect(tep_href_link(FILENAME_PRODUCTS_INFO,'products_id='.$prods_id));

 

Regards

Hari

Link to comment
Share on other sites

Hi Robert..

 

you can do one thing.. use th tep_redirect to redirect to the page if the category has only one product.. the changes will involve in the index.php file.

 

in the index.php file.

you will find the code snippet:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {

just above that add in the following code:

if(tep_get_num_rows(tep_db_query($listing_sql)) == 1)

{

$prods_arr = tep_db_fetch_array(tep_db_query($listing_sql));

$prods_id = $prods_arr['products_id'];

tep_redirect(FILENAME_PRODUCTS_INFO,'products_id='.$prods_id);

}

 

I think that will work the solution out.. if not send me a message across and i will help you out..

Cheers

Hari

 

Thanks to Hari's help, the solution finally is :

at the top of catalog/index.php after these lines:

 

// the following cPath references come from application_top.php

$category_depth = 'top';

if (isset($cPath) && tep_not_null($cPath)) {

$categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");

$cateqories_products = tep_db_fetch_array($categories_products_query);

if ($cateqories_products['total'] > 0) {

 

add these lines:

 

if ($cateqories_products['total'] == 1)

{

$query = tep_db_query("select p2c.products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where categories_id = '" . (int)$current_category_id . "'");

$prods_arr = tep_db_fetch_array($query);

$prods_id = $prods_arr['products_id'];

tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO,'products_id='.$prods_id));

}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...