Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Linking to product's category instead of the prod info page


glenda

Recommended Posts

Is there any way I could alter the way product links are generated to make it so that all products when clicked go to their subcategory instead of product_info.php?

 

I need this because I'm not using the product_info.php page in my store.

 

Any help would be greatly appreciated :!:

Mary

Link to comment
Share on other sites

I can understand you using your picture, you are very beautiful, now to your problem, you can use <a href="http://www.your web site.com/default.php?cPath=50"> or what ever # you want if that helps

Link to comment
Share on other sites

Hi there,

 

You're asking for alot of changes to your core files but i will start you off with an easy example.

 

In catalog/includes/boxes/specials.php line 13 change...

 

if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_rrp, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added desc limit " . MAX_RANDOM_SELECT_SPECIALS)) {

 

to........

 

if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_rrp, p.products_tax_class_id, p.products_image, s.specials_new_products_price, pc.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added desc limit " . MAX_RANDOM_SELECT_SPECIALS)) {

 

then on line 26 you'll find a snippet as below...

 

<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product["products_id"]) . '">

 

chenge this to.........

 

<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $random_product["categories_id"]) . '">

 

now upload and then every time you click on a special offer link in the special info box it takes your to the items category/subcategory!

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Link to comment
Share on other sites

Thanks for helping me!

 

I modified my boxes/specials.php and I can't get it to quite work. You can look at My temp site - http://www.plazmaart.com/rocknroll/ and see that the modified code is creating bogus links to incorrect categories. I have made 2 on-special items to test this code.

 

I edited the image link in the specials box and left the product name text how it was originally.

 

<?php

/*

 $Id: specials.php,v 1.1.1.1 2002/11/28 23:22:24 wilt Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 osCommerce



 Released under the GNU General Public License

*/

?>

<!-- specials //-->

<?php

 if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price, pc.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC limit " . MAX_RANDOM_SELECT_SPECIALS)) {

?>

         <tr>

           <td>

<?php

   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'left',

                                'text'  => BOX_HEADING_SPECIALS

                               );

   new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS, '', 'NONSSL'));



   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'center',

                                'text'  => '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $random_product["categories_id"], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br><s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>'

                               );

   new infoBox($info_box_contents);

?>

           </td>

         </tr>

<?php

 }

?>

<!-- specials_eof //-->

Do any ideas come to mind?

 

Thanks!

Mary

Link to comment
Share on other sites

Hi Glenda,

 

Try this code i added a where statement in the select call and it should come out correct now :oops:, you should be able to see the additions, if not activate 'allow HTML' in your profile ;

 

<?php

/*

$Id: specials.php,v 1.1.1.1 2002/11/28 23:22:24 wilt Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

?>

<!-- specials //-->

<?php

if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price, pc.categories_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC limit " . MAX_RANDOM_SELECT_SPECIALS)) {

?>

<tr>

<td>

<?php

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left',

'text' => BOX_HEADING_SPECIALS

);

new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS, '', 'NONSSL'));

 

$info_box_contents = array();

$info_box_contents[] = array('align' => 'center',

'text' => '<a href="' . tep_href_link(FILENAME_DEFAULT)) . '</span>'

);

new infoBox($info_box_contents);

?>

</td>

</tr>

<?php

}

?>

<!-- specials_eof //-->

 

 

Back up before you try! Let me know how it goes :)

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Link to comment
Share on other sites

It works well now! Thank you so much!!!

 

I've just got one more question...Would it be possible to link to the cpath with the main category and subcategorie(s) in the url. For instance instead of linking to http://www.plazmaart.com/rocknroll/default...t.php?cPath=106 link to http://www.plazmaart.com/rocknroll/default...p?cPath=105_106 so the breadcrumb is accurate.

 

Thanks again :)

Mary

Link to comment
Share on other sites

Yes, sorry should have added it in!

 

<?php 

/* 

$Id: specials.php,v 1.1.1.1 2002/11/28 23:22:24 wilt Exp $ 



osCommerce, Open Source E-Commerce Solutions 

http://www.oscommerce.com 



Copyright (c) 2002 osCommerce 



Released under the GNU General Public License 

*/ 

?> 

<!-- specials //--> 

<?php 

if ($random_product = tep_random_select("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price, pc.categories_id, c.parent_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pc.products_id = s.products_id and c.categories_id = pc.categories_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC limit " . MAX_RANDOM_SELECT_SPECIALS)) { 



if ($random_product["parent_id"] > 0) {

$prepath = $random_product["parent_id"] . '_';

} else {

$prepath = '';

}

?> 

<tr> 

<td> 

<?php 

$info_box_contents = array(); 

$info_box_contents[] = array('align' => 'left', 

'text' => BOX_HEADING_SPECIALS 

); 

new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS, '', 'NONSSL')); 



$info_box_contents = array(); 

$info_box_contents[] = array('align' => 'center', 

'text' => '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $prepath . $random_product["categories_id"], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $prepath . $random_product['categories_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br><s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>' 

); 

new infoBox($info_box_contents); 

?> 

</td> 

</tr> 

<?php 

} 

?> 

<!-- specials_eof //-->

 

Back up first as usual!

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Link to comment
Share on other sites

You did it! That works great.

 

There's only one thing...if the category in more than 2 levels deep the breadcrumb isn't displayed properly.

 

I placed an item on special which is 3 levels deep and when I click on if from the specials box, it's main category is left out. Only the 2 subcategories above it are shown.

 

Is there a fix for this?

 

Thanks again for helping me so much :D

Mary

Link to comment
Share on other sites

It's much easier to simply call this function from functions/general.php

 

////

// Construct a category path to the product

// TABLES: products_to_categories

function tep_get_product_path($products_id) {

$cPath = '';

 

$cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");

$cat_count_data = tep_db_fetch_array($cat_count_sql);

 

if ($cat_count_data['count'] == 1) {

$categories = array();

 

$cat_id_sql = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");

$cat_id_data = tep_db_fetch_array($cat_id_sql);

tep_get_parent_categories($categories, $cat_id_data['categories_id']);

 

for ($i=sizeof($categories)-1; $i>=0; $i--) {

if ($cPath != '') $cPath .= '_';

$cPath .= $categories[$i];

}

if ($cPath != '') $cPath .= '_';

$cPath .= $cat_id_data['categories_id'];

}

 

return $cPath;

}

Mary

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...